azure-service-bus-java icon indicating copy to clipboard operation
azure-service-bus-java copied to clipboard

Error: 2 messages in DeadLetter if one message isn't completed / closed by IMessageReceiver...

Open abhikt48 opened this issue 6 years ago • 9 comments

Actual Behavior

  1. Two messages are going in DeadLetter instead of one message if not closed IMessageReceiver

Please find the below code. Say I have 5 messages (A,B,C,D,E) in my subscriber available for consumption; I start consuming message A and neither I call complete on the message nor close the receiver. I should expect message A to appear in the DeadLetter after the given operation time out, however, I am seeing 2 messages, A and B both, in the DeadLetter on my Service Bus.

Is this a bug or I am missing something obvious here?

Code:

import java.time.Duration;
import com.microsoft.azure.servicebus.ClientFactory;
import com.microsoft.azure.servicebus.IMessage;
import com.microsoft.azure.servicebus.IMessageReceiver;
import com.microsoft.azure.servicebus.ReceiveMode;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;

public class TopicReceiveExample {

	private static final String connectionString = "Endpoint=######";
    private static final String subscriptionName = "####-topic/subscriptions/####-sub";
    private static ConnectionStringBuilder connectionStringBuilder;
    
    IMessageReceiver receiver;
    
    public static void main(String[] args) throws InterruptedException, ServiceBusException {
		
    	connectionStringBuilder = new ConnectionStringBuilder(connectionString, subscriptionName);
    	
    	IMessageReceiver receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder(connectionStringBuilder, ReceiveMode.PEEKLOCK);
		IMessage message = receiver.receive(Duration.ofSeconds(10));
		
		System.out.println("Message Content :: "+ new String(message.getBody()));
		//
		//receiver.complete(message.getLockToken());
		//receiver.close();
		
	}
}

Expected Behavior

  1. Only message A should go in DeadLetter

Actual Behavior

  1. message A and B both are pushed to the DeadLetter

Environment

Windows 8

  • Maven package : com.microsoft.azure :: azure-servicebus :: 1.1.1

Any more information needed here???

This behavior is making me bonkers already and need assistance;

abhikt48 avatar Feb 26 '18 10:02 abhikt48

First of all, just receiving a message and failing to complete it doesn't dead letter it, unless max delivery count on your subscription is set to 1. When a message is received and not completed, its delivery count is incremented by 1. When it reaches MaxDeliveryCount described in your Queue or Subscription, it is dead-lettered. It is a service side behavior and has nothing to do with client. I would suggest you check your subscription description and client code once again. I would suggest you look at our samples at https://github.com/Azure/azure-service-bus/tree/master/samples/Java

yvgopal avatar Feb 26 '18 21:02 yvgopal

@yvgopal Yes correct, MaxDeliveryCount is 1 on Subscription.

Suppose - I have 5 messages (A,B,C,D,E) in subsription.

When you run above sample code, Java application prints only message A , after 10 seconds i can message A in DeadLetter because i have not completed this.

Problem - After refreshing subscription, i can see message B also in DeadLetter. This is a problem. Why message B went in DeadLetter? I have not received message B while running java application.

Could you please suggest solution of this problem. Please let me know for any information.

abhikt48 avatar Feb 28 '18 11:02 abhikt48

Have you enabled prefetching of messages? Keep prefetch as 0 and see if this is still repro'able.

nemakam avatar Feb 28 '18 21:02 nemakam

@nemakam - I checked with prefetchCount as 0 as well. I am having same issue. Please find below changed code. @yvgopal - Could you please open this issue ?

IMessageReceiver receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder(connectionStringBuilder, ReceiveMode.PEEKLOCK);
receiver.setPrefetchCount(0);
IMessage message = receiver.receive(Duration.ofSeconds(10));
System.out.println("Message Content :: "+ new String(message.getBody()));

abhikt48 avatar Mar 01 '18 13:03 abhikt48

How do you know which one is message A and which one is message B? Can you reproduce the issue on an empty queue or subscription? If it is reproduced, can you try to receive the messages from dead letter queue and see the dead letter reason? Every dead lettered message will have a reason in message properties. You can find them by calling getProperties() method on the message. Something like this... {DeadLetterReason=MaxDeliveryCountExceeded, DeadLetterErrorDescription=Message could not be consumed after 10 delivery attempts.} Send me the dead letter reason. Also send me the namespace, topic name, subscription name and the exact time when the actions(your test send and receive) were performed.

yvgopal avatar Mar 01 '18 20:03 yvgopal

@yvgopal

How do you know which one is message A and which one is message B? --> I sent 5 messages (A, B, C, D and E) sequentially. Once i started application i received only message 'A' and after 10 seconds message 'A' and 'B' both went to dead letter.

Can you reproduce the issue on an empty queue or subscription? --> Yes, every time i am able reproduce this issue. Please follow below steps to reproduce this issue and let me know if you are not able to reproduce this issue.

  1. Send 5 messages on topic
  2. Change "connectionString" and "subscriptionName" in above code (First Post).
  3. Run as --> "Java Application"
  4. You can see only one output in console that is --> "Message Content :: A"
  5. Check subscription message --> now you can see 2 message in dead letter queue after elapsing message lock duration.

If it is reproduced, can you try to receive the messages from dead letter queue and see the dead letter reason? --> I received both messages from dead letter. Please find below details.

Message Content :: A
Message Properties :: {DeadLetterReason=MaxDeliveryCountExceeded, DeadLetterErrorDescription=Message could not be consumed after 1 delivery attempts.}

Message Content :: B
Message Properties :: {DeadLetterReason=MaxDeliveryCountExceeded, DeadLetterErrorDescription=Message could not be consumed after 1 delivery attempts.}

Problem -- You can see in above code, i am receiving message at only one time, so java prints one message. Look like receiver keep second message, if we did not complete first message then second message also moving in dead letter.

namespace, topic name, subscription name - my namespace ends with **.servicebus.windows.net. I am sorry, i cant send details due to security reason.

Could you please try reproduce this issue from your end.. I hope this helps..

Please find below subscription setting.

subscription details

abhikt48 avatar Mar 02 '18 19:03 abhikt48

I will try to reproduce it myself. But we are Azure Service Bus team. We can't troubleshoot issues without knowing namespace, entity names. Every customer support ticket has to include namesapce name, entity names. Your data is secure as long as you keep your SAS keys secret. We never ask for SAS keys. Without namespace, entity names, there is only so much I can do.

yvgopal avatar Mar 02 '18 21:03 yvgopal

Hi Vijya,

Sure.. Thanks.. Please let me if you are able to reproduce or not. If not then I will raise support request from Azure portal, might be that request land in your bucket.. If this will also not help then I will create new service bus account and share details with you...

Thanks a lot for quick response.

On Mar 2, 2018 9:08 PM, "Vijaya Gopal Yarramneni" [email protected] wrote:

I will try to reproduce it myself. But we are Azure Service Bus team. We can't troubleshoot issues without knowing namespace, entity names. Every customer support ticket has to include namesapce name, entity names. Your data is secure as long as you keep your SAS keys secret. We never ask for SAS keys. Without namespace, entity names, there is only so much I can do.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-service-bus-java/issues/190#issuecomment-370052889, or mute the thread https://github.com/notifications/unsubscribe-auth/AV1krRkywDDFuPn9ZfHS7uEpb5IrZ-7cks5tabTcgaJpZM4STBG7 .

abhikt48 avatar Mar 02 '18 21:03 abhikt48

@yvgopal - Did you get chance to reproduce this issue? Are you able to reproduce this issue?

abhikt48 avatar Mar 07 '18 11:03 abhikt48