0

I am using spring JMS to connect to WSO2MB server. Everything is working fine, but all listeners are assigned the same id. To make it unique, I provided clientId but it is not working. I am not finding any other field where I can provide the name.

I even provided id on the JMS listener but no success.

@Bean
@ConditionalOnProperty(name="my.listener.active", matchIfMissing = true)
public JmsListenerContainerFactory jmsListenerContainerFactory(@Qualifier("listenerConnectionFactory") ConnectionFactory connectionFactory) throws URLSyntaxException {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setClientId("listener"+listenerTopic);
    if (Boolean.valueOf(listenerTopic)) {
        factory.setSubscriptionDurable(true);
        factory.setPubSubDomain(true);
    }
    return factory;
}

@JmsListener(destination = "${default-queue-name-to-listen}", id = "${default-queue-name-to-listen}")
public void receiveMessage(final Message<T> message) throws JMSException {
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
krmanish007
  • 6,749
  • 16
  • 58
  • 100
  • did you need the same id's used after application restart ?? this is the problem. if not you can add "listener"+listenerTopic+System.currentTimeMillis() – Hassen Bennour May 03 '17 at 12:15
  • I want the same name for each service, so even if multiple instance running, they will share the same name. But different service should have different name – krmanish007 May 03 '17 at 12:24

2 Answers2

0

each connection need to have a unique clientID

void org.apache.activemq.ActiveMQConnectionFactory.setClientID(String clientID)

Sets the JMS clientID to use for the created connection. Note that this can only be used by one connection at once so generally its a better idea to set the clientID on a Connection

your solution is to use org.springframework.jms.connection.SingleConnectionFactory

Hassen Bennour
  • 3,885
  • 2
  • 12
  • 20
  • I am already setting clientId: factory.setClientId("listener"+listenerTopic); – krmanish007 May 03 '17 at 13:17
  • yes but if you create more than 1 connection this will fails, but SingleConnectionFactory creates only one connection and you can SingleConnectionFactory.setClientId("listener"+listenerTopic); – Hassen Bennour May 03 '17 at 13:19
  • Ok, I will try that, though I am not sure how it will impact, as I am using docker and multiple instances will still create one of each. Currently, I am having some server problem, so once resolved, I will try this. Thanks – krmanish007 May 03 '17 at 13:26
  • Oh sorry i do not understood that you have multiple instances of the application, in this case my solution will not work like this and so maybe you can add the hostname or instance id to the cliend id with SingleConnectionFactory injected by propertyplaceholder from a file properties – Hassen Bennour May 03 '17 at 14:50
0

subscription name made the connection name unique and resolved my problem

@JmsListener(
        destination = "${default-queue-name-to-listen}",
        subscription = "${default-queue-name-to-listen}"
    )
    public void receiveMessage(Message<T> message) throws JMSException {}
krmanish007
  • 6,749
  • 16
  • 58
  • 100