javaapache-camelactivemq-classic

Active MQ / Camel - setting the durable client ID


I am using a CachingConnectionFactory to set up the activeMQ context for camel; and then camel itself for connecting to active MQ.

When I run my application, it throws the following error:

setClientID call not supported on proxy for shared Connection. Set the 'clientId' property on the SingleConnectionFactory instead.

The relevant code is as follows:

ActiveMQComponent amqComponent = new ActiveMQComponent();
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
cf.setBrokerURL("tcp://" + amqServer + ":" + amqPort + "?jms.watchTopicAdvisories=false");
            
UserCredentialsConnectionFactoryAdapter uca = new UserCredentialsConnectionFactoryAdapter();
uca.setUsername(amqUser);
uca.setPassword(amqPassword);
uca.setTargetConnectionFactory(cf);
            
CachingConnectionFactory ccf = new CachingConnectionFactory(uca);
ccf.setClientId(amqClientID);
            
amqComponent.setConnectionFactory(ccf);
amqComponent.setMaxConcurrentConsumers(1);

context.addComponent("activemq", amqComponent);

...

from("activemq:topic:" + amqFeedTopic + "?clientId=" + id + "&durableSubscriptionName=" + id + "-sub")
.id(id)
.bean(messageHandlerClass, "process")
.to("kafka:" + kafkaTopic + "?brokers=" + kafkaBootstrapServers);

Solution

  • I am setting the client ID twice - once in the CCF and once in the camel code.

    It should be removed from the camel code:

    from("activemq:topic:" + amqFeedTopic + "?durableSubscriptionName=" + id + "-sub")

    and then this will work.

    Note if you don't want a durable subscription, just remove the durableSubscriptionName part altogether.