![](/img/trans.png)
[英]Spring Configuration for JMS (Websphere MQ - SSL, Tomcat, JNDI, Non IBM JRE)
[英]Spring Tomcat configuration for JMS (IBM MQ, Tomcat, Spring)
我有一個使用Websphere MQ進行消息傳遞的相對較舊的應用程序。 它運行在WAS(Websphere應用程序服務器)上,並使用MDB(消息驅動Bean)。 我必須從Websphere遷移該應用程序,以便Tomcat
我使用springboot進行了一些嘗試,並且能夠編寫一個示例JMS應用程序,該應用程序連接到隊列並讀取消息,並且能夠處理它們,但尚未使用JMS實現事務管理。 現在,我被要求配置該應用程序,以便它在tomcat上運行。 任何人都可以幫忙,我在tomcat中如何以及在哪里設置配置。 或者,如果將springboot應用程序打包為war並將其部署在Tomcat上,那么將需要進行哪些更改。
這就是我在applicationconfig.java中的代碼的樣子
@Bean(name = "mqQueueConnectionFactory")
public MQQueueConnectionFactory mqQueueConnectionFactory() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
try {
mqQueueConnectionFactory.setHostName("hostname");
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setCCSID(1208);
mqQueueConnectionFactory.setChannel("channel");
mqQueueConnectionFactory.setPort(1415);
mqQueueConnectionFactory.setQueueManager("qManager");
} catch (Exception e) {
System.out.println("MQQueueConnectionFactory bean exception" + e);
}
return mqQueueConnectionFactory;
}
@Bean
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(
MQQueueConnectionFactory mqQueueConnectionFactory) {
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
userCredentialsConnectionFactoryAdapter.setUsername("");
userCredentialsConnectionFactoryAdapter.setPassword("");
userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(mqQueueConnectionFactory);
return userCredentialsConnectionFactoryAdapter;
}
@Bean
@Primary
public CachingConnectionFactory cachingConnectionFactory(
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter) {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(userCredentialsConnectionFactoryAdapter);
cachingConnectionFactory.setReconnectOnException(true);
return cachingConnectionFactory;
}
@Bean
public JmsOperations jmsOperations(CachingConnectionFactory cachingConnectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
jmsTemplate.setReceiveTimeout(50000);
return jmsTemplate;
}
@Bean(name = "wmq")
public JmsComponent wmQ(@Value(AppConstants.WMQ_CONNECTION_TYPE) int connType,
@Value(AppConstants.WMQ_HOST) String hostName,
@Value(AppConstants.WMQ_PORT) Integer port,
@Value(AppConstants.WMQ_QUEUE_MANAGER) String queueManager,
@Value(AppConstants.WMQ_CHANNEL) String channel,
@Value(AppConstants.WMQ_CONCURRENT_CONSUMERS) int concurrentConsumers,
@Value(AppConstants.WMQ_USERNAME) String username,
@Value(AppConstants.WMQ_PASSWORD) String password
) throws JMSException {
JmsComponent jmsComponent = new JmsComponent();
MQConnectionFactory mqConnectionFactory = new MQConnectionFactory();
try {
mqConnectionFactory.setTransportType(connType);
mqConnectionFactory.setHostName(hostName);
mqConnectionFactory.setPort(port);
mqConnectionFactory.setQueueManager(queueManager);
mqConnectionFactory.setChannel(channel);
jmsComponent.setConnectionFactory(mqConnectionFactory);
JmsConfiguration jmsConfiguration = new JmsConfiguration(mqConnectionFactory);
jmsConfiguration.setUsername(username);
jmsConfiguration.setPassword(password);
jmsConfiguration.setConcurrentConsumers(concurrentConsumers);
jmsComponent.setConfiguration(jmsConfiguration);
} catch (JMSException e) {
String msg = "Error while creating IBM MQ Connection Factory";
throw new JMSException(msg);
}
return jmsComponent;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.