mq-jms-spring icon indicating copy to clipboard operation
mq-jms-spring copied to clipboard

IBM-MQ (ibm.mq.allclient:jar:9.2.2.0) Spring Boot dynamic listener fails with too many MQ connections with compcode '2' ('MQCC_FAILED') reason 2537

Open mohamed-rafii opened this issue 3 years ago • 2 comments

Please include the following information in your ticket.

Problem Statement: We manually create the listeners for multiple queues when the system starts. What we face problem was the channel has got 10 conversations by default. Each connection takes 2 conversations and after 5 messages that channel connection is not processing any messages. We configured the 100 channels and it gets exhausted. Not sure how we can release the conversation.

for reference - https://stackoverflow.com/questions/69982367/ibm-mq-ibm-mq-allclientjar9-2-2-0-spring-boot-dynamic-listener-fails-with-to

  • ibmmq-jms-spring 2.4.5.

  • Java 1.8.0_281.

    /*

    • Ibm-mq connection factory creation */ public ConnectionFactory ibmConnectionFactory() throws JMSException, MalformedURLException, FileNotFoundException {

      StringBuilder sb = new StringBuilder("file:///"); File fileName = ResourceUtils.getFile("ibmmq-default.json"); sb.append(fileName.getAbsolutePath()); URL qCCDT = new URL(sb.toString());

      MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory(); mqQueueConnectionFactory.setQueueManager(queueManager); mqQueueConnectionFactory.setAppName("APA-MQ"); mqQueueConnectionFactory.setCCDTURL(qCCDT);

      return mqQueueConnectionFactory; }

    //JMS template @Primary @Bean(name="ibmJMSTemplate") public JmsTemplate ibmJMSTemplate() throws JMSException, MalformedURLException, FileNotFoundException { return new JmsTemplate(ibmConnectionFactory()); } //transaction manager creation @Primary @Bean(name="ibmTM") public JmsTransactionManager ibmJMSTransactionManager() throws JMSException, MalformedURLException, FileNotFoundException { JmsTransactionManager jmsTransactionManager = new JmsTransactionManager(); jmsTransactionManager.setConnectionFactory(ibmJMSTemplate().getConnectionFactory()); return jmsTransactionManager; }

    //Default Listener container @Bean(name="mqJmsListenerContainerFactory") public DefaultJmsListenerContainerFactory mqJmsListenerContainerFactory() throws JMSException { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(ibmConnectionFactory); factory.setDestinationResolver(new DynamicDestinationResolver()); factory.setSessionTransacted(true); factory.setConcurrency(requestConcurrency); return factory; }

    /* This method fetches the queue name at start of the service and configures the listener. this will be in transaction. What we face the problem the channel has got 10 converstations by default. each connection takes 2 conversation and after 5 messages that channel connection is not processing any messages. we configured the 100 channels and it gets exhausted. Not sure how we can release the conversation. */ @Override public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {

      List<IBMmqQueue> requestMQQueueNames = apamqConnectionRepository.findAllQueueNames();
      //setting up listener for trades
      for (IBMmqQueue aTradeQueue : requestMQQueueNames) {
          if(StringUtils.isEmpty(aTradeQueue.getTradeRequestName())){
              continue;
          }
          SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
          endpoint.setId(aTradeQueue.getTradeRequestName());
          endpoint.setDestination(aTradeQueue.getTradeRequestName());
          endpoint.setMessageListener(message -> {
              TransactionStatus status = jmsTransactionManager.getTransaction(null);
              try {
                  // This starts a new transaction scope. "null" can be used to get a default transaction model
                  TextMessage msg = streamlineJMSMsgToTextMsgFormat(message, aTradeQueue.getTradeRequestName());
                  ibmmqConsumer.tradeListener(msg, aTradeQueue.getTradeRequestName());
                  jmsTransactionManager.commit(status);
              } catch (Exception e) {
                  jmsTransactionManager.rollback(status);
                  try {
                      LOG.error("Failed to publish trade to Active-MQ & rolled back to IBM-MQ : " + message.getJMSMessageID());
                  } catch (JMSException ex) {
                      ex.printStackTrace();
                  }
              }
          });
          try {
              registrar.setContainerFactory(this.mqJmsListenerContainerFactory());
          } catch (JMSException e) {
              e.printStackTrace();
          }
          registrar.registerEndpoint(endpoint);
      }
    

mohamed-rafii avatar Nov 18 '21 23:11 mohamed-rafii

Are you saying that each invocation of your OnMessage method eats up a connection? If so then this is odd, as Spring should be managing these for you. If each invocation is consuming a connection then this indicates something wrong in your OnMessage.

Spring handles Open / Close, and if you have factory.setSessionTransacted(true) it will handle commit and rollback also. Commit if the method ends normally, Rollback if it throws an exception.

So the logic that you have added eg.

TransactionStatus status = jmsTransactionManager.getTransaction(null);

seems redundant. Have you tried without these lines? You will need to rethrow the exception you catch to allow Spring to detect it.

chughts avatar Nov 19 '21 11:11 chughts

Hi

Removed the transaction, still the same

Thanks Rafi

Sent from my iPhone

On 19 Nov 2021, at 11:02, Soheel Chughtai @.***> wrote:

 Are you saying that each invocation of your OnMessage method eats up a connection? If so then this is odd, as Spring should be managing these for you. If each invocation is consuming a connection then this indicates something wrong in your OnMessage.

Spring handles Open / Close, and if you have factory.setSessionTransacted(true) it will handle commit and rollback also. Commit if the method ends normally, Rollback if it throws an exception.

So the logic that you have added eg.

TransactionStatus status = jmsTransactionManager.getTransaction(null); seems redundant. Have you tried without these lines? You will need to rethrow the exception you catch to allow Spring to detect it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

mohamed-rafii avatar Nov 19 '21 11:11 mohamed-rafii