5 Replies Latest reply on Oct 17, 2014 6:14 AM by Jorge Morales

    Simple forward from file the queue

    Erhard Siegl Novice



      When I use a simple file binding to read a message and forward it with Camel to HornetQ like this:


        public void configure() {





      I don't get the message from the Queue. This fails:

        Session session = hornetQMixIn.createJMSSession();

        final MessageConsumer consumer = session.createConsumer(HornetQMixIn


        Message message = consumer.receive(3000);

        assertNotNull("Got message", message);


      However when I convert the body to a String it works:

        public void configure() {





      It seems that the message is an object-message when it comes from the file-component and the switchyard components don't know how to handle this. There is also no clear error-message which makes the problem hard to locate.

      My question is whether this is a bug or intended behaviour. In the second case where can I find more information when I have to convert messages?

      If needed I can upload a simple example that demonstrates this issue.



      Kind regards


        • 1. Re: Simple forward from file the queue
          Jorge Morales Master

          I guess that depending on your contracts your message body needs to be converted. For jms, you should see camel jms component documentation.

          You can specify your component contact to expect a string, so the massage gets implicitly converted.

          Documentation for switchyard is not very good so feel free to add a JIRA for whatever you think should be documented.

          • 2. Re: Re: Simple forward from file the queue
            Erhard Siegl Novice

            Thanks for the answer. I tried to add the property


                      <jms:parameter name="jmsMessageType" value="Text"/>


            with no success. I also attached a test-case.

            • 3. Re: Simple forward from file the queue
              Jorge Morales Master

              Hi Erhard,

              Your main problem is with the contracts you are using. It would simplify everything if you just use an interface of:

              "void write(String content)" as then the contents of the file would get converted to String before hitting the camel route, and then to the JMS as Text.


              Read this: http://unpoucode.blogspot.com.es/2014/10/switchyard-contracts.html


              PS: You can also use a ESB interface, which doesn't tie you to a physical class for the interface.

              PS2: In this other entry (http://unpoucode.blogspot.com.es/2014/10/copy-files-with-switchyard.html) you have a link to a github project where you can see at least left side of things (file binding with String contract) To adapt to your example, just replace the reference with the JMS binding you have (use the String example).


              Cheers, and I hope it helps,

              1 of 1 people found this helpful
              • 4. Re: Simple forward from file the queue
                Erhard Siegl Novice

                Hi Jorge,


                These are really interesting posts on your blog. Thanks! The reason why I'm hesitant to use String is the following:

                The real use cases are not simple copying of messages, but something like reading a XML-message, transforming it with JAXB to a Java object and do further manipulation. See e.g. sy-poc/switchyard.xml at master · Gepardec/sy-poc · GitHub for a little proof of concept we did. When I use WSDL -> Java-Interface (XML->MyMessage) I can use a JAXB transformer easily. However, when I tried String->MyMessage I couldn't find a way to do it with JAXB.

                The File->JMS is only one occasion when I had to use a explicit conversion in Camel. Another is in sy-poc/ResultRoute.java at master · Gepardec/sy-poc · GitHub where I get a org.apache.camel.component.exec.ExecResult.

                As I see it, on hand there is the interface to define the content-type of the message like Person or Order for example as XML. On the other hand this XML is "carried" on a String, a Stream, a File or in a ExecResult. The problem seem to be that for example on the JMS-component there is no (easy?) way to say "The message should be a Order as String". Therefore the JMS-Component gets an ExecResult-object or a File-object and doesn't know how to handle it properly.


                Best regards


                • 5. Re: Re: Simple forward from file the queue
                  Jorge Morales Master


                  Understood your point here. I guess that what you require is to the JMS binding do a conversion, from the pojo/XML type to String, so set a transformer there. If you instead need the XML representation of the object to be there, you need to instruct the implicit transform, like this:



                  public interface OrderService {
                      @OperationTypes(in = "{urn:switchyard-quickstart:bean-service:1.0}submitOrder")
                      void submitOrder(String orderXML);


                  This way you'll get into the submitOrder:

                  <urn:submitOrder xmlns:urn="urn:switchyard-quickstart:bean-service:1.0">


                  I hope this does the trick for you. That tip is in: http://unpoucode.blogspot.com.es/2014/10/switchyard-development-guidelines.html when talking about @OperationTypes.