| Author | 
		  Message
		 | 
		
		  | ppraveen33 | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 1:25 am    Post subject: REG: Reading a message from a queue using Java Application | 
				     | 
			   
			 
		   | 
		
		
		   Apprentice
 
 Joined: 26 Jun 2013 Posts: 36
  
  | 
		  
		    
			  
				HI,
 
My scenario is a Java Program needs to read a message from a Queue. Consider Each message contains mqrfh2 headers and its elements. I need to access those elements. For this I have developed a java code as follows.
 
 
   
	| Code: | 
   
  
	
 
public class Read {
 
    private String qManager = "IB9QMGR";  // define name of queue
 
     // manager to connect to.
 
private MQQueueManager qMgr;                 // define a queue manager
 
     // object
 
public static void main(String args[]) {
 
new Read();
 
}
 
 
public Read() {
 
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 WebSphere MQ 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("Q2",
 
openOptions);
 
 
// Define a simple WebSphere MQ message, and write some text in UTF format..
 
 
MQMessage hello_world = new MQMessage();
 
/*hello_world.writeUTF("Hello World!");
 
String src=hello_world.getStringProperty("usr/EAIhEADER/SRC"); */
 
 
// specify the message option 
 
 
 
 
 
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 WebSphere MQ 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);
 
 
 
//retrievedMessage.writeUTF("Hello World!");
 
 
 
 
String srcQ=retrievedMessage.getStringProperty("SRCQ"); | 
   
 
I am passing MQRFH2 headers data using rfhutil by giving usr data(<srcQ>Q2</srcQ>). I am able to get the srcQ. But In usr we will be having EAIHdr folder,in that sub elements. So when I am passing the same message by giving usr data(<EAIHdr><srcQ>Q2</srcQ></EAIHdr>) I am unable to retrieve the queue name
 
 
Can anyone help on this?? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | smdavies99 | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 3:16 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Council
 
 Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land. 
  | 
		  
		    
			  
				Please edit your post and wrap bits of code inside [ C O D E ] tags 
 
for example
 
   
	| Code: | 
   
  
	
 
public class Read {
 
private String qManager = "IB9QMGR"; // define name of queue
 
// manager to connect to.
 
private MQQueueManager qMgr; // define a queue manager
 
// object
 
public static void main(String args[]) {
 
new Read();
 
} 
 
 | 
   
 
 
 
This makes it a lot easier to read.
 
 
Moderators. Can this be moved to the Java forum _________________ WMQ User since 1999
 
MQSI/WBI/WMB/'Thingy' User since 2002
 
Linux user since 1995
 
 
 
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 5:40 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| smdavies99 wrote: | 
   
  
	| Moderators. Can this be moved to the Java forum | 
   
 
 
 
So moved _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 5:43 am    Post subject: Re: REG: Reading a message from a queue using Java Applicati | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| ppraveen33 wrote: | 
   
  
	| Can anyone help on this?? | 
   
 
 
 
Yes - you need to code the Java correctly to achieve this. The segement you posted does not appear to be so coded in that it doesn't allow for sub folders. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 7:00 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				Also you need to read up on what you are coding.
 
You don't use msg.write to a message you just retrieved...   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | PeterPotkay | 
		  
		    
			  
				 Posted: Tue Jan 14, 2014 7:51 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Poobah
 
 Joined: 15 May 2001 Posts: 7723
  
  | 
		  
		    
			  
				
   
	| smdavies99 wrote: | 
   
  
	Please edit your post and wrap bits of code inside [ C O D E ] tags 
 
 | 
   
 
 
 
I added the code tags. _________________ Peter Potkay
 
Keep Calm and MQ On | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |