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 IndexWebSphere Message Broker (ACE) SupportSend plain String to MQ via JavaCompute Node

Post new topicReply to topic Goto page 1, 2  Next
Send plain String to MQ via JavaCompute Node View previous topic :: View next topic
Author Message
Thomas2ab
PostPosted: Fri Mar 07, 2014 9:20 am Post subject: Send plain String to MQ via JavaCompute Node Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Hello,

I'm having troubles in sending a simple text (like 'Hello World') via a JavaComputeNode.
I am using the BLOB parser but it is send as BytesMessage, and I want it as TextMessage (the queue consumer app only reads TextMessage).
I am not having any exception but always get to the output queue as ByteMessage.
Is there anyway to do it simpler?

thank you,

Regards,
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Mar 07, 2014 9:48 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

You should never send a JMS/WMQ message from inside a Java Compute Node. The InfoCenter explicitly warns against doing this. Always use the inbuilt facilties to interact with external resources and use the JCN as it was intended to be used; as a transformation node.

The simple way to do this is to form your message in the JCN & send it using an MQOutput node, configuring the header properties so that the MQOutput node knows you want a text message (Hint: text messages are made up of STRINGS). The node will then send the message appropriately for you, and you won't have to worry about the broker coming down round your ears.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Thomas2ab
PostPosted: Fri Mar 07, 2014 10:33 am Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Thank you.
Actually I simplified what I had to do. Basically we receive an XML message that we transform to a text message using business rules from an external java library (external .jar). That is why I am using and I need to use a JCN.
If I send it within the BLOB parser without doing nothing more, it's working perfectly, but the consumer needs it to be in TextFormat (String).
So I try removing the getBytes() method on the content of my message but even like this it didn't work (actually it sends a length=0 message to the MQOutput).
So I try something much more simple:
[code]out = getOutputTerminal("out");
inMessage = contact admin.getMessage();
outMessage = new MbMessage(inMessage);
MbElement outRoot = outMessage.getRootElement();
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "TEST", "Hello World");
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,
contact admin.getLocalEnvironment(),
contact admin.getExceptionList(),
outMessage);
out.propagate(outAssembly);[/code]
But that doesn't work, I still have the length=0 message in my MQOutput (no exception is thrown).

How can I set the MQ header to force it as String/Text?

Thank you,

Best Regards,
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Mar 07, 2014 10:51 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Thomas2ab wrote:
How can I set the MQ header to force it as String/Text?


Set the format of the header to be string?

I thought my hint was fairly unsubtle....
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Thomas2ab
PostPosted: Fri Mar 07, 2014 11:47 am Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Yes, sorry I didnt understand...
Could you explain it please?

Thank you,

Regards,
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Mar 07, 2014 11:52 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Thomas2ab wrote:
Yes, sorry I didnt understand...
Could you explain it please?


OK, so how clear do you need this? As it's Friday, how to set the MQ header to force it to a string is as follows:

- Locate the field in the MQ Header (known as the MQMD or MQ Message Descriptor) called Format. This field describes the format of the message (the clue is in the name)
- Set it to the value of MQFMT_STRING (or the code for a string message 'MQSTR ') to indicate the message is in a string format

Simple enough? Would you like to go through some of the controls on your car as well? Or have you noticed a correlation between the direction of travel & how you move the big wheel in front of your seat?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Thomas2ab
PostPosted: Fri Mar 07, 2014 4:03 pm Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Thank you.
Here is what I did:
[code]
mqmd.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"Format","MQSTR ");
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "TEST" , "Hello World!!");

MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,
contact admin.getLocalEnvironment(),
contact admin.getExceptionList(),
outMessage);
out.propagate(outAssembly);[/code]

But once in the MQOutput I only have unreadable caracters like encrypted one. It looks more like headers then the body that doesn't appear.
Is there something wrong in this code?

Thank you,

Regards,[/code]
Back to top
View user's profile Send private message
smdavies99
PostPosted: Sat Mar 08, 2014 12:18 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.

Before you process the message with your flow take a dump of it with the mq browser utility AMQSBCG.

This will tell you if there are some OTHER headers in the message apart from the MQMD.
As you are working with JMS there might be an MQRFH2 header as well. Your code needs to be aware of the complete message structure in order for it to be processed properly.
_________________
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
Thomas2ab
PostPosted: Sat Mar 08, 2014 11:27 am Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Hello,

Thank you for your help.
Actually my flow is like this:

MQInput -> JCN -> MQOutput

In the MQInput I'm putting any xml message, just to start the flow, via RFHUtil or even via Websphere MQ.

Before adding the header part in the JCN, my output was 'null' (length = 0), but I had no exception.
Now I have a message with a non zero-length size (and it is finally a TextMessage), but it seems that the body is the header content.
I mean I cannot find anywhere the 'Hello World!!' I sent...

Does it make sense to you? I am not sure where I should use the AMQSBCG in that case.

Thank you,

Regards,

I forgot to precise I am using WMB 8.0.0.1 e MQ 7.5.0.2
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Mar 08, 2014 8:31 pm Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Move at least to WMB 8.0.0.3 or IIB 9.0.0.1...
as for the rest... your tree should look like

Code:
Root
  Properties
  MQMD
  BLOB
     BLOB


Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
smdavies99
PostPosted: Sat Mar 08, 2014 10:46 pm Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Thomas2ab wrote:


Does it make sense to you? I am not sure where I should use the AMQSBCG in that case.



Use it to look at your message BEFORE your flow reads is. Stop the flow, put the message on the queue and browse it.
Then use the same utility to browse your message AFTER you have written it.

Running your message through your flow with usertrace enables will also help you see what is going on (coupled with TraceNodes either side of the JCN).
Set the trace node to output ${Root}.

Look at the various message trees and hopefully you can see what is happening to your message.
All veru much IIB/Broker development 102.
_________________
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
Thomas2ab
PostPosted: Mon Mar 10, 2014 3:28 pm Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Thank you for your help.
Here is the message before I processed it (basic XML sample message):

[code]C:\Program Files (x86)\IBM\WebSphere MQ\tools\c\Samples\Bin>amqsbcg.exe TEST.IN
DEVBTGQM

AMQSBCG0 - starts here
**********************

MQOPEN - 'TEST.IN'


MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****

StrucId : 'MD ' Version : 2
Report : 0 MsgType : 8
Expiry : -1 Feedback : 0
Encoding : 546 CodedCharSetId : 437
Format : ' '
Priority : 0 Persistence : 0
MsgId : X'414D5120444556425447514D2020202087831C532001BC03'
CorrelId : X'000000000000000000000000000000000000000000000000'
BackoutCount : 0
ReplyToQ : ' '
ReplyToQMgr : 'DEVBTGQM '
** Identity Context
UserIdentifier : 'XXX '
AccountingToken :
X'1601051500000030103509E117E66D824BB63B240B010000000000000000000B'
ApplIdentityData : ' '
** Origin Context
PutApplType : '11'
PutApplName : 'B\Plugin\Rfhutil\rfhutil.exe'
PutDate : '20140310' PutTime : '23185858'
ApplOriginData : ' '

GroupId : X'000000000000000000000000000000000000000000000000'
MsgSeqNumber : '1'
Offset : '0'
MsgFlags : '0'
OriginalLength : '-1'

**** Message ****

length - 86 of 86 bytes

00000000: 3C3F 786D 6C20 7665 7273 696F 6E3D 2231 '<?xml version="1'
00000010: 2E30 2220 656E 636F 6469 6E67 3D22 5554 '.0" encoding="UT'
00000020: 462D 3822 3F3E 0D0A 3C4D 6573 7361 6765 'F-8"?>..<Message'
00000030: 3E0D 0A20 203C 426C 6F63 6B31 3E0D 0A20 '>.. <Block1>.. '
00000040: 203C 2F42 6C6F 636B 313E 0D0A 3C2F 4D65 ' </Block1>..</Me'
00000050: 7373 6167 653E 'ssage> '



No more messages
MQCLOSE
MQDISC
C:\Program Files (x86)\IBM\WebSphere MQ\tools\c\Samples\Bin>[/code]


Here is after in the output queue how it looks:

[code]C:\Program Files (x86)\IBM\WebSphere MQ\tools\c\Samples\Bin>amqsbcg.exe GEN.SEND
PRICE.INP DEVBTGQM

AMQSBCG0 - starts here
**********************

MQOPEN - 'GEN.SENDPRICE.INP'


MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****

StrucId : 'MD ' Version : 2
Report : 0 MsgType : 8
Expiry : -1 Feedback : 0
Encoding : 546 CodedCharSetId : 1208
Format : 'MQSTR '
Priority : 0 Persistence : 0
MsgId : X'414D5120444556425447514D2020202087831C532001C302'
CorrelId : X'000000000000000000000000000000000000000000000000'
BackoutCount : 0
ReplyToQ : ' '
ReplyToQMgr : 'DEVBTGQM '
** Identity Context
UserIdentifier : 'XXX '
AccountingToken :
X'1601051500000030103509E117E66D824BB63B240B010000000000000000000B'
ApplIdentityData : ' '
** Origin Context
PutApplType : '11'
PutApplName : 'B\Plugin\Rfhutil\rfhutil.exe'
PutDate : '20140310' PutTime : '23220828'
ApplOriginData : ' '

GroupId : X'000000000000000000000000000000000000000000000000'
MsgSeqNumber : '1'
Offset : '0'
MsgFlags : '0'
OriginalLength : '-1'

**** Message ****

length - 364 of 364 bytes

00000000: 4D44 2020 0200 0000 0000 0000 0800 0000 'MD ............'
00000010: FFFF FFFF 0000 0000 2202 0000 B501 0000 '    ...."...Á...'
00000020: 2020 2020 2020 2020 0000 0000 0000 0000 ' ........'
00000030: 414D 5120 4445 5642 5447 514D 2020 2020 'AMQ DEVBTGQM '
00000040: 8783 1C53 2001 BC04 0000 0000 0000 0000 'çâ.S ...........'
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 '................'
00000060: 0000 0000 2020 2020 2020 2020 2020 2020 '.... '
00000070: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
00000080: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
00000090: 2020 2020 4445 5642 5447 514D 2020 2020 ' DEVBTGQM '
000000A0: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
000000B0: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
000000C0: 2020 12596 1256 4589 8596 6974 6820 2020 ' XXX '
000000D0: 1601 0515 0000 0030 1035 09E1 17E6 6D82 '.......0.5 ß.µmé'
000000E0: 4BB6 3B24 0B01 0000 0000 0000 0000 000B 'KÂ;$............'
000000F0: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
00000100: 2020 2020 2020 2020 2020 2020 2020 2020 ' '
00000110: 0B00 0000 425C 506C 7567 696E 5C52 6668 '....B\Plugin\Rfh'
00000120: 7574 696C 5C72 6668 7574 696C 2E65 7865 'util\rfhutil.exe'
00000130: 3230 3134 3033 3130 3233 3232 3038 3238 '2014031023220828'
00000140: 2020 2020 0000 0000 0000 0000 0000 0000 ' ............'
00000150: 0000 0000 0000 0000 0000 0000 0100 0000 '................'
00000160: 0000 0000 0000 0000 FFFF FFFF '........     '



No more messages
MQCLOSE
MQDISC[/code]


So basically I cannot find my Body (Hello World!!) in that message.
Is there something missing that could be the reason of it?

Thank you,

Regards,
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 10, 2014 9:54 pm Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

No there is something too many. It looks like your message has 2 MQMD headers instead of 1!
Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
smdavies99
PostPosted: Mon Mar 10, 2014 10:36 pm Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

As my colleague says, there are TWO MQMD headers. The clue here is the fixed length of 384 bytes.
What is missing is the actual message.

Perhaps you are copying the MQMD instead of the actual message data.

Kudos for carrying on with Java. What you want to do is so very simple in ESQL that many of of more experienced hacks/developers/whatever would do it almost without thinking.

I hope you start to appreciate the power of some of the tools you have at your disposal. browsing a raw message with amqsbcg can be very effective especially because it gives you the actual bytes in hex without the posibility of the data being skewed/translated by a graphical utility.
I can only wish that more posters here would use it before posting questions about invalid characters and CCSID's.
_________________
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
Thomas2ab
PostPosted: Tue Mar 11, 2014 5:44 am Post subject: Reply with quote

Acolyte

Joined: 07 Mar 2014
Posts: 51

Thank you for your help!
I truly agree about ESQL, the problem is that in that case I need to use JCN. This is a pre-requisite.

It seems indeed that there are 2 MQMD headers, which is weird as my Java code is:

Code:
 
mqmd.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"Format","MQSTR ");
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "TEST" , "Hello World!!");

MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,
contact admin.getLocalEnvironment(),
contact admin.getExceptionList(),
outMessage);
out.propagate(outAssembly);


How could I write 2 MQMD headers that way?

Thank you,

Regards,
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum IndexWebSphere Message Broker (ACE) SupportSend plain String to MQ via JavaCompute Node
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.