Author |
Message
|
elenzo |
Posted: Thu Dec 20, 2012 10:24 am Post subject: Cast MQMessage to MbMessage in Java Compute ? |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
Hi, as part of a customer requirement I need to do a Req/reply client connection in a java compute, I have the code of the req/reply api and it works fine outside WMB, the problem I have is that the result of the API is a MQMessage, and I don't know how to copy this MqMessage into MbMessage to propagate it to the out terminal, any ideas ?
The Java compute code is (it is incomplete until I figure out how to copy the MqMessage)
Code: |
public class Conector_JavaCompute extends MbJavaComputeNode {
public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbMessage inMessage = assembly.getMessage();
MbMessage outMessage = new MbMessage();
copyMessageHeaders(inMessage, outMessage);
try {
// ----------------------------------------------------------
// Add user code below
String queueManager = "WBIMBQM";
String username = "";
String password = "";
String qSender = "INPUTQ";
String qReceiver = "OUTPUTQ";
int timeout = 60000;
String request = "<Message>Hello world</Message>";
MQEnvironment.hostname = "127.0.0.1";
MQEnvironment.port = 1414;
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
MQQueueManager qm = null;
MQQueue m_receiver = null;
try {
qm = new MQQueueManager(queueManager);
String txtResponse = new String();
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.expiry = timeout / 100;
msg.replyToQueueName = qReceiver;
msg.replyToQueueManagerName = queueManager;
msg.write(request.getBytes());
MQPutMessageOptions pmo = new MQPutMessageOptions();
qm.put(qSender, msg, pmo);
m_receiver = qm.accessQueue(qReceiver, MQC.MQOO_INPUT_AS_Q_DEF, null, null, null);
MQMessage response = new MQMessage();
// Set the get message options..
MQGetMessageOptions gmo = new MQGetMessageOptions();
response.correlationId = msg.messageId;
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = timeout;
m_receiver.get(response, gmo);
byte[] b = response.readStringOfByteLength(response.getDataLength()).getBytes();
for (int i = 0; i < b.length; i++)
if (b[i] == 0)
b[i] = 32;
txtResponse = new String(b);
MbElement outRoot = outMessage.getRootElement();
MbElement outBody = outRoot.createElementAsLastChild(MbXMLNSC.PARSER_NAME);
...
...
...
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,outMessage);
out.propagate(assembly);
|
Any help will be appreciated, may be there is another way to do the req/reply API using the Broker Objects (it must be a client connection because is an external queueManager and I cant use remote queues) |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Dec 20, 2012 10:30 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can not *cast* an MQMessage to an MBMessage.
They are *entirely* different things.
You must *map* from an MQMessage to an MBMessage, one field at a time.
You should review the documentation on creating user defined nodes in Java, particularly on receiving external data into a buffer. |
|
Back to top |
|
 |
elenzo |
Posted: Thu Dec 20, 2012 10:33 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
oohh I see...
well, as I am new in java I have no idea of how can I do this "Map", any code to help me ?
Can I surf the MQMessage with readFirstChild, nextChild and so on ? |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Dec 20, 2012 10:38 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
Purhaps I'm missing some point you are trying to make... Why didn't you use an MQOutput node followed by an MQGet node to do the request/reply?
Yes, you will need to go through the broker's Qmgr and not do a direct client connection but that will also give you better performance and other things. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Dec 20, 2012 10:39 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
elenzo wrote: |
oohh I see...
well, as I am new in java I have no idea of how can I do this "Map", any code to help me ?
Can I surf the MQMessage with readFirstChild, nextChild and so on ? |
You have to use the methods of the MQMessage object to access the fields of it.
You then have to use the methods of an MbMessage object to set the relevant fields.
If you do not know java this well, then you are very likely not qualified to produce a proper solution to this particular task, and are doing your customer a disservice by not informing them of this and asking them to pass the task to someone more qualified.
You are attempting to drive a sports car when you have only previously ridden bicycles. |
|
Back to top |
|
 |
elenzo |
Posted: Thu Dec 20, 2012 10:40 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
JosephGramig that would be the best, but I need to access queues in an AS400 qmgr, and we can't use remote queues, so I have no other idea to do it than a client connection with java. |
|
Back to top |
|
 |
elenzo |
Posted: Thu Dec 20, 2012 10:45 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
mqjeff thanks for the metaphor, unfortunatly I am the only one assigned to this project, and the client is very aware that I am not a java programmer, that is way I am looking for some help in this forum |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Dec 20, 2012 10:50 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
elenzo wrote: |
JosephGramig that would be the best, but I need to access queues in an AS400 qmgr, and we can't use remote queues, so I have no other idea to do it than a client connection with java. |
Why can't you use remote queues? |
|
Back to top |
|
 |
elenzo |
Posted: Thu Dec 20, 2012 10:53 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
It is a migration project and we have to coexist with Sonic ESB, and until we have all migrated we need to use the same queues in AS400 and right now they are defined as local queues, if we change then Sonic wouldn't work, so we can't do it. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Dec 20, 2012 11:11 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Dec 22, 2012 5:38 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
As you need to access a remote qmgr, use the JMSOutputNode and JMSRead/GetNode...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
elenzo |
Posted: Wed Dec 26, 2012 5:33 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
Yes, it's a posibility, but I will have to ask If we can use JMS objects. If there isn't other choice I might do it as you said. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Dec 26, 2012 7:13 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
elenzo wrote: |
Yes, it's a posibility, but I will have to ask If we can use JMS objects. If there isn't other choice I might do it as you said. |
Just a silly question (it is the holidays isn't it?)
Won't you be using JMS to interface with the Sonic ESB? If so why should there be a problem using the JMS nodes? _________________ 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 |
|
 |
elenzo |
Posted: Wed Dec 26, 2012 7:17 am Post subject: |
|
|
Acolyte
Joined: 22 Aug 2006 Posts: 53
|
Not exactly, but you are probably right, this queues I have to acces are in an AS400 QMGR, but sonic connects to them, so I guess they are using JMS. It looks like it is my best chance right now. |
|
Back to top |
|
 |
|