🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
JavaScript API > Error: Operation is invalid for Message Consumer in disconnected
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?
Answers
-
Hi @marc ,
Thanks for the input. I placed a listener for each of these events and found that none were firing. This gave me a hint that the Message Consumer was not successfully connecting (also mentioned in the error message).
After much more investigation, I found that the queue owner has an ACL profile with IP address exemptions. My machine was not on this exemption list.
This meant that the Queue Browser object was not able to connect and calling qb.disconnect(); results in an invalid operation.
Thanks for the help!
1