简体   繁体   English

JMS的Spring Tomcat配置(IBM MQ,Tomcat,Spring)

[英]Spring Tomcat configuration for JMS (IBM MQ, Tomcat, Spring)

I have a relatively old application that uses Websphere MQ for messaging. 我有一个使用Websphere MQ进行消息传递的相对较旧的应用程序。 It runs on WAS (Websphere Application Server) and uses MDBs (Message Driven Beans). 它运行在WAS(Websphere应用程序服务器)上,并使用MDB(消息驱动Bean)。 I have to migrate that application from Websphere so Tomcat 我必须从Websphere迁移该应用程序,以便Tomcat

I tried something using springboot and was able to write a sample JMS application that connects to queues and read messages and is able to process them but have not implemented transaction management with JMS. 我使用springboot进行了一些尝试,并且能够编写一个示例JMS应用程序,该应用程序连接到队列并读取消息,并且能够处理它们,但尚未使用JMS实现事务管理。 Now I have been asked to configure the application so that it runs on tomcat. 现在,我被要求配置该应用程序,以便它在tomcat上运行。 Can anyone please help, how and where I have to setup configuration in tomcat. 任何人都可以帮忙,我在tomcat中如何以及在哪里设置配置。 Or what all changes will be required if package my springboot application as war and deploy it on Tomcat. 或者,如果将springboot应用程序打包为war并将其部署在Tomcat上,那么将需要进行哪些更改。

This is how my code in applicationconfig.java looks like 这就是我在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM