How to get back the message id after publishing a message on solace topic using nodejs

solacenewbie80
Sun, 30 Apr 2023 11:36:19 +0000
Solace Event Broker

hi Members,
i need help to get the message id immediately after publishing a message on topic using nodejs. i can publish a message but not sure how to get the message id back after publishing.
i tried to search on the google but no luck.
here is the code i am using to publish.
code block :
const solace = require(‘solclientjs’);
const hostUrl = ‘url’;
const vpnName = ‘VPN’;
const userName = ‘user’;
const password = ‘pwd’;
const topicName = ‘testtopic’;
const messagePayload = ‘hello nodejs’;
const factoryProps = new solace.SolclientFactoryProperties();
solace.SolclientFactory.init(factoryProps);
const session = solace.SolclientFactory.createSession({
url: hostUrl,
vpnName: vpnName,
userName: userName,
password: password
});
session.connect();
session.on(solace.SessionEventCode.UP_NOTICE, () => {
console.log(‘Session is up.’);
const message = solace.SolclientFactory.createMessage();
message.setDestination(solace.SolclientFactory.createTopicDestination(topicName));
message.setBinaryAttachment(messagePayload);
message.setDeliveryMode(solace.MessageDeliveryModeType.PERSISTENT);
message.setAcknowledgeImmediately(true);

session.send(message);
console.log(Message sent: ${messagePayload});
session.disconnect();
});
session.on(solace.SessionEventCode.DISCONNECTED, () => {
console.log(‘Session is disconnected.’);
});
session.on(solace.SessionEventCode.RECONNECTING_NOTICE, () => {
console.log(‘Session is reconnecting.’);
});
session.on(solace.SessionEventCode.RECONNECTED_NOTICE, () => {
console.log(‘Session is reconnected.’);
});
session.on(solace.SessionEventCode.CONNECT_FAILED_ERROR, (sessionEvent) => {
console.error(Error connecting to Solace message broker: ${sessionEvent.infoStr});
});

thanks

8 posts - 1 participant