Accessing JMS queue from SwitchYard
bbelovic Jun 13, 2011 10:42 AMHello,
I've read that SwitchYard can access large set of endpoints - all endpoints supported in Apache Camel are accessible from SwitchYard. One of these endpoints are JMS queues.
I tried to configure SwitchYard service to access JMS queue (queue is deployed on AS6).
Here is the switchyard.xml file
<?xml version="1.0" encoding="UTF-8"?>
<switchyard xmlns="urn:switchyard-config:switchyard:1.0"
xmlns:swyd="urn:switchyard-config:switchyard:1.0"
xmlns:trfm="urn:switchyard-config:transform:1.0"
xmlns:bean="urn:switchyard-component-bean:config:1.0"
xmlns:soap="urn:switchyard-component-soap:config:1.0"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:camel="urn:switchyard-component-camel:config:1.0"
targetNamespace="urn:switchyard-quickstart-demo:orders:0.1.0-SNAPSHOT"
name="camel-binding">
<sca:composite name="camel-binding">
<sca:service name="GreetingService" promote="GreetingService">
<camel:binding.camel configURI="jms:OrderQueue_XXX?connectionFactory=ConnectionFactory">
</camel:binding.camel>
</sca:service>
</sca:composite>
</switchyard>
configUri attribute has the same format as in JMS component in Camel.
But when I deployed my srevice I've got exception saying:
Caused by: java.lang.RuntimeException: org.apache.camel.FailedToCreateRouteException: Failed to create route GreetingService-[jms:OrderQueue_XXX?connectionFactory=ConnectionFactory]: Route[[From[jms:OrderQueue_XXX?connectionFactory=ConnectionF... because of Failed to resolve endpoint: jms://OrderQueue_XXX?connectionFactory=ConnectionFactory due to: Could not find a suitable setter for property: connectionFactory 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: javax.jms.ConnectionFactory with value ConnectionFactory
at org.switchyard.component.camel.InboundHandler.<init>(InboundHandler.java:66) [:0.1.0-SNAPSHOT]
at org.switchyard.component.camel.deploy.CamelActivator.createInboundHandler(CamelActivator.java:242) [:0.1.0-SNAPSHOT]
... 56 more
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route GreetingService-[jms:OrderQueue_XXX?connectionFactory=ConnectionFactory]: Route[[From[jms:OrderQueue_XXX?connectionFactory=ConnectionF... because of Failed to resolve endpoint: jms://OrderQueue_XXX?connectionFactory=ConnectionFactory due to: Could not find a suitable setter for property: connectionFactory 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: javax.jms.ConnectionFactory with value ConnectionFactory
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:165) [:2.6.0]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:701) [:2.6.0]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1623) [:2.6.0]
at org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:649) [:2.6.0]
at org.apache.camel.impl.DefaultCamelContext.addRouteDefinition(DefaultCamelContext.java:654) [:2.6.0]
at org.switchyard.component.camel.InboundHandler.<init>(InboundHandler.java:64) [:0.1.0-SNAPSHOT]
... 57 more
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jms://OrderQueue_XXX?connectionFactory=ConnectionFactory due to: Could not find a suitable setter for property: connectionFactory 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: javax.jms.ConnectionFactory with value ConnectionFactory
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:449) [:2.6.0]
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47) [:2.6.0]
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:175) [:2.6.0]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110) [:2.6.0]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116) [:2.6.0]
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72) [:2.6.0]
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:88) [:2.6.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:737) [:2.6.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:160) [:2.6.0]
... 62 more
Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: connectionFactory 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: javax.jms.ConnectionFactory with value ConnectionFactory
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:341) [:2.6.0]
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:291) [:2.6.0]
at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:225) [:2.6.0]
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:200) [:2.6.0]
at org.apache.camel.component.jms.JmsComponent.createEndpoint(JmsComponent.java:449) [:2.6.0]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75) [:2.6.0]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:431) [:2.6.0]
... 70 more
I planned to create very simple service, which will monitor JMS queue, read all messages sent in this queue and print them to server console.
Is there some additional configuration needed? Can you provide some example how to access JMS queues?
I also noticed that there is a Spring configuration needed in order to configure Camel itself to access JMS queue. One should provide Camel with Spring XML file with JMS Component definition, this is then read by Camel, it creates SpringCamelContext after this JMS queues are accessible from Camel.
I created this spring-beans.xml with JMSComponent definition, put it into META-INF of my service, but nothing happened
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"/>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.hornetq.jms.client.HornetQConnectionFactory"/>
</property>
</bean>
</beans>
Is it possible to use SpringCamelContext from SwitchYard (this will allow to use components which need to be configured via Spring) or SwitchYard supports only DefaultCamelContext?