Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Java: Azure Service Bus Queue Receiving messsages with sessions

$
0
0

Hi, 
I posted a question on StackOverflow but no one answered so I'm trying here too 😊

(Link: stackOverflow: https://stackoverflow.com/questions/59213314/java-azure-service-bus-queue-receiving-messsages-with-sessions)

I'm writing code in java (using Azure SDK for Java), I have a Service bus queue that contains sessionful messages. I want to receive those messages and process them to another place.

I make a connection to the Queue by using QueueClient, and then I use registerSessionHandler to process through the messages (code below).

The problem is that whenever a message is received, I can print all details about it including the content, but it is printed 10 times and after each time it prints an Exception. (printing 10 times: I understand that this is because there is a 10 times retry policy before it throws the message to the Dead letter queue and goes to the next message.)

The Exception says

> USERCALLBACK-Receiver not created.Registering a MessageHandler creates a receiver.

But I'm sure that the SessionHandler does the same thing as MessageHandler but includes support for sessions, so it should create a receiver since it receives messages. I have tried to use MessageHandler but it won't even work and stops the whole program because it doesn't support sessionful messages, and the ones I receive have sessions.

My problem is understanding what the Exception wants me to do, and how can I fix the code so it won't give me any exceptions? Does anyone have suggestions on how to improve the code? or other methods that do the same thing?

QueueClient qc =newQueueClient(newConnectionStringBuilder(connectionString),ReceiveMode.PEEKLOCK);

qc.registerSessionHandler(newISessionHandler(){@OverridepublicCompletableFuture<Void> onMessageAsync(IMessageSession messageSession,IMessage message){System.out.printf("\nMessage received: "+"\n --> MessageId = %s "+"\n --> SessionId = %s"+"\n --> Content Type = %s"+"\n --> Content = \n\t\t %s",
                            message.getMessageId(),
                            messageSession.getSessionId(),
                            message.getContentType(),
                            getMessageContent(message));return qc.completeAsync(message.getLockToken());}@OverridepublicCompletableFuture<Void>OnCloseSessionAsync(IMessageSession iMessageSession){returnCompletableFuture.completedFuture(null);}@Overridepublicvoid notifyException(Throwable throwable,ExceptionPhase exceptionPhase){System.out.println("\n Exception "+ exceptionPhase +"-"+ throwable.getMessage());}},newSessionHandlerOptions(1,true,Duration.ofMinutes(1)),Executors.newSingleThreadExecutor());

Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>