spring amqp - RabbitMQ cluster fail-over issue -
created cluster 2 rabbitmq nodes. configuration below rabbit1 , rabbit2 nodes.
1> cachingconnectionfactory connectionfactory = new cachingconnectionfactory(); connectionfactory.setaddresses("rabbit1:5672,rabbit2:5672"); 2> node types rabbit1 - disc node rabbit2 - ram node 3> producer , consumer programs sits on rabbit2 node(ie> ram node)
4> producer sample code - string queuename = "queue."; for(int m=0; m<50000; m++){ // send message system.out.println(this.rabbittemplate.getconnectionfactory().gethost()); this.rabbittemplate.convertandsend(m); /*thread.sleep(100);*/ } 5> consumer code - string queuename = "queue."; public void run() { system.out.println("consumer running host : " + this.connectionfactory.gethost()); simplemessagelistenercontainer container = new simplemessagelistenercontainer(); container.setconnectionfactory(this.connectionfactory); container.setqueuenames(this.queuename); container.setmessagelistener(new messagelisteneradapter(new testmessagehandler(this.connectionfactory.gethost()), new jsonmessageconverter())); container.start(); } testmessagehandler class sample code- public testmessagehandler(string hostname){ system.out.println("host: " + hostname); this.hostname = hostname; } // handle message public void handlemessage(int message) { system.out.println("handlemessage host: " + this.hostname); system.out.println("int : " + message); } 6> each node executed below policy cmd> rabbitmqctl set_policy ha-all "^queue\." "{""ha-mode"":""all""}" 7> started producer , consumer simultaneously. see host name "rabbit1" stopped "rabbit1" node "rabbitmqctl stop_app" command test fail-over scenario. got below error warn [.listener.simplemessagelistenercontainer]: consumer raised exception, processing can restart if connection factory supports com.rabbitmq.client.shutdownsignalexception: connection error; reason: {#method<connection.close>(reply-code=541, reply-text=internal_error, class-id=0, method-id=0), null, ""} @ com.rabbitmq.client.impl.amqconnection.startshutdown(amqconnection.java:678) @ com.rabbitmq.client.impl.amqconnection.shutdown(amqconnection.java:668) @ com.rabbitmq.client.impl.amqconnection.handleconnectionclose(amqconnection.java:624) @ com.rabbitmq.client.impl.amqconnection.processcontrolcommand(amqconnection.java:598) @ com.rabbitmq.client.impl.amqconnection$1.processasync(amqconnection.java:96) @ com.rabbitmq.client.impl.amqchannel.handlecompleteinboundcommand(amqchannel.java:144) @ com.rabbitmq.client.impl.amqchannel.handleframe(amqchannel.java:91) @ com.rabbitmq.client.impl.amqconnection$mainloop.run(amqconnection.java:523) info [.listener.simplemessagelistenercontainer]: restarting consumer: tag=[amq.ctag-5cj3yjyfmzdnjonxsds6_q], channel=cached rabbit channel: amqchannel(amqp://guest@192.168.97.70:5672/,1), acknowledgemode=auto local queue size=0 after warning, again getting host name "rabbit1" only. should "rabbit2" per understanding not happening. so, here queries - 1> why getting host name "rabbit1" after stopping? 2> test fail-over require load balancer? 3> if steps wrong testing fail-over case, please provide steps same? 4> how distribute queues/messages particular node, below, 1-500 messages/queues node1, 501-1000 messages/queues node2, etc. 5> please let me know there other approach test fail-over scenario? appreciate on this.
Comments
Post a Comment