FAIZAN
FAIZAN

Reputation: 333

UnSatisfied Link Exception While sending a message to ibm-mq

I am new to MQ, I have a requirement where in I have to send a mq message from 1 system to another. The Message queue and Queue Manager is Set up at the server, and i only have the qname and the mqmanager name,I have written the following code to create a connection to mq, but i am getting this Exception: UnsatisfiedLinkError: mqjbnd (Not found in java.library.path)

The code is:

package com.demo.mqsamplimport com.ibm.mq.MQC;

import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.MQConstants;


public class MQSample {
    private static final String qManager = "(MyQueueManagerName)";
    private static final String qName = "(MyQueueName)";

    public static void putGet(String args[]) {
        try {

        MQQueueManager qMgr = new MQQueueManager(qManager);

        int openOptions = MQConstants.MQOO_OUTPUT;

        MQQueue queue = qMgr.accessQueue(qName, openOptions);

        MQMessage msg = new MQMessage();

        msg.writeString("Hello World!");

        MQPutMessageOptions pmo = new MQPutMessageOptions();

        queue.put(msg, pmo);

        }
        catch (MQException ex) {
            ex.printstacktrace();
        }
        catch (java.io.IOException ex) {
            ex.printstacktrace(););
        }
    }
}

can anyone please help me on this.

Upvotes: 1

Views: 225

Answers (2)

JoshMc
JoshMc

Reputation: 10642

UnsatisfiedLinkError: mqjbnd (Not found in java.library.path) error is normally caused when you try to make a binding mode connection to IBM MQ Queue Manager hosted on the same server and the IBM MQ Classes for Java can not locate the library mqjbnd. If you do not specify a hostname and channel name for IBM MQ Classes for Java to use to connect, they default to a binding mode connection.

If your applications runs on the same server as the IBM MQ Queue Manager then you would need to tell the client how to find the mqjbnd libraries (on Linux this is /opt/mqm/java/lib) with one of the following methods:

  1. set the LIBPATH environment variable for example on Linux bash export LIBPATH=/path/to/library
  2. With the command line option -Djava.library.path=/path/to/library
  3. Programmatically with System.setProperty("java.library.path", "/path/to/library");

If you are trying to connect to a IBM MQ Queue Manager hosted on a remote server I agree with @user7790438 that you would need to provide MQ with the details on how to connect to the remote queue manager. The MQEnvironment is global and not thread safe. You should use a hashtable to pass these values for example:

import java.util.Hashtable;

private static String host = "dns.name";
private static int port = 1414;
private static String channel = "MQ.SVRCONN.CHL";

Hashtable properties = new Hashtable<String, Object>();
properties.put("hostname", host);
properties.put("port", port);
properties.put("channel", channel);

MQQueueManager qMgr = new MQQueueManager(qManager, properties);

You do not mention what version of IBM MQ the queue manager is, or what version of IBM MQ classes for Java jar files you are referencing. Other details can be passed via the hash table, for example if you are using IBM MQ v8 or later Classes for Java and connecting to a IBM MQ v8 or later Queue Manager you may need to pass a UserID and Password, this would be accomplished by adding the following to the has table:

private static String user = "UserID";
private static String password = "Password";

properties.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
properties.put(MQConstants.USER_ID_PROPERTY, user);
properties.put(MQConstants.PASSWORD_PROPERTY, password);

Please note that per the IBM v9.0 Knowledge center page "Deprecated, stabilized and removed features", IBM MQ Classes for Java have been Stabilization as of v8.0. This means that no further enhancements will be made and eventually IBM will deprecated the IBM MQ Classes for Java. You may want to write your application using the IBM MQ classes for JMS which has no support restrictions.

Stabilization of IBM MQ classes for Java
IBM will make no further enhancements to the IBM MQ classes for Java and they are functionally stabilized at the level shipped in IBM MQ Version 8.0. Existing applications that use the IBM MQ classes for Java will continue to be fully supported, but this API is stabilized, so new features will not be added and requests for enhancements rejected. Fully supported means that defects will be fixed together with any changes necessitated by changes to IBM MQ System Requirements.

Upvotes: 2

Fady Saad
Fady Saad

Reputation: 1189

You instantiated MQQueueManager before setting MQEnvironment's hostname and channel.

Just try add this:

MQEnvironment.hostname = "mq hostname";
MQEnvironment.channel = "mq channel";

Before:

MQQueueManager qMgr = new MQQueueManager(qManager);

Upvotes: 0

Related Questions