Galadriel
Galadriel

Reputation: 369

ActiveMQ Artemis cluster: JMS ConnectionFactory

I want to setup an ActiveMQ Artemis HA cluster with 4 nodes: two masters, two slaves.

I already tried to to it with only one node, and it's working. Now I have to adapt the ConnectionFactory in my code so that it can connect with the cluster.

In the ActiveMQ Artemis documentation I found something like that:

@Bean
public ConnectionFactory connectionFactory() {    
    TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName());
    ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, transportConfiguration);
    return cf;
}

The JavaDoc says:

Creates an ActiveMQConnectionFactory that receives cluster topology updates from the cluster as servers leave or join and new backups are appointed or removed.

How can I set a specified url here for ssl use and so on?

@Bean
public ConnectionFactory connectionFactory() {    
    ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?sslEnabled=true&trustStorePath=activemq.example.truststore&trustStorePassword=activemqexample");
    return cf;
}

JMS connection factory, not further specified in documentation.

Are here topology infos downloaded?

What and how is the intended way of using it?

Upvotes: 0

Views: 1492

Answers (1)

Justin Bertram
Justin Bertram

Reputation: 35207

The topology information received by the client is only really used for failover. To create a JMS connection factory URL which supports failover simply add the ha parameter with the value true, e.g.:

tcp://localhost:61616?ha=true

If you need SSL/TLS configuration you can add that as well, e.g.:

tcp://localhost:61616?ha=true&sslEnabled=true&trustStorePath=activemq.example.truststore&trustStorePassword=activemqexample

If you want the URL to be able to potentially connect to any node in the cluster than you can add multiple host/port elements, e.g.:

(tcp://node1:61616,tcp://node2:61616,tcp://node3:61616,tcp://node4:61616)?ha=true&sslEnabled=true&trustStorePath=activemq.example.truststore&trustStorePassword=activemqexample

Instead of hard-coded host/port elements you can also use UDP discovery to find the cluster nodes, e.g.:

udp://231.7.7.7:9876?ha=true&sslEnabled=true&trustStorePath=activemq.example.truststore&trustStorePassword=activemqexample

The group address and port used here (i.e. 231.7.7.7:9876) should match the group address and port used by the broadcast-group configured for your cluster nodes. Also, keep in mind that the UDP packets used here are usually only transmitted across a single subnet.

Upvotes: 1

Related Questions