user2023861
user2023861

Reputation: 8208

How do I kill a RabbitMQ connection in C# or using a Windows command?

I'm using RabbitMQ.Net for messaging and I want to test out different scenarios. In one case, I want to see what happens when a connection goes down. How can I force a connection to go down in the middle of a test?

Using the "Hello World" example here as an example, I'd like to do this:

  1. Set up the sender and receiver
  2. Send a message
  3. Make a C# call or run a windows command to kill the connection. Do this before the receiver has a chance to receive the message
  4. See what happens to both the sender and the receiver

How do I do step #3?

Upvotes: 0

Views: 956

Answers (1)

theMayer
theMayer

Reputation: 16157

The behavior of RabbitMQ is well-defined in this regard, so I'm not sure what the point of the test is (the build already presumably has automated tests for this behavior).

If RabbitMQ is set up with a heartbeat, the dropped TCP socket will be picked up once two heartbeat intervals pass. If not, then the dead socket will be picked up when the next network operation is attempted. This is due to how TCP works.

Once the dropped socket is picked up, the application connection close logic will be triggered. This involves sending the connection close and channel close events. I did a quick read through the .NET client documentation and it looks like they've implemented some auto-recovery. You'd probably have to read through the code to find out what exactly it does, and frankly, I wouldn't trust it as far as I could throw it. I'd prefer to handle re-connection manually.

Upvotes: 3

Related Questions