Fuse esb - using quartz - apache-camel

i want to build simple copy from folder to folder application using camel:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true"/>
<to uri="file:src/data/new"/>
</route>
</camelContext>
I wanted to add quartz to copy file every 5 seconds.
I found something like this:
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
<property name="startDelayedSeconds" value="5"/>
</bean>
but i don't know how to use it to in my example.
Please help

You do not need to use quartz. Just change your from:
file:src/data?noop=true&consumer.delay=5000

Related

Implementing Durable Subscription on ServiceMix

I currently am using ServiceMix to route messages using QPID libraries.
My working config is below :
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="amqp" class="org.apache.camel.component.amqp.AMQPComponent">
<property name="connectionFactory">
<bean class="org.apache.qpid.jms.JmsConnectionFactory">
<property name="remoteURI" value="failover:amqps://remote-broker:9551?transport.trustStoreLocation=/vault/QA_UM_A.jks />
</bean>
</property>
</bean>
<bean id="kubeActivemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://10.100.10.13:61616" />
</bean>
<route>
<from uri="amqp:queue:///queue-1" />
<to uri="kubeActivemq:local-queue?jmsMessageType=Text" />
</route>
</camelContext>
</blueprint>
The above config works.
Now I need to implement durable subscription so that if servicemix goes down, it is able to recover all messages when it comes back up (the ones sent when servicemix is down.)
Based on the documentation , I have implemented a route :
<route>
<from uri="amqp:queue:///queue-1?clientId=1&durableSubscriptionName=bar1" />
<to uri="kubeActivemq:queue:///local-queue" />
</route>
But this implementation gives the ERROR :
2018-05-28 13:28:58,421 | ERROR | mix-7.0.0/deploy | BlueprintCamelContext | 40 - org.apache.camel.camel-blueprint - 2.16.4 | Error occurred during starting Camel: CamelContext(camel-1) due A durable subscription requires a topic (pub-sub domain)
java.lang.IllegalArgumentException: A durable subscription requires a topic (pub-sub domain)
at org.springframework.jms.listener.AbstractMessageListenerContainer.validateConfiguration(AbstractMessageListenerContainer.java:435)
at org.springframework.jms.listener.AbstractJmsListeningContainer.afterPropertiesSet(AbstractJmsListeningContainer.java:157)
at org.apache.camel.component.jms.JmsConsumer.prepareAndStartListenerContainer(JmsConsumer.java:163)
at org.apache.camel.component.jms.JmsConsumer.doStart(JmsConsumer.java:155)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3234)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3528)
at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:3464)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3394)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3162)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3018)
.
.
.
Is there something Ive missed here ? Arent the topic names supposed to be same as queue names ?
Your route is instructing Camel to connect to a queue, and you need to change it to use a 'topic' for Durable Subscriptions. (Queue subscriptions are durable by default)
amqp:queue:///queue-1...
And Durable Subscriptions require a topic
amqp:topic:///topic-1...

Activemq Not Starting with HTTP uri

I am using activemq with camel for consuming messages from a queue and send them to a http server. I am using following camel configuration :-
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:Consumer.A.VirtualTopic.Orders"/>
<to uri="http://localhost:8080/" />
<!-- <to uri="file:///Users/vinod/activemq.txt"/> -->
<!-- <to uri="activemq:queue:sssss"/> -->
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?create=false"/>
</bean>
</property>
</bean>
In first block creates a route which consumer messages from activemq:queue:Consumer.A.VirtualTopic.Orders queue and send them to server at http://localhost:8080/. The other two commented destinations are working fine, but when I start activemq with above configuration for sending messages over http, the server stops without throwing any error message. Activemq log for this is https://gist.github.com/kumar003vinod/1e5944cb246edb74c47fef7a0b433387
Please provide some insight.
Make sure to include camel-http and camel-http-common JARs in the ActiveMQ lib/camel directory. You may also need to include the transitive dependencies from camel-http in that directory so ActiveMQ has all the needed JARs in its classpath.
That would be commons-httpclient and commons-codec JARs but I think they are already included in lib/optional.

set endpoint of an OSGI Blueprint file in ServiceMix

I know I can define Camel routes in stand-alone xml file, using the Blueprint syntax. If I move one of this file in the "deploy" folder of ServiceMix, it automatically becomes an OSGI bundle. My question is, can I set an endpoint to this new bundle, accessible from outside?
I would like to do something like this:
blue_route1.xml
<blueprint>
<camelContext>
<route>
<from uri="http:my_servicemix:8181/blue_route1_endpoint" />
<to uri="jetty:http://server1" />
</route>
</camelContext>
</blueprint>
blue_route1 becomes an OSGI bundle once deployed, but where should I define "blue_route1_endpoint" ? Is it doable?
[UPDATE]
summering, I want that an external WS is able to send messages to blue_route1_endpoint, where the blue_route1 bundle will redirect messages according to Camel routes, without the need to create a new WS "Blue_route1" to deploy in ServiceMix
______________________
| ____________ |
external-->(blue_route1_endpoint)==|==-->|blue_route1|--|-->(http://server1)
WS | |___________| |
|____________________|
ServiceMix
Found it! I didn't get that it's so easy. To make ServiceMix listen on a port, I just have to specify the endpoint using the Camel-jetty component.
So, to answer my question, I solved in this way:
install the camel-jetty component in ServiceMix
features:install camel-jetty
Write the camel-route with Blueprint, in blue_route1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri:="jetty:http:my_servicemix:8181/blue_route1_endpoint">
<to uri="http://localhost:8080/user/services/user?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
</route>
<route>
<from uri="jetty:http://0.0.0.0:6969/sp_role?matchOnUriPrefix=true"/>
<setHeader headerName="Content-Type">
<groovy>"text/xml; charset=utf-8"</groovy>
</setHeader>
<to uri="http://server1"/>
</route>
</camelContext>
</blueprint>
I used a random port 8181 to listen to... but I could choose every number, ServiceMix will automatically start a jetty component, listening and consuming on that port/endpoint.
For SOAP messages you need CXF Component and wsdl file of your webservice. You can configure your endpoint outside of the camelContext like this:
<cxf:cxfEndpoint id="yourId" address="/your/address/to/endpoint"
serviceClass="your.java.ServiceClass"
wsdlURL="path/to/your/wsdl/file.wsdl" />
And in your route use tag like this:
<from uri="cxf:bean:yourId"/>
You need to add namespace and schemaLocation to your blueprint to use cxf namespace, use this:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

JBOSS FUSE Bundle is waiting for namespace handlers in GracePeriod

I tried to add bean into blueprint.
Added CXF namespace. But, JBOSS FUSE shows
13:10:28,339 | INFO | NAPSHOT-thread-1 | BlueprintContainerImpl | 14 - org.apache.aries.blueprint.core - 1.0.1.redhat-60024 | Bundle camel-basic is waiting for namespace handlers [http://camel.apache.org/schema/cxf]
So, I remove the cxf and added blueprint namespace
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
But, still no use, It shows same error for this namespace also.
Do I need to change anything in pom, blueprint.xml r need install anything in jboss fuse?
I have no clue about this.
blueprint.xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<camelContext id="blueprintContext"
trace="false"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="httpBridge">
<from uri="jetty:http://localhost:8282/service_sample_proxy/services_proxy/WebserviceClassPort?matchOnUriPrefix=true"/>
<process ref="downloadLogger"/>
<to uri="jetty:http://localhost:8080/service_sample/services/WebserviceClassPort?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<process ref="downloadLogger"/>
<to uri="bean:helloBean"/>
</route>
</camelContext>
<cxf:cxfEndpoint id="webserviceProxy"
address="http://localhost:8383/service_sample_proxy/services_proxy/WebserviceClassPort"
endpointName="tns:WebserviceClassPort"
serviceName="tns:WebserviceClassService"
wsdlURL="wsdl/webserviceclass.wsdl"
xmlns:tns="http://webservice/" />
<bean id="helloBean" class="org.fusesource.example.HelloBean" />
<bean id="downloadLogger" class="org.fusesource.example.DownloadLogger"/>
</blueprint>
I haven't used this bean in any place. First I need to resolve this problem then I need to use it in route.
I check the
Please help me.
Install all needed features into your Fuse container (see here for more information):
features:addUrl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install war
features:install cxf
features:install camel-jaxb
features:install camel-blueprint
features:install camel-cxf
Well, I went through all the steps stated above to find out it still does not work in blueprint.
Strangely as soon as the route was dropped in the spring xml and taken out of blueprint everything started working like a magic.
Tried camel-cxf instead cxf and worked with blueprint

Apache Camel message multiplexer integration pattern

I am trying to determine the best way to combine message streams from two hornetq broker instances into a single stream for processing, using Apache Camel and Spring. This is essentially the opposite of the Camel reciepient list pattern; but instead of one to many I need many to one. One idea is to implement this functionality with the direct component:
<?xml version="1.0" encoding="UTF-8"/>
<beans xmlns="..."
xmlns="...">
<!-- JMS Connection 1 -->
<bean id="jndiTemplate1" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
...Connection 1 Specific Information...
</props>
</property>
</bean>
<bean id="jmsTopicConnectionFactory1"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate1"/>
</property>
<property name="jndiName">
<value>java:jms/RemoteConnectionFactory</value>
</property>
</bean>
<bean id="jms1" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsTopicConnectionFactory1"/>
</bean>
<!-- JMS Connection 2 -->
<bean id="jndiTemplate2" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
...Connection 2 Specific Information...
</props>
</property>
</bean>
<bean id="jmsTopicConnectionFactory2"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate2"/>
</property>
<property name="jndiName">
<value>java:jms/RemoteConnectionFactory</value>
</property>
</bean>
<bean id="jms2" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsTopicConnectionFactory2"/>
</bean>
<!-- Camel route many to 1 using direct component -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="hornetQ_broker_1">
<from uri="jms1:topic:testTopic1">
<to uri="direct:process_message">
</route>
<route id="hornetQ_broker_2">
<from uri="jms2:topic:testTopic2">
<to uri="direct:process_message">
</route>
<route id="message_processor">
<from uri="direct:process_message">
<log message="message_processor received message">
</route>
</camelContext>
</beans>
Question: Is the above approach recommended when a many->1 integration pattern is required? If multiple Apache Camel solutions exist, what are the key performance impacts of each approach?
Runtime environment:
HornetQ brokers are JBoss EAP6.
Camel context deployed to FuseSource 4.4.1
Each entity exists on a seperate server/jvm.
Notes:
The hornetQ broker instances cannot be clustered.
The hornetQ broker instances do not contain duplicate data.
I think that your approach is valid for your scenario. However, maybe direct is not the component you need to use for this if you are running in different JVMs.
There are different components for internal queues: Direct, Direct-VM, SEDA, VM, Disruptor... but I believe all of them are if you are running in the JVM (and some of the if you just running in the same CamelContext). For more info: How do the direct, event, seda and vm endpoints compare
If you are going to have different CamelContexts across different JVM will need to use a different component.

Resources