0
votes

I'm new to azure service bus, I'm developing a sample publish/subscribe application using java sdk. In this exercise what I want to achieve is I will publish 50 messages (json)to a queue, these are in below format.

[{'lastname'='test0','firstName'='success0'}...'lastname'='test49','firstName'='success49'}]

In receiver application at 25th message , I want this message to abandon, so the 25th message will be available in queue. But when I run application, all 49 messages are completed and one message went to dead letter queue. I got below exception.

Either receive link to 'asb.java.pub' closed with a transient error and reopened or the delivery was already settled by complete/abandon/defer/deadletter.
2019-05-09 06:17:19 ERROR MessageAndSessionPump:241 - Completing message with sequence number '5002' failed
java.lang.IllegalArgumentException: Delivery not found on the receive link.
    at com.geico.messaging.servicebus.primitives.CoreMessageReceiver.generateDeliveryNotFoundException(CoreMessageReceiver.java:1319)
    at com.geico.messaging.servicebus.primitives.CoreMessageReceiver.updateMessageStateAsync(CoreMessageReceiver.java:1161)
    at com.geico.messaging.servicebus.primitives.CoreMessageReceiver.completeMessageAsync(CoreMessageReceiver.java:1046)
    at com.geico.messaging.servicebus.MessageReceiver.lambda$3(MessageReceiver.java:267)
    at java.util.concurrent.CompletableFuture.uniComposeStage(Unknown Source)
    at java.util.concurrent.CompletableFuture.thenCompose(Unknown Source)
    at com.geico.messaging.servicebus.MessageReceiver.completeAsync(MessageReceiver.java:262)
    at com.geico.messaging.servicebus.MessageReceiver.completeAsync(MessageReceiver.java:255)
    at com.geico.messaging.servicebus.MessageAndSessionPump.lambda$6(MessageAndSessionPump.java:220)
    at java.util.concurrent.CompletableFuture.uniHandle(Unknown Source)
    at java.util.concurrent.CompletableFuture$UniHandle.tryFire(Unknown Source)
    at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

.here is my publishing code

ConnectionStringBuilder connectionResolver = new ConnectionStringBuilder(connectionString, "asb.java.pub");     
QueueClient sendClient = new QueueClient(connectionResolver,ReceiveMode.PEEKLOCK);
for(int i =0;i<50;i++){Message message = new Message("{'lastname' = 'test"+i+"', 'firstName' ='success"+i+"'}");
message.setLabel("name");sendClient.send(message);}sendClient.close();

here is my subscriber code

IMessageHandler ih=new IMessageHandler() {              
public CompletableFuture<Void> onMessageAsync(IMessage message)   {
byte[] body = message.getBody();                    
Map map = GSON.fromJson(new String(body, UTF_8), Map.class);    
try{                        if(map.get("lastname").equals("test25")){                       return receiveClient.abandonAsync(message.getLockToken());
;
}catch(Exception e){                        e.printStackTrace();                        
}
CompletableFuture.completedFuture(null);
}
public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
                    System.out.printf(exceptionPhase + "-" + throwable.getMessage());
}
};

            receiveClient.registerMessageHandler(ih, executorService);

the below is the screenshot after running publish appenter image description here

the below screenshot after running subscriber app.enter image description here

my question is why message goes to deadletter , when I call abandon method. Can't I made a specific message to abandon or autocomplete false.So that that message will be available in the queue .

Thank you.

2

2 Answers

0
votes

Looks like an expected behavior. When you abandon a message , the delivery count is increased by 1 and message is available again in the queue for processing. However If you keep on abandoning a message the delivery count will reach the max limit (from your screenshot it's 10) and then message is moved to dead letter queue.

To get a better idea explore the message in deal letter queue and reason why it's failed. You can do it in the Service bus explorer.

0
votes

just replace with below one

 receiveClient.registerMessageHandler(ih, new MessageHandlerOptions(1,true, Duration.ofMinutes(1)),executorService);