3

I am new to Spring JMS. My application is developed using Spring Boot and is deployed in JBoss EAP 7.2.0. I have a remote queue which is an Active MQ Artemis queue which is also embedded within JBoss EAP 7.2.0. Can anyone please suggest me how to send a message to the remote JMS queue using JmsTemplate of Spring Boot? Basically I am not getting how should I define the remote connectionFactory to connect to the remote queue.

Anirban
  • 925
  • 4
  • 24
  • 54

1 Answers1

2
  1. Add the following to application properties as your application is deployed in application server
  spring.jms.jndi-name=java:/<your connection factory name for artemis>
  1. Add artemis dependency and let spring boot autoconfigure jmsTemplate
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-artemis</artifactId>
   </dependency>
  1. Autowire jmsTemplate and send message
@Component
public class MyMessageSender {

        @Autowired
        JmsTemplate jmsTemplate;


        public void send(String msg){
                jmsTemplate.convertAndSend("my.queue.name", msg);
        }
}
  1. Optionally you can configure message converters and send pojos as message and let spring take care of converting it to json. For example
    @Bean // Serialize message content to json using TextMessage
    public MessageConverter jacksonJmsMessageConverter() {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
    }
  • My queue is located on a remote server, so where will I provide the INITIAL_CONTEXT_FACTORY, PROVIDER_URL, SECURITY_PRINCIPAL and SECURITY_CREDENTIAL? – Anirban Jun 19 '20 at 04:32
  • https://developers.redhat.com/quickstarts/eap/helloworld-jms/?referrer=jbd, in this example source code, a Connectionfactory is created first. So you can extract that part and define a ```@Bean public ConnectionFactory connectionFactory(){...}``` (This is one of the beans created by ```JndiConnectionFactoryAutoConfiguration``` and it won't do as you will be configuring one) – Kavithakaran Kanapathippillai Jun 19 '20 at 06:29