8

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?

viraptor
  • 33,322
  • 10
  • 107
  • 191
  • 1
    if you want to remove the consumer programmatically, calling the cancel method on the RabbitMQ channel should do. – asgs Aug 14 '18 at 13:33

3 Answers3

12

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

Hardy
  • 1,499
  • 2
  • 26
  • 39
10

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.

Brian Kelly
  • 19,067
  • 4
  • 53
  • 55
  • That did work, almost. For some reason there are two consumers, but there's only one connection assigned to one of them. The other consumer just... exists. Looking for an explanation of that situation now. – viraptor Aug 19 '11 at 10:00
  • No idea...if you restart your broker, does the problem remain? – Brian Kelly Aug 20 '11 at 01:30
0

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.