Udostępnij za pośrednictwem


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?

Comments

  • Anonymous
    July 12, 2005
    typo on the link. Here is the correct url:
    http://java.sun.com/docs/books/tutorial/native1.1/implementing/array.html
  • Anonymous
    July 19, 2005
    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.
  • Anonymous
    July 22, 2005
    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,
  • Anonymous
    September 08, 2005
    The comment has been removed