MQ client connect to MQ server - ibm-mq

I installed MQ Client(7.0.1) in my computer,and write an app using c# to connect to remote Websphere MQ server.I have reference amqmdnet.dll in my project.below is my connect code:
MQEnvironment.Host = ip address;
MQEnvironment.Channel = channel name;
MQEnvironment.Port = 1414;
MQQueueManager qmgr = new MQQueueManager("qm name");
But when new MQQueueManager(),throw a type initializer for 'IBM.WMO.MQ.QueueManager'.
I am very confused about the exception.
Can you help me?

Can you give the complete stack trace of the exception? Type initializer exception occurs when an creation of an class instance fails. This exception is basically a wrapper for an internal exception. So knowing the details of the internal exception is helpful. You can put the MQQueueManager qmgr = new MQQueueManager("qm name"); in a try/catch block and print the complete exception.
From what I know this exception generally occurs if WMQ Client libraries are not installed. The amqmdnet assembly refers to other WMQ libraries, for example amqxcs2.dll and if they are not installed, this exception can be thrown.
You can use the dspmqver -a command output to check what has been installed.

Related

IBM Reason Code 2009 when attempting to connect to external host .net

I'm very new to IBM MQ and feel like I'm missing something fairly easy.
I received the following files and I'm attempting to connect to an externally hosted MQ:
.crl
.kdb
.rdb
.sth
.tab
I've tried several different approaches, but the "furthest" I think I've gotten is:
MQRC_CONNECTION_BROKEN Reason: 2009 when I attempt to create a new Queue Manager connection.
Below is my most recent block of code, trying to get this to work:
using IBM.WMQ;
...
Hashtable connectionProperties = new Hashtable();
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, SOME_ADDRESS);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, SOME_CHANNEL);
connectionProperties.Add(MQC.PORT_PROPERTY, SOME_PORT);
connectionProperties.Add(MQC.SSL_CERT_STORE_PROPERTY, PATH TO KDB FILE without .kdb);
connectionProperties.Add(MQC.SSL_CIPHER_SUITE_PROPERTY, SOME_CIPHER);
MQQueueManager qmgr = new MQQueueManager(SOME_VALUE, connectionProperties);
Prior to this I was attempting to set the MQ_CHANNEL_LIB and MQ_CHANNEL_TAB environment variables and call MQQueueManager qmgre = MQQueueManager() but that resulted in a 2277 error code.
I'm currently using the IBMMQDotnetClient/9.3.0 nuget package. Any help would be greatly appreciated.
The *.kdb file is a ssl keystore file containing certificates required to connect to queue manager. The *.kdb file can only be used with Transport type (TRANSPORT_PROPERTY property) MQC.TRANSPORT_MQSERIES_CLIENT. In this mode, MQ .NET client uses MQI C client underneath to communicate with queue manager.
The *.tab file is a client channel definition table (CCDT) file containing connection information like qm name, channel name, host name and few others required to connect to your queue manager.
Since you are using IBMMQDotnetClient/9.3.0 nuget package, TRANSPORT_MQSERIES_CLIENT transport type can't be used as the package doesn't contain MQI C client. With this nuget package you can only use TRANSPORT_MQSERIES_MANAGED. Ask your admins/management if they can provide you Redistributable MQ client. This package contains MQI C, .NET and other MQ clients libraries. You can choose to install the client libraries you want to use.
As Shashi mentioned if you need to use the Unmanaged mode,you need MQ C Client libraries as well.
You need to reference "amqmdnet.dll" which comes with IBM MQ Redistributable package to your .NET project. You can download IBM MQ Redistributable package from IBM Fix central.
To use CCDT, you need to set MQCHLLIB & MQCHLTAB environment variables.On how to create a CCDT file you can refer KC page:Configuring a binary format CCDT
After creating the CCDT File, i had used only the following code in my project to establish a successful connection
Environment.SetEnvironmentVariable("MQCHLLIB", #"C:\ProgramData\IBM\MQ\qmgrs\QMSSL\#ipcc");
Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL.TAB");
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
Environment.SetEnvironmentVariable("MQSSLKEYR", #"C:\temp\Certs\ForCclient\client");
try
{
queueManager = new MQQueueManager(queueManagerName, properties);
}
catch (MQException e)
{
Console.WriteLine("ERROR - Connect failed with unexpected MQRC {0}", e.ReasonCode);
throw e;
}

Facing issues in IBM MQ testing using JMeter

I am working on IBM MQ Performance testing using JMeter. Currently while executing the script i am facing error message. I am able to connect this IBM MQ using RHF utility manually. But in JMeter, i am getting below error. May i know how to fix this error.
Error :
Response message:javax.script.ScriptException: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'CLDACEAPD' with connection mode 'Client' and host name '172.XX.XX.XX(1414)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
Look at jmeter.log file, the full exception details should be there, look for the string which starts with Caused by and see what is the real cause of the issue.
If it's not there surround your code which establishes the connection with the queue manager into try block and populate the catch block as follows:
try {
//your code here
}
catch (Exception ex) {
log.error('Failed to connect to IBMMQ instance', ex)
}
Additional logging for IBMMQ client can be enabled by setting the following system properties:
com.ibm.msg.client.commonservices.trace.status=ON
com.ibm.msg.client.commonservices.trace.level=9
com.ibm.msg.client.commonservices.trace.outputName=/path/to/ibbmq/client.log

Can't connect to ibm mq using jms

I had a problem with connecting to the IBM MQ queue from Java. I tried to change the passwords for the service of the IBM MQ, create a connection without specifying a login and password, but nothing happens. I wrote the code:
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
props.setProperty(Context.PROVIDER_URL, "file:/D:/JNDI/");
try {
InitialContext initialContext = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName);
Destination destination = (Destination) initialContext.lookup(queueName);
initialContext.close();
Connection queueConnection = connectionFactory.createConnection("login", "password");// .createConnection();
which falls when I create a connection. I get an error:
JMSWMQ2013: Invalid credentials were passed to the queue manager QueueManager 'QM_LOCAL' in the 'Client' connection mode using the host 'localhost (1414)'.
Verify that the provided user name and password are correct in the queue administrator that you are connecting to.
can I turn off the authentication so that the method ".createConnection();" works? If not, where do I set the password? I Use the Windows.
Thanks.
p.s.: I get the completion code '2' ('MQCC_FAILED'), reason'2035' ('MQRC_NOT_AUTHORIZED').

Multi Instance MQ set up

I am trying to set up Multi Instance MQ. I have configured NFS and able to see the active and stand by instances using dspmq -x. However my doubt is after this setup how to proceed further.
How can I configure the channel(s). I got CONNAME property should be use for this. e.g. CONNAME(<ip><port>,<ip><port>). I am not aware how to do it exactly.
How many listeners I need to start.
For normal mode of MQ, I follow the below steps:
1. crtmqm QM
2. strmqm QM
3. runmqsc QM
4. runmqlsr -m QM -t tcp -p 1125
5. runmqsc QM
6. define channel(SYSTEM.ADMIN.SVRCONN) chltype(SVRCONN) mcauser('mqm')
For multi-instance MQ, what changes I have to do for the below steps. There are many good documents available for Multi Instance MQ set up, but most of these are limited to how to configure the queue manager with multi-instance. Could anybody please guide me for the remaining steps.
Any guidance is much appreciated.
EDIT
Thanks Shashi and Morag for the guidance.
I have created different listeners on port 1600 in both the servers. I have created the below channel:
DEFINE CHANNEL(MYCHANNEL) CHLTYPE(CLNTCONN) TRPTYPE(TCP)
CONNAME('IP11600),IP2(1600)')
DEFINE CHANNEL(MYCHANNEL) CHLTYPE(SVRCONN) TRPTYPE(TCP) MCAUSER(' ')
Below is the stand alone java code I am using to put a message in queue.
public class MutilInstanceMq
{
public static void main(String[] args)
{
sendMsg("Test Message");
}
public static void sendMsg(String msg)
{
MQQueueConnectionFactory connectionFactory = null;
QueueConnection queueConn = null;
QueueSession queueSession = null;
QueueSender queueSender = null;
TextMessage message = null;
try
{
connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setConnectionNameList("<IP1>(1600), <IP2>(1600)");
connectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
connectionFactory.setQueueManager("MYQM1");
connectionFactory.setChannel("MYCHANNEL");
queueConn = connectionFactory.createQueueConnection(" ","password");
queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queueSession.createQueue("MYQ"));
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
message = queueSession.createTextMessage(msg);
message.setJMSCorrelationID("12345");
queueSender.send(message);
queueConn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
With the above code I end up with the below exception while creating the connection.
> com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to
> connect to queue manager 'MYQM1' with connection mode 'Client' and
> host name 'IP1(1600),IP2(1600)'. Check the queue manager is
> started and if running in client mode, check there is a listener
> running. Please see the linked exception for more information.
Detailed Print stack trace is:
com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to connect to queue manager 'MYQM1' with connection mode 'Client' and host name 'IP1(1600),IP2(1600)'. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:608)
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:236)
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:440)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:7062)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:6453)
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:295)
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6230)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:144)
at MutilInstanceMq.sendMsg(MutilInstanceMq.java:40)
at MutilInstanceMq.main(MutilInstanceMq.java:17)
Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2543' ('MQRC_STANDBY_Q_MGR').
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:223)
... 8 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2543;AMQ9204: Connection to host 'IP2(1600)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2543;AMQ9487: Remote queue manager is a standby queue manager instance. [3=MYCHANNEL]],3=IP2(1600),5=RemoteConnection.analyseErrorSegment]
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:2010)
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1227)
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:355)
... 7 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9204: Connection to host 'IP1(1600)' rejected. [3=IP1(1600)]
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1980)
... 9 more
Where I am going wrong? Meanwhile I have turned off channel authentication and able to connect to the queue.
To answer your explicit questions:
If you want to use the comma-separated CONNAME method, then you'll end up with something like this. CONNAME('machine1(1234),machine2(1234)'). You should have the same port number in both.
You have two options here. Either use runmqlsr on each machine - so you have two listeners, on the same port. The purpose of the one on the primary machine is for connections to be able to connect to the queue manager. The purpose of the one on the standby machine is to reject connections which try to connect there more quickly than they could be rejected by TCP working out that there is no listener. It also means that the error reported by the connection for the reason it could not connect is much more explicit - "This machine is the standby" rather than "no TCP listener here".
The alternate option is to define a LISTENER object and have it controlled by the queue manager, this way it will only run where the queue manager runs. This keeps the configuration all within the queue manager, but does mean you don't get the benefits outlined above.
The steps are well documented in Knowledge Center here: http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.1.0/com.ibm.mq.doc/fa70161_.htm?lang=en. How to verify the multi-instance setup is described here: http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.1.0/com.ibm.mq.doc/fa70163_.htm?lang=en.

Able to connect to remote queue manager but not able to create topic connection

I am trying to publish a message to a remote JMS queue by a pretty standard mechanism:
TopicConnection tc = null;
TopicSession ts = null;
TopicPublisher tp = null;
Properties p = new Properties();
String providerUrl = "iiop://servername:9810";
String contextFactory = "com.ibm.websphere.naming.WsnInitialContextFactory".trim();
p.put(javax.naming.Context.PROVIDER_URL, providerUrl );
p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, contextFactory );
InitialContext ct = new InitialContext(p);
{
Topic topic = (Topic)ct.lookup( "jms/customer_event" );
TopicConnectionFactory tcf = (TopicConnectionFactory)ct.lookup( "jms/TopicFactory2" );
tc = tcf.createTopicConnection();
....
..
..
}
Now, the Topic and TopicConnectionFactory lookups are fine but when it comes to tcf.createTopicConnection(), it throws:
javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for 'servername:QMGR1'
Inner exception(s):
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2059
java.net.ConnectException: Connection refused: connect
I opened up MQ explorer, and the topic is existing on the remote Queue manager. IS the TopicCoonectionFactory TopicFactory2 also supposed to reside on the queue manager? Because it does not.
What can be the cause of error?
When connecting, the details of host, port and channel must be correct. If the host or port are wrong, then the TCP socket is refused. If the channel name is wrong, then the queue manager will refuse the connection and close the socket. It is possible that you have all the details correct but that the listener on the queue manager is not running.
If the connection is getting as far as the queue manager then you will have an error in the [WMQ Install dir]/qmgrs/[QMgr name]/errors/AMQERR01.LOG file. If the connection gets to WMQ but cannot resolve the queue manager's name or specifies the wrong QMgr then the error will be in [WMQ Install dir]/errors/AMQERR01.LOG. If there is no entry in either of these then the connection isn't making it to WMQ and you need to check the listener or the network.
2059 connection refused is highly likely a network error or a typeo in the MQ server hostname and/or port. Double check your config in WebSphere and the network connection.
JavaDoc for ConnectException also states this http://docs.oracle.com/javase/6/docs/api/java/net/ConnectException.html
Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port).

Resources