简体   繁体   中英

Spring Tomcat configuration for JMS (IBM MQ, Tomcat, Spring)

I have a relatively old application that uses Websphere MQ for messaging. It runs on WAS (Websphere Application Server) and uses MDBs (Message Driven Beans). I have to migrate that application from Websphere so 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. Now I have been asked to configure the application so that it runs on tomcat. Can anyone please help, how and where I have to setup configuration in tomcat. Or what all changes will be required if package my springboot application as war and deploy it on Tomcat.

This is how my code in applicationconfig.java looks like

@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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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