Hi all, I’m a tad confused when it comes to the difference between the Notifications 2.0 & Realtime.
I would like to use mqtt / websockets (not long polling) inside a c# / node application that listens to all events, alarms, telemetry, location changes to our device on c8y production instance please. This will then update our Redis cache with that data ready for our React frontend to subscribe too via SignalR
I’ve tried the c# websocket route but I keep getting a 403 errors, even though I have the highest level roles attached to my user:
[{“channel”:“/meta/handshake”,“error”:“403::Handshake denied”,“advice”:{“reconnect”:“none”},“successful”:false}]
I tried the node examples provided in the test-microservice repo (github/SoftwareAG/cumulocity-examples/blob/ad3670210071553f6c1a6c5d3cc097dec1f2ff2b/microservices/node-microservice/controllers.js#L100), I created the following code but I get a client.getFetchOptions is not a function error:
// "@c8y/client": "^1020.29.0",
// "tslib": "^2.8.0"
const { Client, BasicAuth, Realtime } = require('@c8y/client');
// Authenticate with BasicAuth
const auth = new BasicAuth({
user: 'USRNAME',
password: 'PASWRD',
tenant: 'TEANANT'
});
const baseUrl = 'https://TEANANT.machines.cloud';
const client = new Client(auth, baseUrl);
// Set up the Realtime client
const realtime = new Realtime(client);
(async () => {
try {
// Verify authentication by listing inventory (optional)
const { data } = await client.inventory.list({ pageSize: 100 });
// console.log('Inventory data:', data);
// Subscribe to real-time notifications for device alarms
// Subscribe to alarms
realtime.subscribe(`/alarms/`, (response) => {
console.log('Received alarm notification:', response);
});
// Subscribe to events
realtime.subscribe(`/events/`, (response) => {
console.log('Received event notification:', response);
});
console.log('Subscribed to real-time notifications for device:', deviceId);
} catch (error) {
console.error("Error during authentication or subscription:", error);
}
})();
Also, it mentions the role: ROLE_NOTIFICATION_2_ADMIN in the docs but my tenant admin says there is no ROLE_NOTIFICATION_2_ADMIN role.
Really not sure sure where to go from here. I can post the c# code too if required.
Thanks