Author |
Message
|
mqwf1 |
Posted: Sat Jan 19, 2002 6:08 am Post subject: |
|
|
Novice
Joined: 13 Jan 2002 Posts: 22
|
source :
=============================================
import javax.jms.*; /* import of Sun's JMS interface */
/* Imports for MQSeries specific objects */
import com.ibm.mq.MQC;
import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnectionFactory; /* import to allow program */
/* to bypass JNDI lookup */
public class mqjmsro {
public static String QMGR = "FMCQM";
public static final String QUEUE = "REPLYQ" ;
public static void main( String[] args )
{
String outString = "Test message from mqjmsro";
Queue ioQueue = null;
QueueSession session = null;
QueueConnection connection = null;
QueueConnectionFactory factory = null;
System.out.println("mqjmsro sample program");
/********************************************************/
/* Process command-line arguments looking for qmgr name */
/********************************************************/
for ( int i=0; i<args.length; i++ ) {
String arg = args[i].toLowerCase();
if( arg.equals("-m") ) {
if (i+1< args.length) {
QMGR = args[++i];
} else {
System.out.println("Ignoring -m flag; no value supplied");
}
} else
// Report and discard any unknown command-line options
System.out.println("Ignoring unknown flag: " + arg );
}
try {
/****************************************************/
/* Create the connection factory directly from qmgr */
/****************************************************/
System.out.println(" creating QueueConnectionFactory");
factory = new MQQueueConnectionFactory();
((MQQueueConnectionFactory)factory).setQueueManager(QMGR);
/****************************************************/
/* Create the connection. Note: Receive calls will */
/* be blocked if the connection is not explicityly */
/* started. */
/****************************************************/
System.out.println(" creating connection");
connection = factory.createQueueConnection();
System.out.println(" starting connection");
connection.start();
/**************************************************/
/* Create a session that won't be transacted and */
/* that should automatically acknowledge received */
/* messages. */
/**************************************************/
System.out.println(" creating session");
boolean transacted = false;
session = connection.createQueueSession( transacted,
Session.AUTO_ACKNOWLEDGE);
/**********************************************/
/* Create a queue using the MQSeries specific */
/* queue name. */
/**********************************************/
ioQueue = session.createQueue( QUEUE );
/**********************************************/
/* Use the session to create a QueueSender by */
/* passing in the destination parameter. */
/**********************************************/
System.out.println(" creating a QueueSender");
QueueSender queueSender = session.createSender(ioQueue);
/***************************************************/
/* Create an empty message and put our text in it. */
/***************************************************/
System.out.println( " creating the message" );
TextMessage outMessage = session.createTextMessage();
outMessage.setText(outString);
/******************************************************/
/* In order to get a report exception, MQSeries must */
/* be given a destination for it. The following code */
/* will set the destination to be the queue manager */
/* and queue where the message is being sent. This */
/* would normally not be done but is being done here */
/* for convenience. */
/******************************************************/
MQQueue replyToQ = new MQQueue(QMGR,QUEUE);
Destination replyTo = (Destination) replyToQ;
outMessage.setJMSReplyTo(replyTo);
System.out.println(" setting Report property");
outMessage.setIntProperty("JMS_IBM_Report_Exception",
MQC.MQRO_EXCEPTION_WITH_DATA);
//should be put in MQMD header!!!
//outMessage.setStringProperty("JMSXUserID","1"); //exception jms1058
outMessage.setStringProperty("JMSXAppID","lad");
//info below will put in MQRFH2 header
outMessage.setStringProperty("JMSXGroupID","FMCGRP"); //JMSXUserID
outMessage.setStringProperty("x2D","1");
/*********************************/
/* Send the message to the queue */
/*********************************/
System.out.println( " sending message to " + ioQueue.getQueueName() );
queueSender.send(outMessage);
/***********************************/
/* Program is done, close objects. */
/***********************************/
System.out.println(" closing queue");
queueSender.close();
System.out.println(" closing session");
session.close();
session = null;
System.out.println(" closing connection");
connection.close();
connection = null;
} catch( JMSException je ) {
System.out.println("Caught JMSException: " + je);
Exception le = je.getLinkedException();
if (le != null) System.out.println("linked exception: " + le);
} catch( Exception e ) {
System.out.println("Caught exception: " + e );
} finally {
/*****************************************************/
/* We'll use a finally block to ensure that the most */
/* important JMS objects were closed. */
/*****************************************************/
try {
if (session != null) {
System.out.println(" closing session");
session.close();
}
if (connection != null) {
System.out.println(" closing connection");
connection.close();
}
} catch (JMSException je) {
System.out.println("Caught exception: "+je);
}
}
System.out.println("mqjmsro ending...");
}
}
=============================================
run infomation:
D:eccmqjmsro.java.tar>java mqjmsro
mqjmsro sample program
creating QueueConnectionFactory
creating connection
starting connection
creating session
creating a QueueSender
creating the message
setting Report property
Caught JMSException: javax.jms.MessageFormatException: MQJMS1058: not valid message property name JMSXAppID
closing session
closing connection
mqjmsro ending... |
|
Back to top |
|
 |
kolban |
Posted: Sat Jan 19, 2002 11:05 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
|
Back to top |
|
 |
mqwf1 |
Posted: Sat Jan 19, 2002 8:37 pm Post subject: |
|
|
Novice
Joined: 13 Jan 2002 Posts: 22
|
Thanks kolban.
I modify my source and try it .An exception was throw:
javax.jms.JMSException: MQJMS1011:
cannot indicate security credentials while using MQ binding
(it was translated English Message(sorry,not exactly)
original Chineses message is :
ʹÓà MQ °ó¶¨Ê±²»ÄÜÖ¸¶¨°²È«ÐÔÆ¾Ö¤
)
Pls tell me what is the problem?
Thanks.
|
|
Back to top |
|
 |
kolban |
Posted: Sun Jan 20, 2002 6:35 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
What does your source look like now? What line is throwing the exception? What is the underlying MQ linked error (if any)? |
|
Back to top |
|
 |
mqwf1 |
Posted: Mon Jan 21, 2002 1:11 am Post subject: |
|
|
Novice
Joined: 13 Jan 2002 Posts: 22
|
old source:
connection = factory.createQueueConnection();
changed source:
connection = factory.createQueueConnection("PM1","PM1");//userid,password
Exception Throws when execute this changed line and
Linked Exception is null.
Thanks. |
|
Back to top |
|
 |
kolban |
Posted: Mon Jan 21, 2002 6:09 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
IBM's JMS is layered/built on top of MQSeries. An MQSeries application can connect to the queue manager in one of two ways. It can be a "client" which means that it forms a network connection and supplies a userid or else it can be "server bound" which means it uses Inter Process Communication and must exist on the same box as the queue manager. In this case, no userid is supplied as authentication is taken from the userid that the application is running as.
Your JMS application is configured to connect to a local queue manager using server binding. In this case, when you attempted to set the userid that the JMS Client should appear to the queue manager as, it was rejected as an invalid operation.
Options:
o Don't set userid
o Connect to queue manager as client |
|
Back to top |
|
 |
mqwf1 |
Posted: Mon Jan 21, 2002 7:13 am Post subject: |
|
|
Novice
Joined: 13 Jan 2002 Posts: 22
|
I'm not sure I catch your words. I repeat it in my words below :
If my JMS app and request Queue in the same machine then I can't set userid;
Only if JMS app send message to remote queue JMS app can set userid.
Another relativa question:
What do I do to tell JMS that I want to run as client of remote MQ QM?
JMS API or Queue definition? |
|
Back to top |
|
 |
|