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 » REG: Reading a message from a queue using Java Application

Post new topic  Reply to topic
 REG: Reading a message from a queue using Java Application « View previous topic :: View next topic » 
Author Message
ppraveen33
PostPosted: Tue Jan 14, 2014 1:25 am    Post subject: REG: Reading a message from a queue using Java Application Reply with quote

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
View user's profile Send private message
smdavies99
PostPosted: Tue Jan 14, 2014 3:16 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Tue Jan 14, 2014 5:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Tue Jan 14, 2014 5:43 am    Post subject: Re: REG: Reading a message from a queue using Java Applicati Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue Jan 14, 2014 7:00 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
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
View user's profile Send private message Send e-mail
PeterPotkay
PostPosted: Tue Jan 14, 2014 7:51 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7717

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » REG: Reading a message from a queue using Java Application
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.