How to see RabbitMQ messages - rabbitmq

Can't view rabbitmq queue messages after using the get messages command.
rabbitmqadmin get queue='queue_name' -H localhost -P 15672 -u rmq -p rmq --vhost=/ count=100
Queue count shows 100 messages, cant use the above command again to see the messages.

I would suggest to read https://www.rabbitmq.com/getstarted.html to understand how rabbitmq works.
The command get consumes the messages so you can't consume them anymore.
If you want to consume the same messages multi-times you can use the stream queue type.

When rabbitMq consumer consumes a mensagem from a queue the same will be deleted from the queue. If you just want to see the message you can log to the RabbitMQ Managment and read the messages, if they're not serialized. But if you want to consume the same message for some reason multiple times read the part of streams queue on the documentation.

Related

How can I track incoming messages in the rabbitmq queue via the console?

Our rabbitmq is running under kubernetes, I can only go into the console of the pod itself, I cannot access the web interface of rabbitmq. I want to track if the right message is coming to queue from the application, how can I do this ?
I only found rabbitmqctl list-queues, which shows message statistics at the time

Set a message limit to the RabbitMQ queue

I use both AMQP and MQTT protocols in RabbitMQ. I use the pica library for AMQP and the paho library for MQTT. I can give a message limit when I define the tail with Pika (x-max-length). But when I use paho for MQTT, I cannot limit the message. If I give the queue 50 message limit in the AMQP, the number of messages in the queue will never exceed 50. Why can't I do this on MQTT, is there another way I can set a message limit?
https://www.youtube.com/watch?v=xcpxGJuOyBQ
There is a sample video. The broadcaster sends the message fast, but because the receiver is slow, too many messages accumulate in the broker. I always want to receive the last message.
Using rabbitmqctl you can directly set maximum length for queue using policies instead of doing that using client libraries.
Example:
rabbitmqctl set_policy my-pol "^one-meg$" '{"max-length-bytes":1048576}' --apply-to queues
Take a look on Queue Length Limit in official docs.

RabbitMQ Manual Retry

How can manual retry work in RabbitMQ after a message has been put onto dead letter queue?
Does RabbitMQ provide an user interface through which you can do this? I assume here that RabbitMQ console does not provide you this capability.
The Rabbit MQ management interface would let you do this crudely, you can go into the deadletter queue, 'get' the message then copy the content. Go to the queue you want to retry the message on and 'publish' it directly to that queue.
Alternatively, you can enable the shovel plugin which allows you to move messages from one queue to another. The RabbitMQ Management plugin directly contains instructions on how to do this.
You can write a consumer / producer using a number of various client libraries. For python a popular library is pika (https://pypi.python.org/pypi/pika).
The script can consume all the messages in a queue, then publish them to another queue.

How can I read and log RabbitMQ message content?

I am sending a message to rabbitMQ, I want to read this message and log it into a file.
How can I do this?
In order to trace all the messages being exchanged on the RabbitMQ server you can use the firehose tracer.
You can activate/deactivate it with the commands:
rabbitmqctl trace_on
rabbitmqctl trace_off
Once activated, all the messages will be duplicated to the exchange amq.rabbitmq.trace.
Just bind a queue to it and consume from there. You can find a working example in our RabbitMQ Cookbook.
It should also be possible to directly trace the messages to file by using the rabbitmq_tracing plugin, but I have never tried it actually.

Way to break a connection from rabbitmq

I've got an application which has some bugs. For some reason 2 consumers are created when only one should be there - and one of them is not checked for messages anymore.
I can detect that situation by listing queues and the number of consumers on the server. Is there some way to destroy that consumer from the server side?
consumer can be kill by rabbitmqctl using close_connection input connectionpid
example
> rabbitmqctl close_connection "<rabbit#hardys-Mac-mini.1.4195.0>" "reason here"
connectionpid can get by
> rabbitmqctl list_consumers
Listing consumers ...
send_email_1 <rabbit#hardys-Mac-mini.1.4185.0> amq.ctag-oim8CCP2hsioWc-3WwS-qQ true 1 []
send_email_2 <rabbit#hardys-Mac-mini.1.4195.0> amq.ctag-WxpxDglqZQN2FNShN4g7QA true 1 []
RabbitMQ 3.5.4
You can kill connections to the RabbitMQ broker using the rabbitmqctl tool (see the man page) or by using the Web UI. You could also purge and delete the queue which belonged to the rogue consumer.
However, you can't kill the consumer process itself using those tools. You really should just focus on fixing the bugs in the application so that only the correct number of consumers get created.
You need to mark you consumer as "exclusive". Then only one consumer is registered with queue and other consumers are ignored even they tries to get data from that queue.