I am new to the Solace Javascript API and trying to read messages from a queue in the PubSub+ Broker Manager.
I kept running into the following error when calling solace.QueueBrowser
.
Uncaught OperationError: Operation is invalid for Message Consumer in disconnected state
The funny thing is, when I run the script for a different Solace environment, I am unable to recreate this error (I.e. it connects correctly).
Below is the source code:
try {
// Login to Solace
var session = solace.SolclientFactory.createSession({
url: loginDetails.url,
vpnName: loginDetails.vpn,
userName: loginDetails.username,
password: loginDetails.pw
});
session.connect(); // Connect session
var qb = session.createQueueBrowser({
queueDescriptor: {
name: dynamicQueueName,
type: "QUEUE"
}
});
qb.on(solace.QueueBrowserEventName.CONNECT_FAILED_ERROR,
function connectFailedErrorEventCb(error) {
console.error(error.message);
sendErrorToPage(error.message);
});
qb.on(solace.QueueBrowserEventName.MESSAGE,
function messageCB(message) {
var appMsgId = message.getApplicationMessageId();
if (appMsgId === undefined) { appMsgId = 'Not specified'; }
var payload = message.getBinaryAttachment();
sendPayloadToPage(message.rc.low, appMsgId, payload);
});
// qb.connect(); // Connect with QueueBrowser to receive QueueBrowserEvents.
setTimeout(
function() {
qb.disconnect();
session.disconnect();
}, 5000); // Disconnect after 5 seconds.
} catch (error) {
console.error(error.message);
sendErrorToPage(error.message);
}
Does anyone have ideas why this error is occurring? If so, what is going on and how do I correct it?