|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Problem accessing remote Qmgr - MSender |
« View previous topic :: View next topic » |
Author |
Message
|
sebastian |
Posted: Thu Oct 05, 2006 11:03 am Post subject: Problem accessing remote Qmgr - MSender |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
Dear MQseries.net:
I downloaded a java program from the IBM website called "MSender."
It is a simple bit of code that allows the user to send typed lines to a queue. I have been able to run this successfully sending to a queue defined on my local workstation but I get the error "2058 - Qmgr name error" when I try to send to a remote queue & queue manager.
I opened a dos session and updated the MQSERVER environment variable to SET MQSERVER=SVRCONCHNL/TCP/PRH345(1414). I also double checked the names of the qmgr and queue and they're correct. It's also worth mentioning that I wrote a perl script that does something similar and it's working without a problem.
I'd appreciate any feedback. Any suggestions?
Sebastian
/*
* Created on Sep 26, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
*
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/***************************************************************************/
/* */
/* (c) Copyright IBM Corp. 2004 All rights reserved. */
/* */
/* This sample program is owned by International Business Machines */
/* Corporation or one of its subsidiaries ("IBM") and is copyrighted */
/* and licensed, not sold. */
/* */
/* You may copy, modify, and distribute this sample program in any */
/* form without payment to IBM, for any purpose including developing, */
/* using, marketing or distributing programs that include or are */
/* derivative works of the sample program. */
/* */
/* The sample program is provided to you on an "AS IS" basis, without */
/* warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, */
/* EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
/* Some jurisdictions do not allow for the exclusion or limitation of */
/* implied warranties, so the above limitations or exclusions may not */
/* apply to you. IBM shall not be liable for any damages you suffer as */
/* a result of using, modifying or distributing the sample program or */
/* its derivatives. */
/* */
/***************************************************************************/
/* */
/* Program name: MSender */
/* */
/* Description: Sample java program that reads a line of input from the */
/* keyboard and sends it to a queue. */
/* */
/***************************************************************************/
/* */
/* Function: */
/* */
/* This program reads a line of input from the keyboard and sends it to a */
/* queue. A blank line ends the program. */
/* */
/* This program has been tested with WebSphere MQ V5.3 CSD7 and JDK 1.4.2. */
/* */
/***************************************************************************/
/* */
/* MSender has 2 parameters: */
/* queue name (required) */
/* queue manager name (optional) */
/* */
/***************************************************************************/
import com.ibm.mq.*;
import java.io.*;
public class MSender {
private static MQQueueManager qMgr;
public MSender() {
super();
}
public static void main(String args[]) {
try {
if (args.length < 1) {
System.out.println("Missing queue name: "
+ "MSender <queue name> <qmgr name (optional)>");
} else {
System.out.println("MSender started...");
// create a new instance of the sample program
MSender mSender = new MSender();
if (args.length > 1) {
qMgr = new MQQueueManager(args[1]);
} else {
qMgr = new MQQueueManager("");
}
int openOptions = MQC.MQOO_OUTPUT;
MQQueue q =
qMgr.accessQueue(args[0], openOptions, null, null, null);
// call method to send messages
mSender.mPut(qMgr, q);
// clean up connection
q.close();
qMgr.disconnect();
System.out.println("MSender ended...");
}
} catch (MQException ex) {
System.out.println(
"WMQ exception occurred : Completion code "
+ ex.completionCode
+ " Reason code "
+ ex.reasonCode);
}
}
/*************************************/
/* This method takes two parameters: */
/* qMgr - a WMQ QueueManager object */
/* q - a WMQ Queue object */
/*************************************/
public void mPut(MQQueueManager qMgr, MQQueue q) {
try {
// Define a MQ message buffer
MQMessage mBuf = new MQMessage();
// create message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// accept defaults
pmo.options = MQC.MQPMO_NONE; // use defaults
System.out.println("Enter text to send, blank line to exit");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String runShow;
do {
runShow = br.readLine();
if (runShow.length() > 0) {
mBuf.clearMessage(); // reset the buffer
mBuf.correlationId = MQC.MQCI_NONE; // set correlationId
mBuf.messageId = MQC.MQMI_NONE; // set messageId
mBuf.writeString(runShow); // set actual message
System.out.println("--> writing message to queue");
q.put(mBuf, pmo); // put the message out on the queue
}
} while (runShow.length() > 0);
} catch (MQException ex) {
System.out.println(
"MQ exception occurred : Completion code "
+ ex.completionCode
+ " Reason code "
+ ex.reasonCode);
} catch (java.io.IOException ex) {
System.out.println(
"An error occurred reading from message buffer: " + ex);
}
}
} _________________ sebastian signature |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Oct 05, 2006 11:27 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
2058 means that the QMGR name you specified is not the name of the queue manager that you connected to.
So either you're hitting the wrong port, or the queue manager name is in the wrong case. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Oct 05, 2006 3:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
MSender mSender = new MSender();
if (args.length > 1) {
qMgr = new MQQueueManager(args[1]);
} else {
qMgr = new MQQueueManager("");
}
|
Java is not like C
You cannot set the environment variable and expect to connect there.
You need to use the MQEnvironment class and set the parameters there. And don't forget to change the transport mode from bindings to client.
And please got to the top of the page and use the documentation button. There is a whole manual (Using Java) that will tell you what you need to do.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
sebastian |
Posted: Mon Oct 09, 2006 9:22 am Post subject: |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
I appreciate the information - thanks _________________ sebastian signature |
|
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
|
|
|
|