|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Problems when sending TextMessages via Java |
« View previous topic :: View next topic » |
Author |
Message
|
haupto |
Posted: Mon Aug 15, 2005 9:34 pm Post subject: Problems when sending TextMessages via Java |
|
|
Newbie
Joined: 15 Aug 2005 Posts: 3
|
Hi,
just started a project where MQSeries is used to transport messages from one application part to the other. This includes an app we bought that can be triggered using messages to support it with commands.
Just coded some generic message receivers and senders that worked fine when only using Java.
But 'somehow' MQseries seems to mix my (javax.jms.)TextMessage up. The 'Format' is set to 'MQHRF2' so, the app I'm feeding with messages doesn't recognize the messages correctly.
Finally - thanks to this forum - I managed to send the messages correctly and they are recognized by MQ as TextMessges (Format is set to 'MQSTR' now).
Ok, now for the questions:
Is there any way to access MQSeries correctly without using all the MQ libraries? I'd prefer to stick to the implementations of the SUN interfaces only, to keep my code free of provider-specific stuff.
I'd like to use something like this:
Code: |
Hashtable env = new Hashtable();
env.put( Context.PROVIDER_URL,"SERVER:1414/SYSTEM.DEF.SVRCONN");
env.put( Context.INITIAL_CONTEXT_FACTORY,"com.ibm.mq.jms.context.WMQInitialContextFactory");
InitialContext ctx = new InitialContext(env);
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup( "INKA_QM_01" );
QueueConnection conn = factory.createQueueConnection();
QueueSession session = conn.createQueueSession( true, Session.AUTO_ACKNOWLEDGE );
Queue q = session.createQueue( "INKA_TEST" );
QueueSender sender = session.createSender( q );
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage msg = session.createTextMessage();
msg.setJMSType( JMSMessage.CLASS_TEXT );
msg.setText( "Hello World );
sender.send( msg );
connection.start();
|
So if there's some way to only use the SUN stuff (and of course its IBM implementation) this would be rather cool.
If someone got some more code snippets this would be awesome, too.
cu,
olli |
|
Back to top |
|
 |
vennela |
Posted: Mon Aug 15, 2005 10:26 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Have you looked at PTPSamples shipped with the product.
For me they are installed in this directory
C:\Program Files\IBM\WebSphere MQ\Tools\Java\jms |
|
Back to top |
|
 |
haupto |
Posted: Mon Aug 15, 2005 11:12 pm Post subject: |
|
|
Newbie
Joined: 15 Aug 2005 Posts: 3
|
vennela wrote: |
Have you looked at PTPSamples shipped with the product.
For me they are installed in this directory
C:\Program Files\IBM\WebSphere MQ\Tools\Java\jms |
I did. Just tried the samples again this morning, and the messages the samples produces are simply ... crappy. The samples create messages with the 'MQHRF2' format.
Was quite surprised, as I thought the IBM samples would create correct messages.
At the moment I'm using a mixture of MQ and javax.jms classes this works but it's somewhat like quick and dirty code. Would like to clean it up.
cu,
oll |
|
Back to top |
|
 |
vennela |
Posted: Mon Aug 15, 2005 11:23 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
haupto wrote: |
I did. Just tried the samples again this morning, and the messages the samples produces are simply ... crappy. The samples create messages with the 'MQHRF2' format.
|
You have toset the targetClient property.
They are really very good programs with explanation for every line.
Search for targetClient property in this forum and learn about uris and JNDI objects for MQ.
Let us know if you have problems and we will definitely help before you jump to conclusions. |
|
Back to top |
|
 |
fschofer |
Posted: Tue Aug 16, 2005 12:19 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi,
Quote: |
I did. Just tried the samples again this morning, and the messages the samples produces are simply ... crappy. The samples create messages with the 'MQHRF2' format.
Was quite surprised, as I thought the IBM samples would create correct messages. |
Its normal that MQ JMS Messages contains a RFH2 Header and the MQMD format is 'MQHRF2'. Thats because the MQRFH2 Header contains JMS data.
Only if you application cannot handle JMS Messages you have to omit the RFH2 Header
Quote: |
The MQRFH2 is optional, and its inclusion in an outgoing message is governed by
a flag in the JMS Destination class. You can set this flag using the WebSphere MQ
JMS administration tool. Because the MQRFH2 carries JMS-specific information,
always include it in the message when the sender knows that the receiving
destination is a JMS application. Normally, omit the MQRFH2 when sending a
message directly to a non-JMS application. This is because such an application
does not expect an MQRFH2 in its WebSphere MQ message. Figure 4 shows how
the structure of a JMS message is transformed to a WebSphere MQ message and
back again |
For more information look into the Using Java Guide
=> Mapping JMS messages onto WebSphere MQ messages
Greetings
Frank |
|
Back to top |
|
 |
|
|
 |
|
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
|
|
|
|