<div dir="ltr"><div>Created Cluster with two rabbitMQ nodes. Configuration is as below for rabbit1 and rabbit2 nodes.</div><div><br></div><div> 1> CachingConnectionFactory connectionFactory = new CachingConnectionFactory();</div>
<div> connectionFactory.setAddresses("rabbit1:5672,rabbit2:5672");</div><div><br></div><div>2> node types</div><div>rabbit1 - disc node</div><div>rabbit2 - ram node</div><div>3> producer and consumer programs sits on rabbit2 node(ie> ram node)</div>
<div> </div><div> 4> Producer sample code -</div><div> String QueueName = "Queue.";</div><div> for(int m=0; m<50000; m++){</div><div> <span class="" style="white-space:pre">        </span>// send message</div>
<div> <span class="" style="white-space:pre">        </span>System.out.println(this.rabbitTemplate.getConnectionFactory().getHost());</div><div> <span class="" style="white-space:pre">        </span>this.rabbitTemplate.convertAndSend(m);</div>
<div> <span class="" style="white-space:pre">        </span>/*Thread.sleep(100);*/</div><div> }</div><div> </div><div> 5> consumer code -</div><div> String QueueName = "Queue.";</div><div> public void run() {</div>
<div> <span class="" style="white-space:pre">        </span>System.out.println("Consumer running host : " + this.connectionFactory.getHost());</div><div> <span class="" style="white-space:pre">        </span>SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();</div>
<div> <span class="" style="white-space:pre">        </span>container.setConnectionFactory(this.connectionFactory);</div><div> <span class="" style="white-space:pre">        </span>container.setQueueNames(this.queueName);</div><div>
<span class="" style="white-space:pre">        </span>container.setMessageListener(new MessageListenerAdapter(new TestMessageHandler(this.connectionFactory.getHost()), new JsonMessageConverter())); </div><div> <span class="" style="white-space:pre">        </span>container.start();</div>
<div> }</div><div> </div><div> TestMessageHandler class sample code-</div><div> </div><div> <span class="" style="white-space:pre">        </span>public TestMessageHandler(String hostName){</div><div> <span class="" style="white-space:pre">                </span>System.out.println("Host: " + hostName);</div>
<div> <span class="" style="white-space:pre">                </span>this.hostName = hostName;</div><div> <span class="" style="white-space:pre">        </span>}</div><div> <span class="" style="white-space:pre">        </span></div><div> <span class="" style="white-space:pre">        </span>// Handle message</div>
<div> <span class="" style="white-space:pre">        </span>public void handleMessage(int message) {</div><div> <span class="" style="white-space:pre">                </span>System.out.println("handleMessage Host: " + this.hostName);</div>
<div> <span class="" style="white-space:pre">                </span>System.out.println("Int : " + message);</div><div> <span class="" style="white-space:pre">        </span>}</div><div> <span class="" style="white-space:pre">        </span></div>
<div> 6> Each node executed below policy</div><div> cmd> rabbitmqctl set_policy ha-all "^Queue\." "{""ha-mode"":""all""}"</div><div> </div><div> 7> Started producer and consumer simultaneously. Could see host name as "rabbit1" then stopped "rabbit1" node with "rabbitmqctl stop_app" command to test fail-over scenario. Then got the below error</div>
<div> </div><div> WARN [.listener.SimpleMessageListenerContainer]: Consumer raised exception, processing can restart if the connection factory supports it</div><div> com.rabbitmq.client.ShutdownSignalException: connection error; reason: {#method<connection.close>(reply-code=541, reply-text=INTERNAL_ERROR, class-id=0, method-id=0), null, ""}</div>
<div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:678)</div><div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:668)</div>
<div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:624)</div><div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:598)</div>
<div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:96)</div><div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)</div>
<div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)</div><div> <span class="" style="white-space:pre">        </span>at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:523)</div>
<div> INFO [.listener.SimpleMessageListenerContainer]: Restarting Consumer: tag=[amq.ctag-5CJ3YJYfMZDnJOnXsds6_Q], channel=Cached Rabbit Channel: AMQChannel(amqp://<a href="http://guest@192.168.97.70:5672/,1">guest@192.168.97.70:5672/,1</a>), acknowledgeMode=AUTO local queue size=0</div>
<div> </div><div> after this warning, again am getting host name as "rabbit1" only. actually it should be "rabbit2" as per my understanding but its not happening.</div><div> </div><div> So, here are my Queries -</div>
<div> </div><div> 1> Why am getting host name as "rabbit1" even after stopping?</div><div> 2> To test the fail-over do we require any load balancer?</div><div> 3> If my steps are wrong for testing fail-over case, please provide steps for the same?</div>
<div> 4> How to distribute queues/messages to particular node, as below, 1-500 messages/queues to node1, 501-1000 messages/queues to node2, etc.</div><div> 5> Please let me know is there any other approach to test fail-over scenario?</div>
<div><br></div><div>Appreciate any help on this.</div><div><br></div><div><br></div><div><br></div></div>