Jason Rowe

Be curious! Choose your own adventure.

RabbitMQ Client Connection Issues

If you suspect issues with your RabbitMQ client you can test out connectivity problems using ToxiProxy.

Once ToxiProxy server is installed and running use the CLI to setup the proxy. The following command creates a local endpoint ‘localhost:5670’ which will proxy to ‘rabbitmq:5672’.

toxiproxy-cli-windows-amd64.exe create rabbitmq -l localhost:5670 -u rabbitmq:5672

With the proxy setup, you can configure your consumer to use ToxiProxy now. The following is an example C# consumer using EasyNetQ.

	using (var bus = RabbitHutch.CreateBus("host=localhost:5670"))
			{
				LogProvider.SetCurrentLogProvider(ConsoleLogProvider.Instance);

				var source = bus.Advanced.ExchangeDeclare("jgr.debug.connection.issue", "topic");
				var subscriptionQueue = bus.Advanced.QueueDeclare("jgr.debug.connection.issue.queue");

				bus.Advanced.Bind(source, subscriptionQueue, "#");

				bus.Advanced.Consume(
				subscriptionQueue,
				(body, properties, info) =>
				{
					var json = Encoding.UTF8.GetString(body);
					Console.WriteLine(json);
				});

				Console.ReadLine();
			}

Now start adding toxic conditions:

Example add timeout

toxiproxy-cli-windows-amd64.exe toxic add rabbitmq -t timeout -a timeout=10000

Example remove timeout

toxiproxy-cli-windows-amd64.exe toxic remove rabbitmq -n timeout_downstream

Example add slow close

toxiproxy-cli-windows-amd64.exe toxic add rabbitmq -t slow_close -a delay=12000

Example remove slow close

toxiproxy-cli-windows-amd64.exe toxic remove rabbitmq -n slow_close_downstream

Example add latency

toxiproxy-cli-windows-amd64.exe toxic add rabbitmq -t latency -a latency=12000

Example remove slow latency

toxiproxy-cli-windows-amd64.exe toxic remove rabbitmq -n latency_downstream

To take a closer look setup wireshark to investigate further.


Posted

in

by

Comments

2 responses to “RabbitMQ Client Connection Issues”

  1. Uma Avatar
    Uma

    Hi,
    I’m trying this with sample application for testing, I’m using RabbitMQClient.dll. Below is the code utilized, and the code breaks at this.rabbitMqConnection = factory.CreateConnection(); with exception RabbitMQ.Client.Exceptions.BrokerUnreachableException. Am i missing something?
    private IModel CreateChannel()
    {
    IModel model;
    if (this.rabbitMqConnection == null || (this.rabbitMqConnection != null && !this.rabbitMqConnection.IsOpen))
    {
    var factory = new ConnectionFactory() { HostName = “localhost” };//, UserName = “guest”, Password = “guest”, AutomaticRecoveryEnabled = true, TopologyRecoveryEnabled = true };
    factory.TopologyRecoveryEnabled = true;
    factory.AutomaticRecoveryEnabled = true;
    factory.Uri = new Uri(“amqp://guest:guest@localhost:5670”);
    factory.Ssl = new SslOption
    {
    Enabled = false,
    AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors,
    };
    this.rabbitMqConnection = factory.CreateConnection();
    }
    model = this.rabbitMqConnection.CreateModel();
    //model.ModelShutdown += Channel_ModelShutdown;
    return model;
    }

  2. Jason Avatar
    Jason

    Sorry this blog post assumes you have the RabbitMQ broker running at rabbitmq:5672. Ensure that endpoint is up and running by using the rabbitMQ management page.

Leave a Reply

Your email address will not be published. Required fields are marked *