Consumer is receiving only 50 percent of the messages published to the topic - apache-pulsar

We're noticing that exactly 50 percent of the messages produced to my Pulsar topic are reaching my app. Everything was working fine yesterday where our Pulsar consumer app was getting 100% of messages that were produced to the topic. We haven't made any setting changes in our app. What is happening with the missing messages? Where are they going?

Pulsar isn't losing your messages.
It looks like you're using a shared subscription and more than one consumer connected. That other consumer is receiving your other messages since the topic will dispatch them in a round-robin when using a shared subscription. This behavior can occur by design if your consumers are auto-scaling on a shared subscription.
If you check topic stats ($ pulsar-admin topics stats options, documented here), in the response, in "subscriptions", look for your subscription by its name. In that object, you can see the "type", which will be marked as "shared," and you will see a list of "consumers". I'd expect that you have more than one consumer in that list.

Related

ReceiveAsync from Azure Service Bus topic without a body

I'm creating a consumer of an Azure Service Bus topic (subscription) that does nothing but store some statistics. The messages sent to the topic contains a rather large body, that is handled by another consumer on a second subscription on the same topic.
Since the statistics consumer can handle a large number of messages in one go, I was wondering if it is possible to receive a lot of messages but leave out the body to improve performance when communicating with Service Bus and to receive even more messages in one go.
I'm currently doing this:
this.messageReceiver = new MessageReceiver(conn, path);
...
await messageReceiver.ReceiveAsync(10, TimeSpan.FromSeconds(5));
It works pretty sweet but it would be nice to be able to receive 100 or more messages, without having to worry about moving large messages over the network.
Before anyone suggests it, I already know that I can ask for a count, etc. on a topic subscription. I still need the Message object since that contains an entry in the UserProperties dictionary that is used to calculate the stats.
Not possible. You can peek, but that brings the whole payload and headers w/o incrementing the DeliveryCount of the message. You could request it as a broker feature here.

How to read messages from topic using multiple subscribers at a time?

I am working on Azure ServiceBus Topic-Subscriptions. I created one topic and two subscriptions in Service Bus Namespace. In my current application, I am able to send messages to topic after that I receive messages by using subscribers.
But whenever one subscriber will read messages from topic then the messages are gone into Dead-Letter-Queue. That’s why second subscriber will be unable to read messages from topic.
I wrote this line in my code after process message from Topic
await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
I followed this documentation for implementing above scenario.
So, can anyone suggest me how to read messages from topic using multiple subscribers at a time.
whenever one subscriber will read messages from topic then the messages are gone into Dead-Letter-Queue. That’s why second subscriber will be unable to read messages from topic.
Either there's a processing logic error and message is retried until it gets moved to the dead-letter queue or you've got MaxDeliveryCount set to one processing attempt. Either way, check DeadLetterReason and DeadLetterErrorDescription headers/properties for the reason message got moved into dead-letter queue.
can anyone suggest me how to read messages from topic using multiple subscribers at a time.
Azure Service Bus supports competing consumer pattern, you don't have to do anything special.

Move all messages from deadletter queue back into main queue of subscription

My service consumes messages from an Azure Service Bus subscription. A dependency of my service was down for a while, which caused a lot of messages to end up in the deadletter queue (DLQ). Now that the service is back up, I want to reprocess all messages from the DLQ. How can I move/resubmit all messages from the DLQ back in to the main queue.
Restrictions:
It's thousands of messages, so manually handling them isn't feasible.
The topic has about ten subscriptions. I don't want to resubmit the messages to the topic, because then all subscriptions would receive the messages, leading to double-processing.
I don't want to run the service against the DLQ directly, because some messages are broken and cause permanent errors, i.e. they would end up in the DLQ again, which would lead to an infinite loop. Moreover, the broken messages are put back at the front of the queue, effectively starving healthy messages that come after the broken ones.
I realize this is a while after the original post but if anyone else stumbles on this problem, there is a fairly handy solution baked into the Service Bus Explorer (which I have found to be incredibly handy with ASB development).
After connecting to your Service Bus and finding the needed namespace, find the desired topic and subscription with the deadletters in it. From there Right Click and Receive Deadletter Queue Messages and hit OK.
From there, highlight which you would like to send back to the main queue and hit Resubmit Selected Messages in Batch Mode.
Thomas, you probably already found your answer since this is quite awhile ago. think of DLQ (or any existing queue that you have) as just another collection variable like in a PC app, but residing on the cloud. just like a PC-app or in-memory collection variable from your tool-kit, you have many ways of utilising it. off course there are limitations and differences between these 2 types of collection variables, but that's how you design your solution as though the DLQ is just another collection variable by knowing those limitations and differences.
For some queuing implementations, one of the solutions would be to have another instance of the same app pointing to the DLQ, but with a fairly long visibility timeout (e.g. 6 or 12 or even 24 hours depending on your SLA), since you don't want to repeat them too often. However, this is not applicable to Azure service bus, as it limits the visibility timeout to at most 5 minutes.
if the DLQ contains broken un-recoverable jobs, you should fix the app to delete them based on the error messages when the unknown exception occurred. once the fix is deployed, such broken un-recoverable jobs would have been removed by your app and never get sent to the DLQ in the first place. and those already in the DLQ will be removed by the fixed app.
The only option to replay DLQ messages is to receive them from DLQ, create new message with same content and send it again to the topic. They will end up at the end of subscription queue.
You can't send messages directly to the subscription. There is a trick to add a metadata property to the message, and then adjust all except one subscription to filter out such messages. It's up to you to decide if it's going to help in your scenario.
As for tooling, we always did that with custom code, because we always needed some extra work to be done, like logging each replayed message for further analysis.
The quick answer is that you cannot directly move messages back to the main queue of a subscription. This is by design with how Microsoft implemented their topics and subscriptions.
Option #1
There is the option to use Azure Service Bus topic filters https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters and define/tag your messages in a manner that would only allow them to be received on the targeted subscription.
Option #2
The other option would be to change your current implementation. You would set up "delivery queues" (regular service bus queues) and configure each corresponding subscription to auto forward its messages to these delivery queues. Your message processing logic would then listen on these "delivery queues" vs the subscription. Any failures would then result in DLQ messages on these associated "delivery queues" which could then be handled outside of the topic/subscriptions.

Azure service bus - Topic full

I have a process(Process A) that keeps sending events to an ASB topic. There are multiple consumers of the topic and therefore multiple subscriptions. So lets say that one of the consumer's process is down. And due to this the topic gets full as the messages are not consumed. Does this mean then Process A also fails as it is not able to send messages to ASB topic as its full?
Two more things to check:
Make sure that your dead letter queue is not full that counts towards the size of the entity.
Make sure that you have at least one subscription that works for each message. For example, if you send a message with ID=1, but you only have a subscription with ID=2, the messages will get backed up.
I think you are correct, once the limit is reached the queue stops.
However, with partitioning (using all 16 partitions * 5 GB), you can store up to 80 GB:
https://azure.microsoft.com/en-us/blog/partitioned-service-bus-queues-and-topics/
Another solution is to use auto forwarding, so the topic forwards all messages to another queue/topic
https://azure.microsoft.com/en-us/documentation/articles/service-bus-auto-forwarding/
This way each subscriber can have it's own queue of 5GB (or 80GB if you use partition)
Some more info:
https://azure.microsoft.com/nl-nl/documentation/articles/service-bus-azure-and-service-bus-queues-compared-contrasted/
https://azure.microsoft.com/en-us/documentation/articles/service-bus-quotas/

Azure ServiceBus PeekBatch method returns wrong number of records

I have an Azure queue (ServiceBus Topic Subscription DeadLetter queue) with ~900 messages. I would like to list them for debug purposes. I call PeekBatch method with parameter messageCount set to 100. I expect to get 100 messages but I only receive 69. Why is that???
I ran into a similar issue recently where the reported Active Message Count number was higher than the actual number of messages that could be read. After some investigation, I contacted Microsoft's Azure support team. Here's what they told me:
After researching I see that there is bug about this where the count is not showing correct value. The bug is active so it’s not resolved. Product group is tracking it but I don’t have any ETA on it.
Although in my case it's the Active Message Count that was off, this could very well be the same issue.
I found a way (that only works some of the times - I don't know why) to correct the message count. Use Service Bus Explorer, select the topic that is displaying the issue, hit Update (without having changed any of the settings) and then hit Refresh.
I also had the same issue, when I tried to peek messages from queue which is enabled partitioning. if I use PeekBatch method with passing message count as parameter, I can read only some of the messages even the actual message count was higher than that.
Partition queue - Partitioned queue consists of multiple fragments handled by different message brokers. when a message is sent to the partitioned queue, Service Bus assigns the message to one of the fragments. When a client wants to receive a message from a queue, Service Bus checks all fragments for messages. if it finds any, it picks one and passes to the receiver.
So, When we try to get messages using PeekBatch() method, it checks the fragments for messages and picks the messages from the fragment which it found at first, even if it is not matched with the given message count.

Resources