10 Replies Latest reply on Mar 27, 2015 7:15 PM by Max Ozkin

    Camel JMS reference binding

    Max Ozkin Apprentice

      I have a JMS composite reference and its Java interface contract is following:

       

      public interface ServiceABC {

          void sendCustomer(Customer c);

      }


      When I send a Customer object using this reference, I am getting following warning from SwitchYard/Camel:

       

      02:59:59,404 WARN  [org.apache.camel.component.jms.JmsBinding] (Camel (camel-15) thread #34 - JmsConsumer[testQueue]) Cannot determine specific JmsMessage type to use from body class. Will use generic JmsMessage. Body class: my.test.Customer. If you want to send a POJO then your class might need to implement java.io.Serializable, or you can force a specific type by setting the jmsMessageType option on the JMS endpoint

       

      What should I do in order to be able to send POJO to JMS queue? Well, actually I need to send a JSON representation of this POJO.

      I tried to add a transformer from Customer to String but it didn't help.

       

      Any ideas?

        • 1. Re: Camel JMS reference binding
          Max Ozkin Apprentice

          Does anyone have any working example of using Camel JMS reference binding? Such that Java operation takes non-String argument (as in the example above).

          • 2. Re: Camel JMS reference binding
            Tomohisa igarashi Master

            Hi Max,

            What should I do in order to be able to send POJO to JMS queue? Well, actually I need to send a JSON representation of this POJO.

            I tried to add a transformer from Customer to String but it didn't help.

             

            So You want to send a String message in JSON format, right? then you would need to use String type as a parameter. If you use Customer object as a parameter, then it means you want to send Customer object into JMS queue, and because of the Customer class doesn't implements Serializable, it can't be sent to JMS queue. Please remember SwitchYard transformer is applied when it checks the service contract and find a gap in input/output type.

             

            One another option would be to add your own camel converter from Customer to String, so camel would internally convert it at the last stage of the exchange. It's out of SwitchYard managed transformation though. See messageConverter option:

            Apache Camel: JMS

             

            hth,

            Tomo

            • 3. Re: Camel JMS reference binding
              Max Ozkin Apprentice

              Thanks Tomo. It is clear now that SY's Transformers won't help here.

              Could you pls provide one clarification on messageConverter option.. if I don't use Camel components (so I have no from()/to()) but use only Bean component and invoke composite reference, how/where do I specify custom converter as a Camel JMS option?

              • 4. Re: Camel JMS reference binding
                Tomohisa igarashi Master

                You should be able to use additionalUriParameters in binding.jms config. I would recommend to use SY transformer in this case to show the message type as a contract though.

                • 5. Re: Camel JMS reference binding
                  Max Ozkin Apprentice

                  I tried to use additionalUriParameters and set "messageConverter" property into the name of my transformer class. But at runtime it threw exception:

                   

                  Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: messageConverter as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.springframework.jms.support.converter.MessageConverter with value my.test.Transformers.

                   

                  What should be actually the value of "messageConverter" property? is it a class name? if so, what class it should point to?

                  You mentioned SY transformer.. I used my transformer which basically has a method with "@Transformer" annotation..

                  What is missing?

                  • 6. Re: Camel JMS reference binding
                    Tomohisa igarashi Master

                    I meant to change the parameter type to String and let SwitchYard transformer transform it. SwitchYard transformer is not a camel converter. Please see my first comment.

                    • 7. Re: Camel JMS reference binding
                      Max Ozkin Apprentice

                      If I would use "String" as the parameter type then why would I need a transformer at all? It is already String and can be sent as such. And the calling bean would have to send the string to the composite reference instead of POJO, but that was the whole point that I want my bean to send POJO and let SY to transform it to String before sending to JMS.

                      Thus I tried to explore the alternative approach with messageConverter, but couldn't make it work.

                      • 8. Re: Camel JMS reference binding
                        Tomohisa igarashi Master

                        If you just change the parameter of composite reference to String and keep the parameter of component reference as Customer, now you have a gap between them. Then SwitchYard transformer is picked up if Customer->String transformer exists. You can still send Customer object if parameter for component reference is Customer. For example, jca-inflow-hornetq quickstart uses this technique in its service binding, composite service has GreetingGateway interface with named JSON String parameter and component service has GreetingService interface with Person POJO. It triggers JSON->Person transformer.

                        • 9. Re: Camel JMS reference binding
                          Tomohisa igarashi Master

                          You would need to add @Named("myCustomerConverter") on your camel converter and specify messageConverter=#myCustomerConverter. But again, IMHO the first option for this usecase is to use SwitchYard transformer, so that you can see the type difference on the service contract.

                          1 of 1 people found this helpful
                          • 10. Re: Camel JMS reference binding
                            Max Ozkin Apprentice

                            Thanks. This way it works (with SY transformers).

                            I just had one Java interface for both component reference and composite reference. Now when I split it and created two interfaces (one accepting Customer and another accepting String), it works fine.