0

I am newbie to MQ, We are usgin spring boot with JMS + IBM MQ Framework. We are facing a very random issue where there is 5 - 15 min delay to execute send method of jmsQueueTemplate as below.

Random delay is Between //POINT 1 and //POINT 2

try {
                logger.info("Calling Send Method ");
                //POINT 1
                jmsQueueTemplate.send(new MessageCreator() {

                    public Message createMessage(Session session) throws JMSException {
                        JMSTextMessage message = null;
                        try {
                        //POINT 2
                        logger.info("Session Object ........ " + session.toString());
                        logger.info("Session Status  - Is Session Transacted ?........ " + session.getTransacted());
                        logger.info("Session Status acknowledge mode........ " + session.getAcknowledgeMode());
                        logger.info("Ready to send Sample message........ ");
                        logger.info("Send ConnectionFactory is: " + jmsQueueTemplate.getConnectionFactory().toString());
                        logger.info("Send destination is: " + jmsQueueTemplate.getDefaultDestination());
                        logger.info("Reply destination is: " + destination);
                        logger.info("Sent message correlationId is: " + correlationId);
                        logger.info("##########################################################");

                        message = (JMSTextMessage) session.createTextMessage();

                        String fosXmlBatchRequest = XMLUtil.createBatchFosRequestXML(oBatchFosRequest);
                        message.setText(fosXmlBatchRequest);
                        message.setJMSCorrelationID(correlationId);
                        logger.info(transactionType + " : Sending message is:");
                        logger.info(message.getText());
                        logger.info("##########################################################");
                        message.setJMSReplyTo(destination);

                        } catch (Exception e) {
                            logger.info("Exception Occured :" + e.getMessage());
                        }
                        return message;
                    }
                }); 
            } catch(Exception e) {
                logger.info("Exception while Sending Message To FOS",e);
                logger.info(e.toString(),e);
                logger.error("Exception while Sending Message To FOS",e);
                logger.error(e.toString(),e);
            }

we are not handling session object and letting spring take care of session creation . I am not sure when exacty is the delay getting introced ? Are we loosing session object ? Any suggestion pls.

Our spring configuration is as below .

import javax.jms.Destination;
import javax.jms.JMSException;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.MessageType;
import org.springframework.stereotype.Component;

import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnectionFactory;


/**
 * 
 * @author krna
 * This class defines configuration for JMS Queues required for FOS update.
 */

@Configurable
@Component
public class JMSConfiguration {

    private final Logger log = LogManager.getLogger(JMSConfiguration.class);

    @Autowired
    MessageListenerReciever messageListenerReciever1;

    @Autowired
    MessageListenerReciever messageListenerReciever2;

    private String hostName1;
    private String hostName2;
    private String hostName3;
    private String writePort;
    private String readPort;
    private String channel;
    private String transportType;
    private String updateQueue;
    private String replyQueue;
    private String queueGateway;

    @Autowired
    JMSConfiguration(Environment environment){
        this.hostName1 = environment.getRequiredProperty("jms.cf.write.hostName1");
        this.hostName2 = environment.getRequiredProperty("jms.cf.read.hostName2");
        this.hostName3 = environment.getRequiredProperty("jms.cf.read.hostName3");
        this.writePort = environment.getRequiredProperty("jms.cf.write.port");
        this.readPort = environment.getRequiredProperty("jms.cf.read.port");
        this.channel = environment.getRequiredProperty("jms.cf.channel");
        this.transportType = environment.getRequiredProperty("jms.cf.transportType");
        this.updateQueue = environment.getRequiredProperty("jms.queue.update");
        this.replyQueue = environment.getRequiredProperty("jms.queue.reply");
        this.queueGateway = environment.getRequiredProperty("jms.queue.gateway");
    }

    public MQQueueConnectionFactory connectionFactory1() {
        MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
        try {
            connectionFactory.setHostName(hostName1);
            connectionFactory.setPort(Integer.parseInt(writePort));
            connectionFactory.setChannel(channel);
            connectionFactory.setTransportType(Integer.parseInt(transportType));
        } catch (NumberFormatException | JMSException e) {
            log.error(e.toString(),e);
        }
        return connectionFactory;
    }

    public MQQueueConnectionFactory connectionFactory2() {
        MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
        try {
            connectionFactory.setHostName(hostName2);
            connectionFactory.setPort(Integer.parseInt(readPort));
            connectionFactory.setChannel(channel);
            connectionFactory.setTransportType(Integer.parseInt(transportType));
        } catch (NumberFormatException | JMSException e) {
            log.error(e.toString(),e);
        }
        return connectionFactory;
    }

    public MQQueueConnectionFactory connectionFactory3() {
        MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
        try {
            connectionFactory.setHostName(hostName3);
            connectionFactory.setPort(Integer.parseInt(readPort));
            connectionFactory.setChannel(channel);
            connectionFactory.setTransportType(Integer.parseInt(transportType));
        } catch (NumberFormatException | JMSException e) {
            log.error(e.toString(),e);
        }
        return connectionFactory;
    }

    @Bean
    public Destination jmsDestinationResolverSender() throws JMSException {
        return new MQQueue(updateQueue);
    }

    @Bean
    public Destination jmsDestinationResolverReceiver() throws JMSException {
        return new MQQueue(replyQueue);
    }

    @Bean
    public Destination jmsDestinationResolverReplyTo() throws JMSException {
        return new MQQueue(queueGateway, replyQueue);
    }

    @Bean
    public JmsTemplate jmsQueueTemplate() throws JMSException {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(connectionFactory1());
        jmsTemplate.setDefaultDestination(jmsDestinationResolverSender());
        jmsTemplate.afterPropertiesSet();

        log.info("Send ConnectionFactory is:" + jmsTemplate.getConnectionFactory());
        log.info("Send destination is:" + jmsTemplate.getDefaultDestination());
        log.info("Send Delivery Delay is :" + jmsTemplate.getDeliveryDelay());
        log.info("Send Delivery Mode is:" + jmsTemplate.getDeliveryMode());

        return jmsTemplate;
    }

    @Bean
    public DefaultMessageListenerContainer listenerContainer() throws JMSException {
        DefaultMessageListenerContainer defMsgListCont = new DefaultMessageListenerContainer();
        defMsgListCont.setConnectionFactory(connectionFactory3());
        defMsgListCont.setDestination(jmsDestinationResolverReceiver());
        defMsgListCont.setMessageListener(messageListenerReciever1);
        defMsgListCont.afterPropertiesSet();
        return defMsgListCont;
    }

    @Bean
    public DefaultMessageListenerContainer listenerContainer2() throws JMSException {
        DefaultMessageListenerContainer defMsgListCont = new DefaultMessageListenerContainer();
        defMsgListCont.setConnectionFactory(connectionFactory2());
        defMsgListCont.setDestination(jmsDestinationResolverReceiver());
        defMsgListCont.setMessageListener(messageListenerReciever2);
        defMsgListCont.afterPropertiesSet();
        return defMsgListCont;
    }   

      // Serialize message content to json using TextMessage
      @Bean
      public MessageConverter jacksonJmsMessageConverter() {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
      }


}

Update: It happened again today. One more Interesting this is sourcetimestamp on MQ msg is different from the time it was send. Sourcetimestamp is showing correct time but execution is delayed

JoshMc
  • 10,239
  • 2
  • 19
  • 38
sunil
  • 177
  • 2
  • 12

0 Answers0