Azure / azure-service-bus-java

☁️ Java client library for Azure Service Bus
https://azure.microsoft.com/services/service-bus
MIT License
60 stars 59 forks source link

Getting existing sessions IDs of queue or subscription client using the Java SDK. #330

Closed lchrissl26 closed 5 years ago

lchrissl26 commented 5 years ago

How can I enumerate existing sessions in a queue or a subscription using the Java API? I could read this on: https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-sessions.

"All existing sessions in a queue or subscription can be enumerated with the SessionBrowser method in the Java API and with GetMessageSessions on the QueueClient and SubscriptionClient in the .NET client..."

But have found no classes or methods in the Java SDK to achieve this. Thanks

yvgopal commented 5 years ago

This feature was already coded in the SDK. Our .net core SDK doesn't have those methods implemented. I had to hide those method just so both the SDKs are similar. I am going to make them public in the upcoming 2.0 release.

yvgopal commented 5 years ago

I discussed this with my team. There were mixed opinions about exposing that API. The API gets only the first 100 sessions, and it doesn't work if it has more than 100 sessions. Do you have a business need for it? Could you explain it? Our ISessionHandler API will cycle through all sessions anyway.

lchrissl26 commented 5 years ago

Well, we simply need to consume all messages from all queues and topics with sessions, if possible one by one. Because attributes (messageId, sessionId etc.) of the consumed message should be reported on the client. So getting first the list of all session IDs may allow us to consume that way.

yvgopal commented 5 years ago

ISessionHandler will give you the session and the message as arguments to the onMessageAsync method. So you will know the session id and all message properties as well inside the method. You should be able to receive every message from every session using a session handler.