Reputation: 45
I am using the following Maven dependency and class in my Spring Boot application to send messages to ActiveMQ:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
@Component
@EnableJms
public class MQSender {
@Autowired
private JmsTemplate jmsTemplate;
public void sendMsgActiveMQ(String msg) {
jmsTemplate.convertAndSend("DEV.QUEUE1", msg);
}
/* public void sendMsgIBMMQ(String msg) {
jmsTemplate.convertAndSend("DEV.QUEUE1", msg);
}*/
}
How could I use the same class or any other class within the same application to send messages to IBM MQ as well? If I add the add the below dependency how will the @Autowired
JmsTemplate
behave?
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>2.5.0</version>
</dependency>
Upvotes: 1
Views: 1206
Reputation: 1045
You can get the IBM MQ client jars file with Maven dependency:
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
<version>9.1.0.6</version>
</dependency>
As to your @Autowired
question, your problem is ambiguity by type. You will need JMS connections factories for the two brokers that have the same type. The article here has some good suggestions.
I prefer to only @Autowire
in test cases, where the application context is small. For a practical application, I prefer explicit initialization. (maybe I'm just used to it). In any event, have a look here github for some examples that may have be useful.
Upvotes: 1