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).
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:
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?
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.
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?
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.
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.
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.
1 of 1 people found this helpful
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.
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.