-1

i am using Web sphere version 7.5,does that require System Broker for starting MQ service.How can i start MQ service when i access through Java code. Currently i am getting the following exceptions when access through a code

MQJE001: An MQException occurred: Completion Code 2, Reason 2009 MQJE016: MQ queue manager closed channel immediately during connect Closure reason = 2009

MQJE001: An MQException occurred: Completion Code 2, Reason 2009 MQJE016: MQ queue manager closed channel immediately during connect Closure reason = 2009

com.ibm.mq.MQException: MQJE001: An MQException occurred: Completion Code 2, Reason 2009

MQJE016: MQ queue manager closed channel immediately during connect Closure reason = 2009

the code i used is given below

public class Demo {
            private MQQueueManager _queueManager = null;
            public int port = 1422;
            public String hostname = "192.168.1.5";//IP OF HOST
            public String channel = "QM_ORANGE.QM_APPLE";//channel name
            public String qManager = "QM_ORANGE";//queue manager name
            public String inputQName = "Q1";//remote q type
            public String outputQName = "QM_APPLE";//queue manager

            public Demo() {
                super();
            }

            private void init(String[] args) throws IllegalArgumentException {
                // Set up MQ environment
                MQEnvironment.hostname = hostname;
                MQEnvironment.channel = channel;
                MQEnvironment.port = port;
            }

            public static void main(String[] args) {

                Demo readQ = new Demo();

                try {
                    readQ.init(args);
                    readQ.selectQMgr();
                    readQ.read();
                    readQ.write();
                } catch (IllegalArgumentException e) {
                    System.out
                            .println("Usage: java MQRead <-h host> <-p port> <-c channel> <-m QueueManagerName> <-q QueueName>");
                    System.exit(1);
                } catch (MQException e) {
                    System.out.println(e);
                    System.exit(1);
                }
            }

            private void read() throws MQException {
                int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING
                        + MQC.MQOO_INPUT_SHARED;

                MQQueue queue = _queueManager.accessQueue(inputQName, openOptions,
                        null, // default q manager
                        null, // no dynamic q name
                        null); // no alternate user id

                System.out.println("MQRead v1.0 connected.\n");

                int depth = queue.getCurrentDepth();
                System.out.println("Current depth: " + depth + "\n");
                if (depth == 0) {
                    return;
                }

                MQGetMessageOptions getOptions = new MQGetMessageOptions();
                getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING
                        + MQC.MQGMO_CONVERT;
                while (true) {
                    MQMessage message = new MQMessage();
                    try {
                        queue.get(message, getOptions);
                        byte[] b = new byte[message.getMessageLength()];
                        message.readFully(b);
                        System.out.println(new String(b));
                        message.clearMessage();
                    } catch (IOException e) {
                        System.out.println("IOException during GET: " + e.getMessage());
                        break;
                    } catch (MQException e) {
                        if (e.completionCode == 2
                                && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
                            if (depth > 0) {
                                System.out.println("All messages read.");
                            }
                        } else {
                            System.out.println("GET Exception: "+e);
                        }
                        break;
                    }
                }
                queue.close();
                _queueManager.disconnect();
            }

            private void selectQMgr() throws MQException {
                _queueManager = new MQQueueManager(qManager);
            }

            private void write() throws MQException {
                int lineNum = 0;
                int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
                try {
                    MQQueue queue = _queueManager.accessQueue(outputQName, openOptions,
                            null, // default q manager
                            null, // no dynamic q name
                            null); // no alternate user id

                    DataInputStream input = new DataInputStream(System.in);

                    System.out.println("MQWrite v1.0 connected");
                    System.out.println("and ready for input, terminate with ^Z\n\n");

                    // Define a simple MQ message, and write some text in UTF format..
                    MQMessage sendmsg = new MQMessage();
                    sendmsg.format = MQC.MQFMT_STRING;
                    sendmsg.feedback = MQC.MQFB_NONE;
                    sendmsg.messageType = MQC.MQMT_DATAGRAM;
                    sendmsg.replyToQueueName = "ROGER.QUEUE";
                    sendmsg.replyToQueueManagerName = qManager;

                    MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the
                                                                            // defaults,
                                                                            // same
                    // as MQPMO_DEFAULT constant

                    String line = "test message";
                    sendmsg.clearMessage();
                    sendmsg.messageId = MQC.MQMI_NONE;
                    sendmsg.correlationId = MQC.MQCI_NONE;
                    sendmsg.writeString(line);

                    // put the message on the queue

                    queue.put(sendmsg, pmo);
                    System.out.println(++lineNum + ": " + line);

                    queue.close();
                    _queueManager.disconnect();

                } catch (com.ibm.mq.MQException mqex) {
                    System.out.println(mqex);
                } catch (java.io.IOException ioex) {
                    System.out.println("An MQ IO error occurred : " + ioex);
                }

            }
        }

i got the following error log 9/24/2016 14:09:24 - Process(1956.7) User(MUSR_MQADMIN) Program(amqrmppa.exe) Host(ABHI-PC) Installation(Installation1) VRMF(7.5.0.2) QMgr(QM_ORANGE)

AMQ9208: Error on receive from host Aneesh (192.168.0.7).

EXPLANATION: An error occurred receiving data from Aneesh (192.168.0.7) over TCP/IP. This may be due to a communications failure. ACTION: The return code from the TCP/IP recv() call was 10054 (X'2746'). Record these values and tell the systems administrator.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
Akshay Prabhu
  • 175
  • 1
  • 4
  • 18
  • Have you looked at some of the suggestions [here](http://www-01.ibm.com/support/docview.wss?uid=swg21226703)? – Scott Kurz Sep 22 '16 at 13:31
  • Do i have to start any **services** for accessing the MQ through Java.if yes then how can i start the service.i have started only the Queue manager using **runmqsc** command. – Akshay Prabhu Sep 23 '16 at 04:38

1 Answers1

2

Your application is calling _queueManager.disconnect() in read method. This closes the connection to queue manager. Then your application are calling accessQueue method using the same disconnected _queueManager object. This will fail with connection error.

Suggest you to remove queueManager.disconnect() from read method and then try.

UPDATE

Couple of suggestions:

1) Set the transport type to client by adding this line MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES_CLIENT)

2) Ensure the channel, QM_ORANGE.QM_APPLE you are using is a Server Connection (SVRCONN) type channel.

This question may be of help: MQ queue manager closed channel immediately during connect

Community
  • 1
  • 1
Shashi
  • 14,980
  • 2
  • 33
  • 52
  • Commented `queueManager.disconnect()` but no use still gets same Exception – Akshay Prabhu Sep 23 '16 at 05:13
  • i got exception during the call `readQ.selectQMgr(); ` `private void selectQMgr() throws MQException { _queueManager = new MQQueueManager(qManager); }` – Akshay Prabhu Sep 23 '16 at 11:53
  • got the following error log plz go through and tell me what to do? – Akshay Prabhu Sep 24 '16 at 08:11
  • done this MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES_CLIENT) – Akshay Prabhu Sep 24 '16 at 08:12
  • As you can see in the error log, channel type of QM_ORANGE.OM_APPLE is SENDER. A SVRCONN(server connection) type channel is required for client application to connect to queue manager. You need to either delete the channel and create again with type SVRCONN or create another channel with type SVRCONN. – Shashi Sep 24 '16 at 08:40
  • as per you mentioned i created server connection channel earlier i was created sender channel...now i getting the above log – Akshay Prabhu Sep 24 '16 at 08:49
  • got these error also :MQJE001: Completion Code 2, Reason 2045 com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2045 – Akshay Prabhu Sep 24 '16 at 08:55
  • Connection error is resolved?. Did you do some research on MQRC 2045 reason code? – Shashi Sep 24 '16 at 09:08
  • Thank you for the answers all errors are fixed... is there any way to extract only the message sir – Akshay Prabhu Sep 26 '16 at 05:51
  • 1
    what do you mean by "only the message"? – Shashi Sep 26 '16 at 06:52
  • Do you have any java pgm to connect to WebSphere client .(without specifying host name) – Akshay Prabhu Oct 04 '16 at 06:56
  • Applications don't connect to WebSphere MQ client. Applications use the API/classes provided by WebSphere MQ client to connect to queue manager. You can always use IP address instead of host name. – Shashi Oct 04 '16 at 08:17
  • i couldn't find this jar com.ibm.mq.constants.MQConstants can you help – Akshay Prabhu Oct 04 '16 at 09:39
  • Please look at this link: http://www-01.ibm.com/support/docview.wss?uid=swg21683398&myns=swgws&mynp=OCSSFKSJ&mync=E – Shashi Oct 04 '16 at 09:58
  • can please you just look this link http://stackoverflow.com/questions/39849868/ibm-mq-client-java-lang-unsatisfiedlinkerror-no-mqjbnd05-in-java-library-path-e – Akshay Prabhu Oct 05 '16 at 05:06