Azure Servicebus queue, BrokeredMessage.SequenceNumbers are not continuous - azure

I'm using this MessageReceiver.ReceiveBatchAsync Method to receive a batch of messages from a service bus queue.
https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.servicebus.messaging.messagereceiver.receivebatchasync?view=azure-dotnet
BrokeredMessage has a SequenceNumber, but sometimes the numbers are not continuous. Does that mean some messages lost.
How can I make this continuous?

BrokeredMessage has a SequenceNumber, but sometimes the numbers are not continuous. Does that mean some messages lost
The message sequence is set on the broker whenever the broker receives messages. So if you have scheduled messages and it's not the time yet, you'll have a gap between message sequence numbers. Messages are not lost once received by the broker. You shouldn't use sequence numbers as indicators.

Related

What are outgoing messages in Service Bus?

I need help interpreting this graph:
It looks like messages are coming in, then being processed, and going back to 0. The graph is not continually rising.
However, the outgoing messages has "--". Does this mean 0?
Does an outgoing message represent a message being read by a service?
If the messages are not being read, then what is happening to them? The dead letter queue has 0 messages.
Yes, an outgoing message represents a message being read by a service.
In your case, I see you've disabled the dead letter queue(in your screenshot, the Dead lettering option is disabled.), so there is no messages in the DLQ. If DLQ is disabled, the messages will be got deleted after expired.
The docs describes them like this:
The number of events or messages received from Service Bus over a specified period.
So, the incoming messages are message that are sent to the service bus. The outgoing messages are messages that are picked up by message processors (your application). So the answer to your question
Does an outgoing message represent a message being read by a service?
is: Yes!

Azure Service Bus: Duplicate messages are processing in message queue

I am working on Azure Service Bus. My service bus queue is processing one message 3 times. My lock time of message is 5 minutes. Every message is processing max of 2 mins but I don't know why the queue is picking same message and sending to processing and the duplicate messages are picking after 5 mins only.
How can I resolve this?
With Azure Service Bus messages will be re-processed when a message is not actioned by the receiving party. An action would be completing, deferring, dead-lettering. If you don't have any of those, once LockDuration on the broker side expires, the message will be re-delivered. Additional situation when a message would be re-delivered without waiting for LockDuration to time out would be to abandon a message. Then a message is picked up right away by the next request for new messages.
You should share your code to provide enough context. Messages can be received manually using MessageReceiver.ReceiveAsync() or using user-callback API. For the first option you have to action messages (complete for example). For the other option, there's a configuration API where you could opt-out of auto-completion and would be required manually complete message passed into user-callback.

How to put a message at the end of MQRabbit Queue

I'm working on a worker which is able to treat message from a RabbitMQ.
However, I am unsure of how to accomplish this.
If I receive a message and during my treating an error occurs, how can I put the message into the end of the queue?
I'm trying to using nack or reject, but the message is always re-put in the first position, and other messages stay frozen!
I don't understand why the message has to be put in the first position, I'm trying to "play" with other options like requeue or AllupTo but none of them seem to work.
Thank you in advance!
Documentation says:
Messages can be returned to the queue using AMQP methods that feature a requeue parameter (basic.recover, basic.reject and
basic.nack), or due to a channel closing while holding unacknowledged
messages. Any of these scenarios caused messages to be requeued at the
back of the queue for RabbitMQ releases earlier than 2.7.0. From
RabbitMQ release 2.7.0, messages are always held in the queue in
publication order, even in the presence of requeueing or channel
closure.
With release 2.7.0 and later it is still possible for individual
consumers to observe messages out of order if the queue has multiple
subscribers. This is due to the actions of other subscribers who may
requeue messages. From the perspective of the queue the messages are
always held in the publication order.
Remember to ack your successful messages, otherwise they will not be removed from the queue.
If you need more control over your rejected messages you should take a look to dead letter exchanges.
nack or reject either discard the message or re-queue the message.
For your requirement following could be suitable,
Once the consumer receives the message, just before start processing it, send ack() back to rabbitmq server.
Process the message then after, If found any error in the process then send ( publish ) the same message into the same queue. This will put the message at the back of the queue.
On successful processing do nothing. ack() has been already sent to rabbitmq server. Just take the next message and process it.

Azure Service Bus pub/sub - Receive vs Peek

What is the difference between Receive and Peek in the context of Azure Service Bus Topics?
Peek: This method enables you to view messages without locking or receiving them.
Receive: Can work in 2 modes: PeekLock (receives the message but keeps it peek-locked until the receiver abandons the message. The maximum timeout is 5 minutes before message expiration) and ReceiveAndDelete (deletes the message after it is received).
So this means you'll use the Peek when your goal is to look at the messages without actually consuming them (maybe you're building a "Queue browser", ... or your process needs to decided if it wants/can consume the message). And you'll use Receive when you're really planning to consume the message and do whatever you need to do with it.
Here is documentation on the PeakLock and ReceiveAndDelete values for ReceiveMode. Note that PeakLock is the default.

Service bus QueueClient returns null brokered message even queue has thousands of messages

I am using Service Bus Queue to pass items from producer to consumer. Producer is able to successfully send the items to the queue and consumer was receiving correctly but then it is showing weird behavior where receive method returns null (with no error) brokered message even if the queue has thousands of message. What is wrong with my queue?
One thing to mention here is that in testing I called the Close() method on the queue. But it was done only once and while testing. But now every time I run the receive methods return null brokered message.
The messageCount can include messages from sub-queues such as dead-lettered and scheduled messages. If all your messages have expired then you will have to create a receiver to the dead-lettered subqueue to get them.

Resources