'Unable to publish message to Rabbitmq after master node is down

I have setup a cluster failover on 2 servers (say usernames dev_master and dev_slave). I have clustered the dev_slave to dev_master by running following commands

docker exec -it dev_slave rabbitmqctl stop_app docker exec -it dev_slave rabbitmqctl reset docker exec -it dev_slave rabbitmqctl join_cluster rabbit@dev_master docker exec -it dev_slave rabbitmqctl start_app docker exec -it dev_slave rabbitmqctl cluster_status

After running above steps, I can see 2 nodes in RabbitMQ UI under overview tab. Next I have enabled rabbitmq_federation using following command on both master and slave

rabbitmq-plugins enable rabbitmq_federation

And run the following policies

rabbitmqctl set_policy ha-fed "." '{"ha-mode":"nodes","ha-sync-mode":"automatic","ha-params":["rabbit@dev_master","rabbit@dev_slave"]}' --priority 1 --apply-to queues rabbitmqctl set_policy federate-me '.' '{"federation-upstream-set":"all"}'

After these I can see all the messages published to master are mirrored to slave as expected.

Now when I down master, I am not able to publish messages. I am getting following exception

None of the specified endpoints were reachable AggregateException: One or more errors occurred. (Connection failed) ConnectFailureException: Connection failed SocketException: No connection could be made because the target machine actively refused it.

If I am correct when master is down, the next node should be promoted as master and I should be still able to publish message without any issues. But that is not what I am seeing. Not sure what I am doing wrong. Can someone help me here plz.

RabbitMQ Versions - 3.8.7 Queue: Classic

Here is the code for publisher in c#.

    public class RabbitMQ
    {
        public IConnection GetConnection()
        {
            ConnectionFactory factory = new ConnectionFactory
            {
                UserName = "guest",
                Password = "guest",
                HostName = "dev_master",
                // HostName = "dev_slave",
                VirtualHost = "/",
                Port = 5672       
            };

            return factory.CreateConnection();

        }
        public void Send(IModel channel, string queue, string message)
        {
            channel.ExchangeDeclare("messageexchange", ExchangeType.Direct);
            channel.QueueDeclare(queue, true, false, false, null);
            channel.QueueBind(queue, "messageexchange", queue, null);

            var properties = channel.CreateBasicProperties();
            properties.DeliveryMode = 2;

            channel.BasicPublish("messageexchange", queue, properties, Encoding.UTF8.GetBytes(message));
        }        
    }

Thanks Lax



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source