Javascript API > Return a specific range of messages from a queue without consuming them.

l16phill
l16phill Member Posts: 7 ✭✭

I have a use case where I'd like to browse a specific subset of messages from a queue.

Example: 100 messages on a queue. We'd like to browse messages 20 to 30 without returning all 100 messages.

I don't want to consume these messages so I think a QueueBrowser would suit, however, I can't see support for this in the Javascript API documentation.

Tagged:

Answers

  • Ragnar
    Ragnar Member, Employee Posts: 64 Solace Employee

    QueueBrowser objects are created by solace.Session#createQueueBrowser.

    See also solace.QueueBrowser

    Ragnar

  • l16phill
    l16phill Member Posts: 7 ✭✭

    Apologies, let me expand on my last sentence as it is not clear:

    I don't want to consume these messages so I think a QueueBrowser would suit, however, in the createQueueBrowser documentation, it appears the QueueBrowser object does not support a mechanism for returning a specific range of messages with a queue. It simply returns all messages.

    Is my understanding of the above true? If so, is there a way to work around this limitation so that we can return a range of messages from a queue?

    Cheers

  • Ragnar
    Ragnar Member, Employee Posts: 64 Solace Employee

    Thanks for the clarification. There is no way with the javascript API to select specific messages for consuming from the queue.

    What criteria would you use for selection? As the spooler message id is generally not available to the clients, choosing by message-id is not an option. How would the clients even get this information in the first place?

    The non-javascript APIs and the broker do support 'selectors' https://docs.solace.com/API/Solace-JMS-API/Selectors.htm?Highlight=selector as a mechanism to retrieve only certain messages from the queue.

    Adding the ability to configure a selector on a Consumer in javascript is not available.

    Regards,

    Ragnar

  • l16phill
    l16phill Member Posts: 7 ✭✭

    Thanks for this confirmation @Ragnar - I felt like this would be the case.

    For the full picture, I am working on a Chrome plugin for the PubSub+ Broker Manager that can display the payload of a message under the message itself in the Messaging > Queues > [queue name] > Message Queue page.

    The message ID can be found deep within the browser DOM as a Table Row element ID attribute.

    If Selectors were available in the Javascript API, we could use these IDs to return only the messages displayed in the UI instead of all messages on the queue.

    I feel like this issue might be a hard limitation but if you have any out of the box ideas I'd be interested in hearing them

    Cheers

  • Ragnar
    Ragnar Member, Employee Posts: 64 Solace Employee

    Selectors cannot select on message-id, so even when they are available, it will not help in this use case.

    The QueueBrowser interface, and the underlying protocol, was designed with this exact use case in mind. A QueueBrowser allows an applications such as your Chrome plugin, to browse all the messages in a queue, whether or not another application is also bound to the queue. Naturally if some other application is consuming from the queue, the view the queue browser sees may not be accurate, but the same would be the case in your plugin that scrapes the WebUI.

    With a QueueBrowser you retrieve all the messages on the queue, a page at a time according to the window size you configure on QueueBrowser. You can provider a user display of just the message-ids, which will be the spooler message-id seen in the WebUI, and allow your user to select any one to display the contents. The user experience would actually be faster here, as the message is already in your plugin and does not have to be downloaded again.

    I was hoping to find something in SolaceSamples to demonstrate this, but it does not appear that such a sample exists.

    I think this would simplify your plugin as all the information you want is available from the QueueBrowser alone. It does mean you are downloading all the messages into your plugin, instead of just a list of message-ids. This may be an issue with very long lists, or very large messages.

    Happy Holidays,

    Ragnar