在我的Spring Boot应用程序中,我想与ActiveMQ和WebsphereMQ连接,但是我有问题,因为当我想运行ActiveMQ队列的侦听器时,Spring Boot在WebsphereMQ的服务器上寻找此队列。当我想设置哪个队列为ActiveMQ和哪个队列为WebsphereMQ时,如何在Spring Boot中进行配置。
JMSConfig.java
@Configuration
@EnableTransactionManagement
public class JmsConfig {
@Value("${mq.host}")
private String host;
@Value("${mq.port}")
private Integer port;
@Value("${mq.queue-manager}")
private String queueManager;
@Value("${mq.channel}")
private String channel;
@Value("${mq.username}")
private String username;
@Value("${mq.password}")
private String password;
//@Value("${mq.sending.payment.quote.queue}")
//private String queueSendingPaymentQuote;
@Value("${mq.receive-timeout}")
private long receiveTimeout;
public static final String QUEUE_MAIL = "queue.mail";
public static final String QUEUE_MAIL_IMPORT = "queue.mail.import";
@Autowired
ApplicationProperties properties;
@Autowired
ConnectionFactory connectionFactory;
@Bean
public Queue queue() {
return new ActiveMQQueue(QUEUE_MAIL);
}
@Bean(name="QueueImport")
public Queue queueImport() {
return new ActiveMQQueue(QUEUE_MAIL_IMPORT);
}
//
/**
* @return
* @throws Exception
*/
@Bean
public BrokerService broker() throws Exception {
BrokerService broker = new BrokerService();
broker.addConnector(properties.getActivemqBrokerUrl());
PersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
File dir = new File(System.getProperty("user.home") + File.separator + "kaha");
if (!dir.exists()) {
dir.mkdirs();
}
persistenceAdapter.setDirectory(dir);
broker.setPersistenceAdapter(persistenceAdapter);
broker.setPersistent(true);
return broker;
}
@Bean(name = "mqQueueConnectionFactory")
public MQQueueConnectionFactory mqQueueConnectionFactory() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName(host);
try {
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setCCSID(1208);
mqQueueConnectionFactory.setChannel(channel);
mqQueueConnectionFactory.setPort(port);
mqQueueConnectionFactory.setQueueManager(queueManager);
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
@Bean
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(MQQueueConnectionFactory mqQueueConnectionFactory) {
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
userCredentialsConnectionFactoryAdapter.setUsername(username);
userCredentialsConnectionFactoryAdapter.setPassword(password);
userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(mqQueueConnectionFactory);
return userCredentialsConnectionFactoryAdapter;
}
@Bean
@Primary
public CachingConnectionFactory cachingConnectionFactory(UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter) {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(userCredentialsConnectionFactoryAdapter);
cachingConnectionFactory.setSessionCacheSize(500);
cachingConnectionFactory.setReconnectOnException(true);
return cachingConnectionFactory;
}
// @Bean(name="jmsTransactionManager")
// public PlatformTransactionManager jmsTransactionManager(CachingConnectionFactory cachingConnectionFactory) {
// JmsTransactionManager jmsTransactionManager = new JmsTransactionManager();
// jmsTransactionManager.setConnectionFactory(cachingConnectionFactory);
// return jmsTransactionManager;
// }
@Bean
public JmsOperations jmsOperations(CachingConnectionFactory cachingConnectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
jmsTemplate.setReceiveTimeout(receiveTimeout);
return jmsTemplate;
}
}
这是ActiveMQ的方法侦听器
@JsonCreator
@JmsListener(destination = JmsConfig.QUEUE_MAIL_IMPORT, containerFactory = "jmsListenerContainerFactory")
public void receiveMessageImport(String message) throws IOException {
MailDto mail = null;
mail = mapper.readValue(message, MailDto.class);
emailSender.sendEmailImport(mail);
}
我需要更改什么?