You're mixing your paradigms. The persistenceAdapter portion of your config is all you need for a master/slave cluster, *as long as* your activemq.data variable resolves to the same value in both processes. (Both processes run on the same machine, right?) If so, the second broker started will pause in its initialization to wait for the filesystem lock to become available, and will not accept incoming connections from clients on its OpenWire ports. If the second broker accepts incoming connections, that's the problem, and you need to figure out why.
All the other broker settings you referenced (networkConnectors, TTL settings, the difference between static and masterslave transports, etc.) are related to networks of brokers, and should not be in use for a master/slave cluster (unless you're networking the cluster with other brokers, but you haven't described that), so take them out. For the message loss you're seeing, are you losing a few messages from right before the failover, or are you losing *all* of the messages from before the failover, or something else? If it's the former, you probably need to set alwaysSyncSend=true on your producer's connection factory. I'm not very familiar with JmsTemplate, so I'm not sure if you can set up a custom connection factory when using it, but if not then you can use the JMS API directly. Tim On Fri, Nov 30, 2018, 6:30 AM PedroRP <pedro.rami...@techonrails.com wrote: > 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> > > We have made test with durable messages and subscriptions wit we got the > same problem. Moreover, we also proved including networkTTL="2" > messageTTL="2" consumerTTL="2" and alwaysSyncSend="true" in both > networkConnectors but the same result. > > You can find the full code and ActiveMQ configuration files in: > > https://github.com/PedroRamirezTOR/ActiveMQ-HA-Sender-Consumer.git > <https://github.com/PedroRamirezTOR/ActiveMQ-HA-Sender-Consumer.git> > > Thanks in advance! > > > > -- > Sent from: > http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html >