Hello,
I noticed that my channel get stuck when the node to which the channel had been created is crashed.
Situation.
I have 3 nodes
node1
node2
node3
Node1 holds the master queue and node2 and node3 hold the slave queues. Channel is created to the node1. When I shutdown the node1 my application gets stuck. I want to configure my application to reconnect to another node, recreate a channel and continue to work normaly.
Here is my code:
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUsername("admin");
connectionFactory.setPassword("adminpass");
connectionFactory.setRequestedHeartbeat(60);
connectionFactory.setAutomaticRecoveryEnabled(true);
connectionFactory.setTopologyRecoveryEnabled(true);
connectionFactory.setNetworkRecoveryInterval(5000);
Address[] addrArr = new Address[]{ new Address("192.168.0.77", 5672)
, new Address("192.168.0.78", 5672), new Address("192.168.0.79", 5672)};
ExecutorService es = Executors.newFixedThreadPool(20);
conn = connectionFactory.newConnection(es, addrArr);
Channel ch = conn.createChannel();
ch.queueDeclare(QUEUE_NAME, true, false, false, null);
ch.addConfirmListener(new RabbitMQConfirmListener(unconfirmedMessagesMap));
ch.confirmSelect();
try {
for(int i=0;i<100000;i++){
ch.basicPublish("", QUEUE_NAME,
MessageProperties.PERSISTENT_BASIC,
task.getBody());
}
} catch (Exception e) {
System.out.print(e);
try {
AMQP.Basic.RecoverOk recoverOk = ch.basicRecover();
} catch (IOException e1) {
LOG.error("CHANNEL RECOVER ERROR!");
e1.printStackTrace();
}
}
I start my application and it starts to publish messages. After that I shutdown node1 and my application stops forever. I don't see any errors so, it doesn't throw any exceptions. How to handle this situation? How to be able to recreate a channel? My new master successfuly changes but application can not continue to work.
Sincerely,
Alexandr