JavaScript API > Error: Operation is invalid for Message Consumer in disconnected

leonard
leonard Member Posts: 10 ✭✭
edited November 2023 in General Discussions #1

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

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 959 admin

    Hi @l16phill,

    It looks like we missed this one. Were you able to figure out or are you still in need of a second pair of eyes?

  • leonard
    leonard Member Posts: 10 ✭✭

    Hi @marc ,

    Was not able to resolve this, unfortunately. I'm also unable to capture these errors with a Try/Catch. I'd love a second pair of eyes thanks

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 959 admin

    Hi @l16phill,

    Can you listen for the other events defined in the docs? One of those is likely triggering without being handled: https://docs.solace.com/API-Developer-Online-Ref-Documentation/js/solace.QueueBrowser.html

    Hope that helps!

  • leonard
    leonard Member Posts: 10 ✭✭

    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!

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 959 admin

    Glad you figured it out and thank you for following up! Happy New Year :)