Trying to connect to remote ActiveMQ Artemis but getting below mentioned error

Viewed 22

Error which I am actually getting:

org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Failed to create session factory; nested exception is ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ219007: Cannot connect to server(s). Tried with all available servers.]
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:661)
at com.cox.fst.wfm.processor.TicketProcessor.processInboundTicket(TicketProcessor.java:68)...
.
.
.
Caused by: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Failed to create session factory; nested exception is ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ219007: Cannot connect to server(s). Tried with all available servers.]
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:661)
at com.cox.fst.wfm.processor.TicketProcessor.processInboundTicket(TicketProcessor.java:68)
... 108 common frames omitted
Caused by: javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:882)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:299)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:294)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)
... 111 common frames omitted
Caused by: org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException: AMQ219007: Cannot connect to server(s). Tried with all available servers.
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:708)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:880)
... 115 common frames omitted

Beans in Artemis config class for sender:

@Bean
public ActiveMQConnectionFactory connectionFactory() {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    JmsDefaultPrefetchPolicy prefetchPolicy = new JmsDefaultPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(prefetch);
    return factory;
}
@Bean
public JmsTemplate jmsTemplate(final ConnectionFactory connectionFactory) {
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
    jmsTemplate.setMessageConverter(producerJackson2MessageConverter());
    jmsTemplate.setDefaultDestinationName(queue);
    return jmsTemplate;
}

@Bean
public SimpleMessageConverter producerJackson2MessageConverter() {
    return new SimpleMessageConverter();
}

Beans in Artemis config class for receiver:

@Bean
public ActiveMQConnectionFactory connectionFactory() {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    JmsDefaultPrefetchPolicy prefetchPolicy = new JmsDefaultPrefetchPolicy();
    prefetchPolicy.setQueuePrefetch(prefetch);
    return factory;
}
@Bean
public DefaultJmsListenerContainerFactory amqpListnerFactory(final DefaultJmsListenerContainerFactoryConfigurer configurer, final ConnectionFactory connectionFactory) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    factory.setSessionTransacted(false);
    factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    factory.setConcurrency(concurrency);
    return factory;
}

prefetch ,queue, concurrency are constants.

My application.properties has

spring.artemis.embedded.enabled=false
spring.artemis.mode=native
spring.artemis.host=amqp://(service name).(namespace)
spring.artemis.port=61616
spring.artemis.user=****
spring.artemis.password=****

In sender:

jmsTemplate.convertAndSend(destination,message);

In receiver:

@JmsListener(destination = "${****}", containerFactory = "amqpListnerFactory")

Please help me solve the issue are please guide me in connecting remote ActiveMQ Artemis broker.

1 Answers

This line in your application.properties is problematic:

spring.artemis.host=amqp://(service name).(namespace)

This is a URL, not a hostname. You need to specify just a hostname (or an IP address) of your remote instance of ActiveMQ Artemis here. This is noted in the Spring Boot documentation, e.g.:

spring.artemis.mode=native
spring.artemis.host=192.168.1.210
spring.artemis.port=9876
spring.artemis.user=admin
spring.artemis.password=secret

Better yet, you should move to Spring Boot 3.x and use the broker-url property instead, e.g.:

spring.artemis.mode=native
spring.artemis.broker-url=tcp://192.168.1.210:9876
spring.artemis.user=admin
spring.artemis.password=secret

See more details in the Spring documentation.

Related