12 July 2005

More on Java and MSMQ

In my original post on Java interop with MSMQ, I gave a sample implementation of a Queue class for Java that was able to send and receive strings, and I suggested that it would be pretty simple to extend it to send whatever you want.  A couple of people have asked just what would be required, so here are some additional details. 

For example, suppose you want to extend the Queue class to be able to send and receive a byte array.  Here's what you'd do:

First, Read The Fine Manual from Sun on sending arrays through JNI.  Then, using the newly-acquired knowledge from that page, add a couple of new native methods (one for send, one for receive) in the MsmqQueueNativeMethods.cpp file, that handle a jbyteArray as input instead of a jstring. Then expose those native methods in the Queue.java class, following the example set by the jstring methods.  Re-build, you're done. 

I've heard back from one person that this works.

If you aren't so comfortable with JNI, a simpler approach may be just to base64-encode the byte array into a string, on the sender and on the receiver side. This would require only Java programming.  But of course you would need a base64 encoding class, which is not included in the Java base class library, as far as I know.  I think Apache have one. Anyone?

Filed under: , ,
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# foobar said:
typo on the link. Here is the correct url:
http://java.sun.com/docs/books/tutorial/native1.1/implementing/array.html
12 July 05 at 5:15 PM
# Rory Winston said:
Actually there are BASE64 (de/en)coders in the JDK - they are just under the com.sun.* namespace, so are not "officially supported", although they have been there for a long, long time.
19 July 05 at 8:55 AM
# Prasad said:
Dino,

Could you please possibly add a method to remove a message after peek, that is a receive method given a label or correlationid.

Thanks,
22 July 05 at 11:47 AM
# Bert Szoghy said:
Hello,

Sun have been scrambling their web site so the link to the array reference no longer works. Fortunately, there is the Wayback:

http://web.archive.org/web/20030813063216/java.sun.com/docs/books/tutorial/native1.1/implementing/array.html

Fascinating subject: MSMQ with Java, thanks!

A possible bridge to Linux might be a UDP multicasting server on the Windows box which would be receiving XML from MSMQ as you describe and then passing it on to the Linux Java UDP clients.

The only gotcha I see is that if you do the UDP server in VB.NET, you might not be able to multicast to "groups" the way Java understands it. Someone, please contradict me with working code.

So I believe the UDP Server on the Windows box looks like it would need to be coded in Java rather than in VB.NET.

Refs with code for that:

http://docs.rinet.ru/UJ11/ch25.htm
and
http://rigauxf.waika9.com/

If others want to structure an Open Source project to try this, let me know.

More JNI on my own website: how to hook up Java to the MS Speech API.

Cheers,
Bert

08 September 05 at 3:54 PM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker