Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:24:13+00:00 2026-06-17T19:24:13+00:00

I am trying to simulate WebSphere MQ reason code 2009 to handle in the

  • 0

I am trying to simulate WebSphere MQ reason code 2009 to handle in the below JMS code but not able to get it. Instead I am getting 2059. All I am doing is disconnecting SVRCONN channel while making the connection call. How can I get 2009 in my sample code.
I have added a sleep time prior making connection again and using transacted sessions. What else can be done to handle reason code 2009 properly that eventually Queue manager won’t get thrashed by frequent unsuccessful connection attempts.
Please find the code.

private static void connectToQmgr(MQQueueConnectionFactory cf) {
    // TODO Auto-generated method stub

    MQQueueConnection connection = null;
    MQQueueSession session = null;
    MQQueue queue = null;
    MQQueueSender sender = null;

    //While Statement to make sure multiple connection tries are made until connection establishes

    while (connection == null){

    try {
        connection = (MQQueueConnection) cf.createConnection();
        session = (MQQueueSession) connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
        queue = (MQQueue) session.createQueue("queue:///LQ");
        sender = (MQQueueSender) session.createSender(queue);
        //MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);
        long uniqueNumber = System.currentTimeMillis() % 1000;
        TextMessage message = session.createTextMessage("MQJMSTest "+ uniqueNumber);
        // Start the connection
        connection.start();
        sender.send(message);
        session.commit();
        System.out.println("Sent message:\\n" + message);

       // JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
       // System.out.println("\\nReceived message:\\n" + receivedMessage);

        session.commit();

        sender.close();
       // receiver.close();
        session.close();
        connection.stop();
        connection.close();

        System.out.println("\\nSUCCESS\\n");

    } catch (JMSException je) {
        System.err.println("Caught JMSException");

        // Check for linked exceptions in JMSException to catch MQException and Reason Codes 
        Throwable t = je;
        while (t != null) {
            // Write out the message that is applicable to all exceptions
            System.err.println("Exception Msg: " + t.getMessage());
            // Write out the exception stack trace
            t.printStackTrace(System.err);

            // Add on specific information depending on the type of exception
            if (t instanceof JMSException) {
                JMSException je1 = (JMSException) t;
                System.err.println("JMS Error code: " + je1.getErrorCode());

                if (t instanceof JmsExceptionDetail){
                    JmsExceptionDetail jed = (JmsExceptionDetail)je1;
                    System.err.println("JMS Explanation: " + jed.getExplanation());
                    System.err.println("JMS Explanation: " + jed.getUserAction());
                }
            } else if (t instanceof MQException) {
                MQException mqe = (MQException) t;
                System.err.println("WMQ Completion code: " + mqe.getCompCode());
                System.err.println("WMQ Reason code: " + mqe.getReason());

                //###################################################################################
                //MQ Reason Code Error Handle here
                //Currently Handling MQ Reason Code 2059 since unable to simulate 2009
                //If connection handle exists make sure you close everything and add a wait interval and try a new connection again
                if (mqe.getReason()== 2059){
                    System.out.println("Inside MQ Reson Code Handle");

                    if( connection != null){
                         try {
                            sender.close();
                            // receiver.close();
                            session.close();
                            connection.stop();
                            connection.close();
                        } catch (JMSException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    // Add Wait Interval for 5 sec
                    try {
                        Thread.sleep(5000);
                        System.out.println("Inside Thread Sleep for 5 sec");
                        //Try New connecting Again
                        connectToQmgr(cf);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();

                    }   
                }
                 //##################################################################################           
            } else if (t instanceof JmqiException){
                JmqiException jmqie = (JmqiException)t;
                System.err.println("WMQ Log Message: " + jmqie.getWmqLogMessage());
                System.err.println("WMQ Explanation: " + jmqie.getWmqMsgExplanation());
                System.err.println("WMQ Msg Summary: " + jmqie.getWmqMsgSummary());
                System.err.println("WMQ Msg User Response: "
                                   + jmqie.getWmqMsgUserResponse());
                System.err.println("WMQ Msg Severity: " + jmqie.getWmqMsgSeverity());
            }

            // Get the next cause
            t = t.getCause();
       }
    }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:24:15+00:00Added an answer on June 17, 2026 at 7:24 pm

    A 2009 is MQRC_CONNECTION_BROKEN. Have you considered pulling the network cable or shutting down the network interface over which the connection travels? This is easy enough when running the code on your laptop. For servers, you can try routing the connection through an SSH proxy or other virtual interface that can be shut down.

    To answer the second part of your question, make sure the program sleeps a few seconds between reconnect attempts. Or, better yet, use a modern version of WMQ client and use the automatic reconnect option. This will make a couple of fast retries and then slow down a bit for subsequent retries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simulate this error with a sample php code but haven't been
I'm trying to simulate a bbcode tag, like code below: [code]this is code to
I'm trying to simulate a coin flip using the code below. public class Coin
I'm trying to simulate a keypress with the below code... jQuery('input[name=renameCustomForm]').live('keyup', function (e) {
I'm trying to simulate a particle system using OpenGl but I can't get it
I'm trying to simulate a substring in Python but I'm getting an error: length_message
I am trying to simulate a simple MIPS processor using behavior code in Verilog.
I am trying to simulate asymmetric key system. I use following code to generate
I'm trying to consume JMS messages send over WebSphere MQ (WebSphere MQ Server v7)
I'm trying to simulate a floating modal box type thing but having an issue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.