Author |
Message
|
liviur |
Posted: Fri May 13, 2011 8:51 am Post subject: MQ Broker v7.0 - Java Compute Node Transaction Participation |
|
|
Novice
Joined: 15 Nov 2005 Posts: 15
|
Hi,
Environment: Windows XP, IBM MQ Broker v7.0
I have a simple flow: MQInput node -> Java Compute Node -> MQOutput node.
The MQInput node has Transaction: YES and reads a message from an MQ Queue. Code in the Java compute node:
Code: |
Hashtable mqEnvironmentTable = new Hashtable();
mqEnvironmentTable.put(MQC.HOST_NAME_PROPERTY, "");
mqEnvironmentTable.put(MQC.PORT_PROPERTY, new Integer(2414));
mqEnvironmentTable.put(MQC.CHANNEL_PROPERTY, "CHANNEL1");
QQueueManager queueManager = null;
try {
queueManager = new MQQueueManager("MB7QMGR", mqEnvironmentTable);
MQQueue q = queueManager.accessQueue("DATA_IN", MQC.MQOO_INPUT_SHARED);
MQMessage msg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_SYNCPOINT;
q.get(msg);
queueManager.disconnect();
} catch (MQException e) {
}
|
The MQOutput node puts a message on another MQ queue. I'd like the code in the Java compute node to participate in the same transaction the MQ Broker started when it pulled the message in the MQInput node. However, this is not the case, as the message retrieved in the Java compute node is lost even if the flow rolls back (via a Throw).
I understand that what I'm trying to do via the Java code could be done using an MQGet broker node but the point is the attached sample code is just that, a sample. In my project, I'm using a legacy code component which performs a lot more than just an MQ Get and I do have to use it.
Any thoughts on how to make the Java MQ code participate in the Broker initiated transaction?
Thank you in advance! |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri May 13, 2011 8:56 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
The JCN does participate already. Throw an exception from the JCN and the message will be rolled back.
A couple of suggestions:
1. Have you taken the WMB developer class yet? Highly recommended.
2. Why are you getting a message from JCN? Whats wrong with MQGet node?
3. 99.9 percent of the message flows you develop will not use Transactionality. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 13, 2011 9:06 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
lancelotlinc wrote: |
Why are you getting a message from JCN? Whats wrong with MQGet node? |
At a bare minimum DO NOT CONNECT AND THEN DISCONNECT IMMEDIATELY.
Wow you will leave so many hanging connections that you will crash the qmgr in question... which is almost certainly the Broker's qmgr...
Also, why are you even using a client connection in the first place?
 |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri May 13, 2011 9:14 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Don't try to port a POJO or batch program directly into a JCN. WMB is a hgh speed messaging engine designed to process one unit of work at a time. A batch job that has 11,000 units of work should not be processed under a single transaction. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
liviur |
Posted: Fri May 13, 2011 9:24 am Post subject: |
|
|
Novice
Joined: 15 Nov 2005 Posts: 15
|
Hi all,
Thank you for your quick replies.
1. Point taken - when and if my organization will pay for said courses I will gladly participate
2. There is nothing wrong with the MQGet node however, as I've mentioned before, I have to use the legacy code.
3. The sample code connects / disconnects. In real life (my project) we're using MQEnvironment.addConnectionPoolToken() and MQEnvironment.removeConnectionPoolToken().
4. My understanding form reading the MQ Java API is that if you leave the Host name empty (which I am), it will use bindings (server mode). Am I misinterpreting the docs?
Thank you much! |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri May 13, 2011 9:33 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
1. There is really no point in you developing code using Message Broker if you do not have the right information. (ie. WMB developers course). I would not consider this optional or other than short term immediate goal.
2. No, you do not HAVE to use the legacy code. I would not use the legacy code in a JCN. A JCN is not an application container, it is a node in the WMB container. If your organization wants to use legacy code, port it to WAS server or Apache server, not WMB. Don't use a flat head screw driver on a phillips screw.
3. Running MQ API code continuously, WMB will work for about 3 days then choke, using MQ API calls. Don't use MQ API calls from inside WMB. You will crash the WMB runtime. This is a known issue. Raise a PMR if you intend to do this. Two blondes walked into a building. At least one of them should have scene it.
Your welcome. What happens to a blonde when she dyes her hair brunette? Artificial intelligence. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 13, 2011 9:38 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Whatever the legacy code is doing with the body of the MQ message can just as easily be done by using MQGet node using BLOB domain and passing this into the legacy code.
Whatever the legacy code is doing, it's probably at least as quick to rewrite it using broker normal methods as it is to try and make it work reliably within Broker without significant change. |
|
Back to top |
|
 |
liviur |
Posted: Fri May 13, 2011 9:47 am Post subject: |
|
|
Novice
Joined: 15 Nov 2005 Posts: 15
|
I wholeheartedly agree with both of you and may end up using the WSMB component to achieve my goals, partially or completely bypassing the legacy code.
However, it would have been nice to understand if it is technically possible to achieve transaction integration with legacy code which uses MQ API.
Best regards! |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri May 13, 2011 9:52 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
JCN can initiate a rollback, but there is no facility inside the JCN for compensating transactions inherent in a JCN itself. Therefore, the answer to your question is "no".
You must manually code compensating transactions in the error logic to accomplish what you are asking. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 13, 2011 9:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Your code is establishing an entirely separate connection to the queue manager than the connection that is in use by the MQInput node.
You can't mix transactions across MQ connections, regardless of where you are running your MQ code.
Broker does not currently provide a public API from within the MB Java APIs to access the Broker's MQ connection pools.
You could do things like store the MQ connection in a class variable and then access it again during exception handling to explicitly rollback the operation. |
|
Back to top |
|
 |
liviur |
Posted: Fri May 13, 2011 10:04 am Post subject: |
|
|
Novice
Joined: 15 Nov 2005 Posts: 15
|
That makes it clear. Will use WSMB nodes.
The time you've taken to explain is greatly appreciated! |
|
Back to top |
|
 |
|