How can I get RabbitMQ Logs programatically? - rabbitmq

I wants to track which message is delivered or expired. How can i get it programatically ?
Help! if anyone knows about it.
Thanks in Advance.

In order to know if the message is delivered, you can use mandatory flag, then handle the result using basic.return
To know if a message is expired you can use dead letter exchange:
Dead Letter Exchanges
Messages from a queue can be 'dead-lettered'; that is, republished to
another exchange when any of the following events occur:
The message is rejected (basic.reject or basic.nack) with
requeue=false, The TTL for the message expires; or The queue length
limit is exceeded.

Related

How can I subscribe to a message being sent to the _skipped queue in rabbit mq

Question one: Can I subscribe to the event of a message being sent to the _skipped queue?
I am using masstransit together with rabbit mq. Some messages sometimes are sent to the _skipped queue for unclear reasons. The message type has a consumer, the ttl (time to life) is not small. It should not happen, and I am getting a log entry from masstransit, but I want to do more at the moment. Maybe log an error, in test maybe pop-up a window. Is there a way to achieve this? I am only getting these log messages below.
MassTransit.ReceiveTransport|SKIP rabbitmq://localhost/services_admin db270000-1fd6-00ff-3b83-08d9000ef97c
MassTransit.ReceiveTransport|Declare queue: name: services_admin_skipped, durable, consumer-count: 0 message-count: 3
Question two: What exactly happens to messages in the _skipped queue? Can they be resent?
Skipped messages either don't match the type (namespace included), don't have a consumer on the endpoint, or were a response to a request client that is no longer waiting for it. Since it's a receive endpoint queue, it's likely one of the first two reasons. Look at the message body/details in the RabbitMQ Management Console, that should give you some ideas.
You can use a shovel in RabbitMQ to move the messages back into the queue once you've resolved the issue.

How to keep only the last object in a RabbitMQ exchange?

I have a RabbitMQ exchange where I put quotes that change several times per second.
When a new message is sent to the exchange, I would like undelivered messages to be dropped and only the last one to be sent.
Is this possible?
I’m doing this in F# but an example in any language would be appreciated.
Just configure the queue to have a max-length of 1.
When the queue gets a new message, it will delete any older messages that are waiting in the queue.

Messages with expiration are not removed from RabbitMQ

I am sending a normal message through a producer to RabbitMQ and then I send a second message with the expiration attribute assigned to a value. Then using the rabbitmqctl list_queues command I monitor the status of the messages.
I found that if I send a normal message first and then a message with expiration, the rabbitmqctl list_queues is always showing me 2 messages pending on the queue. When I consume them, I get only one.
On the other hand if I send just 1 message with expiration, in the beginning I see the message and then after the correct expiration time, I find it deleted.
My question is, on the first situation is actually the message taking space? Or it is an interface bug?
My rabbitMQ version is:
rabbitmq-server.noarch -> 3.1.5-1.el6
Looks like you missed some of the documentation on this feature. If you read the RabbitMQ documentation on per-message TTL (expiration), you will notice the following warning for exactly the behavior you are seeing (emphasis added):
Caveats
While consumers never see expired messages, only when expired messages reach the head of a queue will they actually be discarded (or dead-lettered). When setting a per-queue TTL this is not a problem, since expired messages are always at the head of the queue. When setting per-message TTL however, expired messages can queue up behind non-expired ones until the latter are consumed or expired. Hence resources used by such expired messages will not be freed, and they will be counted in queue statistics (e.g. the number of messages in the queue).

RabbitMQ TTL maximum ms to sustain message in queue

I am using RabbitMq really amazing message broker, but what i need is to have long message back up time in the queue. So that if a message is not reached to certain consumers who were inactive at that time and they are active after few mins eventually the message should be delivered to the respective consumer through fanout exchange.
What i tried is i had increased TTL in queue. Whether it is the correct way or some other tricks can be done?
Thanks in advance
You could try to use a queue with x-message-ttl, and x-dead-letter-exchange
args.put("x-message-ttl", 10000);
args.put("x-dead-letter-exchange",exchange_dead_letter);
channel.queueDeclare(queue, false, false, false, args);
x-dead-letter-exchange is an exchange and if the message is expired by the TTL time, the message is redirect to the x-dead-letter-exchange.
Then you can handle the message as you prefer.
You can find more detail here: http://www.rabbitmq.com/dlx.html.

How does AMQ's redeliver work? Does it hold a consumer completely during the redelivery process?

Assuming that we only have one consumer and our redelivery policy will allow the message to be redelivered for a quite long time.
I've tried a scenario where I sent two messages(different type), one is designed to be redelivered and the other can be consumed normally.
It seems the normal message will be blocked if it is delivered later than the redelivered one.
It will not be consumed until the redelivered message has tried many times reaching the maximum redeliver times. That would lead to a situation where a easy-to-consumed message must wait a long time to be consumed..
I'm wondering how the AMQ redeliver work. When a message is redelivered in a consumer, the other message can be sent to this consumer until current message has been consumed or timeout(to DLQ).
Can someone help ? Thanks,
ActiveMQ's overriding concern when redelivering messages is to honour message ordering on a queue.
Given two messages A and B, which get sent to a queue with a defined redelivery policy as you describe: if a client fails processing A, that message will get placed back on the queue and no other messages will be consumed until A is consumed successfully.
Check out the ActiveMQ Message Redelivery and DLQ Handling section for further details.
Please remember to vote this response up if it answers your question.
For this case it is possible to set the ActiveConnectionFactory to onBlockingRedelivery.
Find details in de ActiveMq Api documentation: