java - Active MQCamel - setting the durable client ID - Stack Overflow

admin2025-04-15  1

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);

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);
Share Improve this question asked Feb 4 at 12:02 simonalexander2005simonalexander2005 4,5974 gold badges53 silver badges104 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

转载请注明原文地址:http://www.anycun.com/QandA/1744721824a86708.html