Does ActiveMQ cluster (master-slave) offer high availability on failover mode? I am publishing messages on a topic but when I kill active node and my consumer connect to the other node It loses several messages. I need only topic mode, because I need to have different pods consuming messages at the same time. We have made test with durable messages and subscriptions wit we got the same problem.
If ActiveMQ doesn't support this functionality, is there other broker that could do this?
We have used Spring boot to develop sender and consumer apps.
SENDER:
To send messages we used and API REST that sends 5000 messages to a topic. If some convertAndSend fails (ActiveMQ node 1 killed) we retry it until the failover.
This is my sender class:
@RestController
public class RestApiController {
@Autowired
private JmsTemplate jmsTemplate;
@RequestMapping(value = "/produce")
public String produce() {
String result = "Done";
for (int i = 0; i < 5000; i++) {
boolean repetir = true;
while (repetir) {
try {
jmsTemplate.convertAndSend("TestTopic", "Message " + i);
repetir = false;
result = "Done";
} catch (JmsException e) {
e.printStackTrace();
result = "ERROR";
}
}
}
return result;
}
}
This is de sender's application.properties:
spring.activemq.broker-url=failover:(tcp://172.18.13.45:61616,tcp://172.18.13.45:61626)?initialReconnectDelay=1&backup=true spring.activemq.user=admin
spring.activemq.password=admin
spring.jms.pub-sub-domain=true
server.port=8081
CONSUMER:
This is my listener class:
@Service
public class ContactTransactionReceiver {
@JmsListener(destination = "TestTopic")
public void receiveMessageSendMessage(Message message) throws Exception {
System.out.println(((TextMessage) message).getText());
}
}
This is the consumer's application.properties:
spring.activemq.broker-url=failover:(tcp://172.18.13.45:61616,tcp://172.18.13.45:61626)?initialReconnectDelay=1&backup=true
spring.activemq.user=admin
spring.activemq.password=admin
spring.jms.pub-sub-domain=true
server.port=8082
ACTIVEMQ NODE 1
We have included this configuration in activemq.xml for HA, that refers to node2:
<persistenceAdapter>
<kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<networkConnectors>
<networkConnector uri="static:(tcp://172.18.13.45:61616,tcp://172.18.13.45:61626)" />
</networkConnectors>
We have proved too master-slave:
<persistenceAdapter>
<kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<networkConnectors>
<networkConnector uri="masterslave:(tcp://172.18.13.45:61616,tcp://172.18.13.45:61626)" />
</networkConnectors>
ACTIVEMQ NODE 2
We have included this configuration in activemq.xml for HA, that refers to node2:
<persistenceAdapter>
<kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<networkConnectors>
<networkConnector uri="static:(tcp://172.18.13.45:61626,tcp://172.18.13.45:61616)" />
</networkConnectors>
We have proved too master-slave:
<persistenceAdapter>
<kahaDB directory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<networkConnectors>
<networkConnector uri="masterslave:(tcp://172.18.13.45:61626,tcp://172.18.13.45:61616)" />
</networkConnectors>
You can find the full code and ActiveMQ configuration files in:
https://github.com/PedroRamirezTOR/ActiveMQ-HA-Sender-Consumer.git
Thanks in advance!