|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
problem setting the MQEnvironment Variables |
« View previous topic :: View next topic » |
Author |
Message
|
Rohitash |
Posted: Mon Oct 03, 2005 5:52 am Post subject: problem setting the MQEnvironment Variables |
|
|
Newbie
Joined: 03 Oct 2005 Posts: 5 Location: Bangalore, INDIA
|
Subject:-problem setting the MQEnvironment Variables using a non default Queue Manager.
I am facing a very basic problem with MQ Series. Can you please help me with this?
When I try to connect to default Queue Manager and put a message on a queue in it, I am able to set the following variables in MQEnvironment. With these parameters, I was able to connect to another host also, accessing its default Queue Manager.
// Define the name of your host to connect to
private static String hostname = "172.21.5.184";
// Define name of channel for client to use - this name is the server connection channel name
private static String channel = "QM3_Ch1";
// Define name of queue manager object to connect to( This is not the default Queue Manager)
private static String qManager = "test_qm_3";
// Define name of queue manager object to connect to
private static String queue = "QM3_Q1";
MQEnvironment.hostname = hostname; // hostname
MQEnvironment.channel = channel; // channel string
//MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
// MQC.TRANSPORT_MQSERIES);
//MQEnvironment.port = 1416;
PROBLEM:-
When I create my own queue manager and a queue, I am able to put the message and get it from the queue, if I don’t specify the MQEnvironment variables. It somehow takes the default value as the localhost. The channel I had created is similar to the channel in the default Queue Manager, ie Server Connection type. But the problem comes when I specify these MQEnvironment variable values with my Queue Manager. I also created similar Client connections as present in the default Queue Manager. It gives the following error:-
Inside initialize
MQEnvironment.hostname =blrkec38229d
MQEnvironment.channel:ServConn_QM3_Ch1
Inside initialize end
MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009
MQJE001: Completion Code 2, Reason 2009
An MQ error occurred : Completion code 2 Reason code 2009
Can you please explain me the how to correct it.
The following is the program:-
// a sample prog by Rohitash to put and receive messages from MQ series
// queues.
package src;
//import java.io.File;
import com.ibm.mq.*;
// Include the MQ package
public class MQSampleTest {
// Define the name of your host to connect to
private static String hostname = "172.21.5.184";
// Define name of channel for client to use - this name is the server connection channel name
//private static String channel = "SERV_CH_test_qm_1";
private static String channel = "QM4_Ch1";
// Define name of queue manager object to connect to
private static String qManager = "QM4"; //test_qm_3
// Define name of queue manager object to connect to
private static String queue = "QM4_Q1";
// define a queue manager object
private static MQQueueManager qMgr;
static boolean bIsConnect = false;
// When the class is called, this initialisation is done first.
public static void main(String args[])
{
// Set up MQ environment
try
{
MQEnvironment.hostname = hostname; // Could have put the hostname and
MQEnvironment.channel = channel; // channel string directly here!
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQEnvironment.port = 1416;
start();
}
catch(Exception e )
{
e.printStackTrace();
}
} // end of init
public static void start() {
try {
// ****************************
// * CONNECT *
// ****************************
// Create a connection to the queue manager
qMgr = new MQQueueManager(qManager);
System.out.println("qmgr in MQSampleTest:" +qMgr);
// ****************************
// * OPEN *
// ****************************
// Set up the options on the queue we wish to open...
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open, and the open options...
MQQueue system_default_local_queue = qMgr.accessQueue( queue, openOptions);// queue name
//null, // default queue manager
//null, // no dynamic queue name
//null); // no alternate user ID
// * MESSAGE *
MQMessage hello_world1 = new MQMessage();
hello_world1.writeString("Bye");
// * PUT *
MQPutMessageOptions pmo1 = new MQPutMessageOptions();
// Put the message on the queue
system_default_local_queue.put(hello_world1, pmo1);
int Key;
System.out.println("Press Enter !!!");
Key = System.in.read();
// ****************************
// * GET *
// ****************************
MQMessage retrievedMessage1 = new MQMessage();
MQGetMessageOptions gmo1 = new MQGetMessageOptions();
// get the message off the queue...
system_default_local_queue.get(retrievedMessage1, gmo1);
// ****************************
// * DISPLAY *
// ****************************
String msgText1 = retrievedMessage1.readLine();
System.out.println("The message is: " + msgText1);
// Close the queue
system_default_local_queue.close();
// Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException ex) {
System.out.println("An MQ error occurred : Completion code "+ ex.completionCode + " Reason code " + ex.reasonCode);
}
// Was it a Java buffer space error?
catch (java.io.IOException ex) {
System.out.println("An error occurred "+
"while writing to the message buffer: "+ ex);
ex.printStackTrace();
}
} // end of start
} // end of sample
[color=darkred][/color] _________________ Thanks and regards
Rohitash Laul |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Oct 03, 2005 7:15 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
So you can establish a connection to a remote queue manager just fine.
When you attempt to connect to a local queue manager using the same code, you get an error.
So it's not the code, is it?
Is there a listener running for the qmgr in question? Is the port number you are using the same one as the listener? Does the channel you are trying to use exist? Is it a SVRCONN channel? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Rohitash |
Posted: Thu Oct 06, 2005 5:06 am Post subject: Solution:problem setting the MQEnvironment Variables hostnam |
|
|
Newbie
Joined: 03 Oct 2005 Posts: 5 Location: Bangalore, INDIA
|
Hi
Thank you for your reply. I tried out and got the solution to the problem. I have to mention the following property in the MQEnvironment variable:-
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
Thanks and regards
Rohitash Laul _________________ Thanks and regards
Rohitash Laul |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|