【发布时间】:2022-02-17 21:41:07
【问题描述】:
我在我的 Spring Boot 应用程序中使用以下 Maven 依赖项和类向 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);
}*/
}
如何在同一应用程序中使用同一个类或任何其他类也将消息发送到 IBM MQ?如果我添加以下依赖项,@Autowired JmsTemplate 的行为会如何?
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>2.5.0</version>
</dependency>
【问题讨论】:
-
我认为这与您拥有多个数据库时相同(例如)。您必须使用“@Qualifier”定义“@Bean”并根据需要注入其中一个。数据源示例:stackoverflow.com/questions/30337582/…
标签: spring-boot activemq ibm-mq spring-jms