Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No response when using IBM MQ client jars in application to connect to IBM MQ server

The application I am working on needs to communicate to an IBM MQ server in a remote location. We currently have a working system using active MQ which uses a broker, and a bridge to connect to this remote IBM MQ server and is working fine.

Due to some new enhancement, we are now trying to achieve the same using IBM client jars instead of Active MQ.

The problem I am facing is that I can connect to the remote server's inboundQ and send messages.But I am always receiving null from the remote servers outbound Queue. But I have no way to check if the messages are received at the remote location. But the same message if sending through the old ActiveMQ system will get a response from remote MQ server.

Old Active MQ internally uses the bridge to connect to remote IBM MQ server which is configured exactly like the new code I am using.

I have tried multiple codes from internet and stack overflow itself and always I am able to connect but not getting any responses.

Also, I get no errors or exceptions while trying to send or receive from remote IBM MQ.

I will paste a sample code which I am trying to get to work. I have changed some configuration values in the code.

My doubts are the following.

  1. All I am doing for this is copying IBM MQ client jars into the application and using the code to send messages to remote MQ. I have not installed any other application. Will such a system work or should there always be some intermediate program like active MQ?

  2. The same code is able to send and receive from an IBM MQ server which I installed in our local network but fails to get a response from the remote server? This leads me to believe if I am missing anything in configuration ? should anything else be configured other than in code?

  3. I see no errors or exceptions. Always message is sent but the response is null. I have not seen the usage of any username-password or public-private key authentication. Is there any authentication used normally to check the source. ?

  4. I am using IBM MQ client 5.3 version which I know is old. But used that since they working active MQ setup uses the same and is working correctly. I have no way of knowing which version on IBM MQ server is present on the remote machine. Is there a problem if we use a different client MQ version than the version of server MQ version. ?

Sample code which works for me in local environment ie is able to send and receive from an IBM MQ server I have installed in another machine in the local network. The same code will fetch null response when I am trying to use it with remote IBM MQ server.

import javax.jms.*;
import javax.jms.JMSException;
import com.ibm.mq.jms.*;
import com.ibm.jms.JMSMessage;
import javax.jms.TextMessage;

public class SendReceive {
    private MQQueueConnectionFactory connectionFactory;
    private MQQueueConnection connection;

    private void runTest() {
        try {
            connect();
            connection.start();
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            MQQueue queue = (MQQueue) session.createQueue("INBOUND_QUEUE");     /* values  replaced with correct values in deployment server */
            MQQueue queue2 = (MQQueue) session.createQueue("OUTBOUND_QUEUE");   /* values  replaced with correct values in deployment server */
            MQQueueSender sender = (MQQueueSender) session.createSender(queue);     

            MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue2);

            //TextMessage message = session.createTextMessage("yesyesyes");
            String stt = "Test Message";        //

            TextMessage message = session.createTextMessage(stt);
            message.setJMSReplyTo(queue2);
            sender.send(message);
            System.out.println("Sent: " + message);

            Message msg1 = receiver.receive(5000);
            if(msg1!=null){
                String responseMsg = ((TextMessage) msg1).getText();
                System.out.println("Received: " + responseMsg);
            }else{
                System.out.println("Message received is null");
            }
        }catch(Exception e){
            System.out.println("Exception caught in program : " + e);
            e.printStackTrace();
        }
    }

    public boolean connect() {
        boolean connected = false;
        try {
            /* values below are replaced with correct values in deployment server */

            connectionFactory = new MQQueueConnectionFactory();            
            connectionFactory.setPort(1515);
            connectionFactory.setHostName("192.168.1.23"); // 
            connectionFactory.setQueueManager("QCCMGR");
            connectionFactory.setChannel("QCHANNEL");            
            connectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);

            connection = (MQQueueConnection) connectionFactory.createQueueConnection();
            connected = true;
        } catch (Exception e) {
            connected = false;
        }
        return connected;
    }

    public static void main(String[] args) {
        new SendReceive().runTest();
    }

}
like image 235
Raj Avatar asked Feb 21 '17 14:02

Raj


People also ask

What is the difference between MQ client and MQ Server?

The output from the call is sent back to the client, which passes it back to the application. An IBM MQ server is a queue manager that provides queuing services to one or more clients. All the IBM MQ objects, for example queues, exist only on the queue manager machine (the IBM MQ server machine), and not on the client.

How do I test connection to IBM MQ?

To test a IBM MQ Connection From the Object Repository tab of the Management Console, navigate to the relevant queue manager, right-click and select Test Middleware Administrator IBM MQ Connection.

How do I connect to MQ client?

Read the topic Configuring connections to IBM MQ. Ensure that the required queue manager has been created on the IBM MQ server. Ensure that the user ID that is running the integration node has the necessary permissions to access the queue manager. Decide how you want to connect to the queue manager.


1 Answers

MQ v5.3 was released November 29th 2002 and has been out of support since September 28th 2007 (almost 9 years). The version may not have anything to do with your issue but I would strongly suggest that you move to a supported version of the MQ client. Newer MQ client versions can connect to older MQ queue managers. You can download a java only install of MQ 8.0 or MQ 9.0 jar files at the links below:

  • IBM MQ v8.0 Client
  • IBM MQ v9.0 Client

I read on some old threads that having the sender and receiver on the same session caused problems when a timeout was specified. Try adding another session for the receiver.

    private void runTest() {
        try {
            connect();
            connection.start();
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            MQQueueSession session2 = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            MQQueue queue = (MQQueue) session.createQueue("INBOUND_QUEUE");     /* values  replaced with correct values in deployment server */
            MQQueue queue2 = (MQQueue) session2.createQueue("OUTBOUND_QUEUE");  /* values  replaced with correct values in deployment server */
            MQQueueSender sender = (MQQueueSender) session.createSender(queue);     

            MQQueueReceiver receiver = (MQQueueReceiver) session2.createReceiver(queue2);

            //TextMessage message = session.createTextMessage("yesyesyes");
            String stt = "Test Message";        //

            TextMessage message = session.createTextMessage(stt);
            message.setJMSReplyTo(queue2);
            sender.send(message);
            System.out.println("Sent: " + message);

            Message msg1 = receiver.receive(5000);
            if(msg1!=null){
                String responseMsg = ((TextMessage) msg1).getText();
                System.out.println("Received: " + responseMsg);
            }else{
                System.out.println("Message received is null");
            }
        }catch(Exception e){
            System.out.println("Exception caught in program : " + e);
            e.printStackTrace();
        }
    }

Try taking a JMS trace by adding the following to the execution of the java app:

-DMQJMS_TRACE_LEVEL=base
-DMQJMS_TRACE_DIR=/tracedirectory

ex: java -DMQJMS_TRACE_LEVEL=base -DMQJMS_TRACE_DIR=/tracedirectory JavaApp

This should produce a file that I believe ends in .trc in the directory you specify.

You can review this for errors that might help point you in the right direction.


Suggestions:

Try changing your program to force it to send a blank username:

connection = (MQQueueConnection) connectionFactory.createQueueConnection("", "");

Try closing the sender after sender.send is called

sender.close(); 

With out further information it is difficult to determine the cause. The more information you can gather the better.

like image 87
JoshMc Avatar answered Oct 15 '22 16:10

JoshMc