activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From PedroRP <pedro.rami...@techonrails.com>
Subject Re: ActiveMQ HA on failover topic mode
Date Fri, 30 Nov 2018 13:30:28 GMT
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

Mime
View raw message