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

    Simple forward from file the queue

    erhard

      Hi,

       

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

       

        public void configure() {

             from("switchyard://IncomingFile")

             .to("switchyard://IncomingQueue");

        }

       

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

        Session session = hornetQMixIn.createJMSSession();

        final MessageConsumer consumer = session.createConsumer(HornetQMixIn

        .getJMSQueue(queueName));

        Message message = consumer.receive(3000);

        assertNotNull("Got message", message);

       

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

        public void configure() {

             from("switchyard://IncomingFile")

             .convertBodyTo(String.class)

             .to("switchyard://IncomingQueue");

        }

      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

      Erhard

        • 1. Re: Simple forward from file the queue
          jorgemoralespou_2

          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

            Thanks for the answer. I tried to add the property

                    <jms:additionalUriParameters>

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

                    </jms:additionalUriParameters>

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

            • 3. Re: Simple forward from file the queue
              jorgemoralespou_2

              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

                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

                Erhard

                • 5. Re: Re: Simple forward from file the queue
                  jorgemoralespou_2

                  Hi,

                  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">
                     <order>
                        <orderId>1</orderId>
                        <itemId>1</itemId>
                        <quantity>100</quantity>
                     </order>
                  </urn:submitOrder>
                  

                   

                  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.