|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
Browse messages + RFH2 data in case there is such.. |
« View previous topic :: View next topic » |
Author |
Message
|
vasilev |
Posted: Tue Mar 19, 2024 11:49 pm Post subject: Browse messages + RFH2 data in case there is such.. |
|
|
![](images/avatars/19296965396366b54d5ba69.png) Acolyte
Joined: 31 Oct 2014 Posts: 58 Location: Germany
|
Hello,
I am reading messages and message data with PCF agent.
I also need to read the RFH2 header and data in case the message is in this format.
Can I use the same approach here and add some if clause or this is not possible and needs to be over JMS?
In such a case - how different messages can be read without deleting?
Code: |
PCFMessageAgent agt = new PCFMessageAgent(qmgr);
....
MQQueue browseQueue = null;
int j = 0;
int openOptionsReply = CMQC.MQOO_INQUIRE + CMQC.MQOO_BROWSE + CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_INPUT_SHARED;
browseQueue = qmgr.accessQueue(Q, openOptionsReply, null, null, null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_BROWSE_NEXT + CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING;
try {
MQMessage myMessage = null;
while (true) {
myMessage = new MQMessage();
myMessage.correlationId = com.ibm.mq.constants.CMQC.MQCI_NONE;
myMessage.messageId = com.ibm.mq.constants.CMQC.MQMI_NONE;
byte[] buffer = null;
myMessage.clearMessage();
browseQueue.get(myMessage, gmo);
buffer = new byte[myMessage.getDataLength()];
myMessage.readFully(buffer);
...... |
I have read:
https://stackoverflow.com/questions/49616262/issue-while-setting-mqrfh2-header-in-ibm-mq
https://stackoverflow.com/questions/55713782/how-to-retrieve-rfh-message-headers-from-a-message-coming-from-mq
and not sure if I can read all messages without a problem.
thank you _________________ Regards
V.Vasilev |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
bruce2359 |
Posted: Wed Mar 20, 2024 6:56 am Post subject: |
|
|
![](images/avatars/58715422151eef88d5f6e3.jpg) Poobah
Joined: 05 Jan 2008 Posts: 9405 Location: US: west coast, almost. Otherwise, enroute.
|
Odd that you would not cite official IBM documentation. Did you search RFH2 format on google? _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
vasilev |
Posted: Wed Mar 20, 2024 9:01 am Post subject: |
|
|
![](images/avatars/19296965396366b54d5ba69.png) Acolyte
Joined: 31 Oct 2014 Posts: 58 Location: Germany
|
The question is if i have to make CMQC.MQGMO_PROPERTIES_FORCE_MQRFH2 always or there is better way.
Ok i will test _________________ Regards
V.Vasilev |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
RogerLacroix |
Posted: Wed Mar 20, 2024 3:13 pm Post subject: Re: Browse messages + RFH2 data in case there is such.. |
|
|
![](images/avatars/136281076646ca0b3d89dee.gif) Jedi Knight
Joined: 15 May 2001 Posts: 3253 Location: London, ON Canada
|
vasilev wrote: |
I am reading messages and message data with PCF agent.
I also need to read the RFH2 header and data in case the message is in this format.
Can I use the same approach here and add some if clause or this is not possible and needs to be over JMS? |
I have never seen the Command Server return an MQRFH2 format message. I'm 99% sure that it will never happen but someone from IBM can chime in.
As for handling MQRFH2 formatted messages, here is a fully functioning Java/MQ sample:
Code: |
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.headers.MQDataException;
import com.ibm.mq.headers.MQRFH2;
/**
* Program Name
* MQTest72
*
* Description
* This java class will connect to a remote queue manager with the
* MQ setting stored in a HashTable and get an MQRFH2 message from a queue.
*
* Sample Command Line Parameters
* -m MQA1 -h 127.0.0.1 -p 1414 -c TEST.CHL -q TEST.Q1 -u UserID -x Password
*
* @author Roger Lacroix
*/
public class MQTest72
{
private static final SimpleDateFormat LOGGER_TIMESTAMP = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
private Hashtable<String,String> params;
private Hashtable<String,Object> mqht;
private String qMgrName;
private String inputQName;
/**
* The constructor
*/
public MQTest72()
{
super();
params = new Hashtable<String,String>();
mqht = new Hashtable<String,Object>();
}
/**
* Make sure the required parameters are present.
* @return true/false
*/
private boolean allParamsPresent()
{
boolean b = params.containsKey("-h") && params.containsKey("-p") &&
params.containsKey("-c") && params.containsKey("-m") &&
params.containsKey("-q") &&
params.containsKey("-u") && params.containsKey("-x");
if (b)
{
try
{
Integer.parseInt((String) params.get("-p"));
}
catch (NumberFormatException e)
{
b = false;
}
}
return b;
}
/**
* Extract the command-line parameters and initialize the MQ HashTable.
* @param args
* @throws IllegalArgumentException
*/
private void init(String[] args) throws IllegalArgumentException
{
int port = 1414;
if (args.length > 0 && (args.length % 2) == 0)
{
for (int i = 0; i < args.length; i += 2)
{
params.put(args[i], args[i + 1]);
}
}
else
{
throw new IllegalArgumentException();
}
if (allParamsPresent())
{
qMgrName = (String) params.get("-m");
inputQName = (String) params.get("-q");
try
{
port = Integer.parseInt((String) params.get("-p"));
}
catch (NumberFormatException e)
{
port = 1414;
}
mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));
mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));
// I don't want to see MQ exceptions at the console.
MQException.log = null;
}
else
{
throw new IllegalArgumentException();
}
}
/**
* Connect, open queue, get a message, close queue and disconnect.
*
*/
private void testReceive()
{
MQQueueManager qMgr = null;
MQQueue queue = null;
int openOptions = CMQC.MQOO_INPUT_AS_Q_DEF + CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_PROPERTIES_FORCE_MQRFH2 + CMQC.MQGMO_FAIL_IF_QUIESCING + CMQC.MQGMO_NO_WAIT;
// gmo.options = CMQC.MQGMO_PROPERTIES_IN_HANDLE + CMQC.MQGMO_FAIL_IF_QUIESCING + CMQC.MQGMO_NO_WAIT;
try
{
qMgr = new MQQueueManager(qMgrName, mqht);
MQTest72.logger("successfully connected to "+ qMgrName);
queue = qMgr.accessQueue(inputQName, openOptions);
MQTest72.logger("successfully opened "+ inputQName);
// Define a simple MQ message
MQMessage receiveMsg = new MQMessage();
receiveMsg.messageId = CMQC.MQMI_NONE;
receiveMsg.correlationId = CMQC.MQCI_NONE;
// get the message on the queue
queue.get(receiveMsg, gmo);
if (CMQC.MQFMT_RF_HEADER_2.equals(receiveMsg.format))
{
receiveMsg.seek(0);
MQRFH2 rfh2 = new MQRFH2(receiveMsg);
int strucLen = rfh2.getStrucLength();
int encoding = rfh2.getEncoding();
int CCSID = rfh2.getCodedCharSetId();
String format= rfh2.getFormat();
int flags = rfh2.getFlags();
int nameValueCCSID = rfh2.getNameValueCCSID();
String[] folderStrings = rfh2.getFolderStrings();
for (String folder : folderStrings)
MQTest72.logger("Folder: "+folder);
if (CMQC.MQFMT_STRING.equals(format))
{
String msgStr = receiveMsg.readStringOfByteLength(receiveMsg.getDataLength());
MQTest72.logger("Data: "+msgStr);
}
else if (CMQC.MQFMT_NONE.equals(format))
{
byte[] b = new byte[receiveMsg.getDataLength()];
receiveMsg.readFully(b);
MQTest72.logger("Data: "+new String(b));
}
}
else if ( (CMQC.MQFMT_STRING.equals(receiveMsg.format)) ||
(CMQC.MQFMT_NONE.equals(receiveMsg.format)) )
{
Enumeration<String> props = receiveMsg.getPropertyNames("%");
if (props != null)
{
MQTest72.logger("Named Properties:");
while (props.hasMoreElements())
{
String propName = props.nextElement();
Object o = receiveMsg.getObjectProperty(propName);
MQTest72.logger(" Name="+propName+" : Value="+o);
}
}
if (CMQC.MQFMT_STRING.equals(receiveMsg.format))
{
String msgStr = receiveMsg.readStringOfByteLength(receiveMsg.getMessageLength());
MQTest72.logger("Data: "+msgStr);
}
else
{
byte[] b = new byte[receiveMsg.getMessageLength()];
receiveMsg.readFully(b);
MQTest72.logger("Data: "+new String(b));
}
}
else
{
byte[] b = new byte[receiveMsg.getMessageLength()];
receiveMsg.readFully(b);
MQTest72.logger("Data: "+new String(b));
}
}
catch (MQException e)
{
MQTest72.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
catch (IOException e)
{
MQTest72.logger("IOException:" +e.getLocalizedMessage());
}
catch (MQDataException e)
{
MQTest72.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
finally
{
try
{
if (queue != null)
{
queue.close();
MQTest72.logger("closed: "+ inputQName);
}
}
catch (MQException e)
{
MQTest72.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
try
{
if (qMgr != null)
{
qMgr.disconnect();
MQTest72.logger("disconnected from "+ qMgrName);
}
}
catch (MQException e)
{
MQTest72.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
}
}
/**
* A simple logger method
* @param data
*/
public static void logger(String data)
{
String className = Thread.currentThread().getStackTrace()[2].getClassName();
// Remove the package info.
if ( (className != null) && (className.lastIndexOf('.') != -1) )
className = className.substring(className.lastIndexOf('.')+1);
System.out.println(LOGGER_TIMESTAMP.format(new Date())+" "+className+": "+Thread.currentThread().getStackTrace()[2].getMethodName()+": "+data);
}
/**
* main line
* @param args
*/
public static void main(String[] args)
{
MQTest72 write = new MQTest72();
try
{
write.init(args);
write.testReceive();
}
catch (IllegalArgumentException e)
{
MQTest72.logger("Usage: java MQTest72 -m QueueManagerName -h host -p port -c channel -q QueueName -u UserID -x Password");
System.exit(1);
}
System.exit(0);
}
}
|
later
Roger _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
vasilev |
Posted: Thu Mar 21, 2024 1:02 am Post subject: |
|
|
![](images/avatars/19296965396366b54d5ba69.png) Acolyte
Joined: 31 Oct 2014 Posts: 58 Location: Germany
|
Thank you, @Roger! _________________ Regards
V.Vasilev |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
|
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
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
|
|
|
|