ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » MQSeries error with Java app.

Post new topic  Reply to topic
 MQSeries error with Java app. « View previous topic :: View next topic » 
Author Message
sebastian
PostPosted: Mon May 23, 2005 9:43 am    Post subject: MQSeries error with Java app. Reply with quote

Centurion

Joined: 12 Nov 2003
Posts: 110
Location: Philadelphia

I took the java code from page 75 of the "Websphere MQ Using Java SC34-6066-02" manual and attempted to run this from my laptop.

I am pretty confident that I am set up okay with MQ and java since I ran the MQIVP verification program and had no problems. When I try to run the MQSample progam, I get the error of MQJE001 Completion code 2 , Reason code 2058 (Qmgr name error).

The qManager variable looks good to me and I ran a command script that does a set for MQSERVER pointing to my server connection channel. It all seems right to me. Can anyone tell me what I am missing?

attached is the code, thanks Sebastian



// ======================================================================
// Licensed Materials - Property of IBM
// 5639-C34
// (c) Copyright IBM Corp. 1995, 1999
// ======================================================================
// MQSeries classes for Java sample application
//
// This sample runs as a Java application using the command :- java MQSample

import com.ibm.mq.*; // Include the MQSeries classes for Java package

public class MQSample
{
private String qManager = "PRH356T"; // define name of queue
// manager to connect to.
private MQQueueManager qMgr; // define a queue manager
// object
public static void main(String args[]) {
new MQSample();
}

public MQSample() {
try {

// Create a connection to the queue manager

qMgr = new MQQueueManager(qManager);

// Set up the options on the queue we wish to open...
// Note. All MQSeries Options are prefixed with MQC in Java.

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("SYSTEM.DEFAULT.LOCAL.QUEUE",
openOptions);

// Define a simple MQSeries message, and write some text in UTF format..

MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Hello World!");

// specify the message options...

MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the // defaults,
// same as MQPMO_DEFAULT


// put the message on the queue

system_default_local_queue.put(hello_world,pmo);

// get the message back again...
// First define a MQSeries message buffer to receive the message into..

MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = hello_world.messageId;

// Set the get message options...

MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
// same as MQGMO_DEFAULT
// get the message off the queue...

system_default_local_queue.get(retrievedMessage, gmo);

// And prove we have the message by displaying the UTF message text

String msgText = retrievedMessage.readUTF();
System.out.println("The message is: " + msgText);
// Close the queue...
system_default_local_queue.close();
// Disconnect from the queue manager

qMgr.disconnect();
}
// If an error has occurred in the above, try to identify what went wrong
// Was it an MQSeries error?
catch (MQException ex)
{
System.out.println("An MQSeries 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 whilst writing to the message buffer: " + ex);
}
}
} // end of sample


_________________
sebastian signature
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Mon May 23, 2005 9:47 am    Post subject: Re: MQSeries error with Java app. Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

sebastian wrote:
The qManager variable looks good to me and I ran a command script that does a set for MQSERVER pointing to my server connection channel. It all seems right to me. Can anyone tell me what I am missing?

You are missing the fact that Java doesn't use the MQSERVER variable. Or the client connection table variables.

Altough, in theory, you could use the Java API to read the MQSERVER variable, parse it yourself, and use it to populate MQEnvironment.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
sebastian
PostPosted: Mon May 23, 2005 9:54 am    Post subject: Reply with quote

Centurion

Joined: 12 Nov 2003
Posts: 110
Location: Philadelphia

My only experience using MQ programmatically has been with Perl up to this point.

In java, how does the program determine the path to the queue manager if you do not set the MQSERVER environment variable?

Any help is greatly appreciated,
Sebastian
_________________
sebastian signature
Back to top
View user's profile Send private message Visit poster's website
kingsley
PostPosted: Mon May 23, 2005 10:02 am    Post subject: Reply with quote

Disciple

Joined: 30 Sep 2001
Posts: 175
Location: Hursley

Java does'nt depend on channel table or mqserver variable.

You need to set the Environ class inside the Java program properly.

Java uses something similar to CONNX as it runs inside the JVM as a trusted buddy. If it messes up, JVM buddy is taken down. It was our expereince with Jms and WAS while working with MQSeries.
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Mon May 23, 2005 10:24 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

kingsley wrote:
Java does'nt depend on channel table or mqserver variable.

You need to set the Environ class inside the Java program properly.

Java uses something similar to CONNX as it runs inside the JVM as a trusted buddy. If it messes up, JVM buddy is taken down. It was our expereince with Jms and WAS while working with MQSeries.


You should not confuse JMS and WAS setup with java jvm
Yes the WAS will not start right if there is an error in JMS.
However this does not mean that the JVM gets taken down.
Normally it just means that any application needing a JMS resource will refuse to load. This may have as a successor effect that the WAS JVM never gets to the point where it displays "ready for ebusiness".

The "taking down" of the JVM is not systematic and is environmentally conditionned. JMS is stable enough not to take WAS down. However what is the point of bringing WAS up if your are missing a vital container resource ??

Just my 0.02 cts and sorry if I have misinterpreted your comment..
Back to top
View user's profile Send private message Send e-mail
sebastian
PostPosted: Mon May 23, 2005 10:29 am    Post subject: Reply with quote

Centurion

Joined: 12 Nov 2003
Posts: 110
Location: Philadelphia

Can anyone tell me how I could modify my code to connect to a queue manager on a different server?

Seb
_________________
sebastian signature
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Mon May 23, 2005 10:34 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

a) JMS this is done in the JNDI setup.
Check out the classes:MQQueueFactory and MQTopicFactory

b) Base Java: check out class MQEnvironment

c) read up on Using Java manual

Enjoy
Back to top
View user's profile Send private message Send e-mail
vennela
PostPosted: Mon May 23, 2005 10:46 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

http://www.mqseries.net/phpBB2/viewtopic.php?t=7984&highlight=mqclientput
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » MQSeries error with Java app.
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.