How do you pass a file from a message producer to a consumer using JMS?

Jerry Smith

Answer by Josh Rayls
I believe the best way to do this would be to use an ObjectMessage. Simply store your File object in the Message.

ObjectMessage msg = queue_session.createObjectMessage();

Upon consumption, just call the msg.getObject() method to return your File object.
Answer by Alessandro A. Garbagnati
I'm not sure that passing the File object will work. The problem is that the File object is just an "abstract representation of file and directory pathnames" (as stated by the JDK documentation), and it does not contain the file itself. What if the file is not located on the same system?
Your solution it's ok, just do not use java.io.File;
Answer by kunal khanna
I just used fileInput stream to read a file into a byte array,transmitted the array to a queue. The consumer reads this byte array and writes it to another file. It runs very well...