You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Bijoy Chaudhury <bi...@gmail.com> on 2013/12/10 08:03:52 UTC

Query on PollingConsumer

Hi,

I have a requirement to FTP a file to a directory but the details of the
FTP route to be picked from a JMS message.

So to implement the route I have used a processor which reads the message
received from JMS component and then uses PollingConsumer Template to fetch
the file from FTP location and then passes the exchange object to FILE
component.

Following is the implementation in Spring DSL...

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
                              http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
                              http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

 <context:annotation-config />

<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
      <property name="brokerURL" value="tcp://localhost:61616"/>
   </bean>

<bean id="jmsProcessor"
class="com.ericsson.crs.camel.processors.JmsToFtpProcessor"/>

  <camel:camelContext id="context1">
      <camel:consumerTemplate id="consumer"/>
         <camel:route id="jmsTransport">
            <camel:from uri="activemq:queue:TEST"/>
            <camel:process ref="jmsProcessor"/>
            <camel:to uri="file:/home/Camel_Work_Dir/FTP_Outbox"/>
        </camel:route>
  </camel:camelContext>
</beans>

*then the Processor implementation... *

public class JmsToFtpProcessor implements Processor {

    private String ftpAddressURI; //fully qualified URI for FTP endpoint;

    @Autowired
    private ConsumerTemplate consumer;

    public void process(Exchange exchange) throws Exception
    {
            Exchange localExchange=null;
            this.ftpAddressURI=exchange.getIn().getBody(String.class);
            System.out.println("Polling to location:  "+ftpAddressURI);
            localExchange = consumer.receive(this.ftpAddressURI);

exchange.getOut().setBody(localExchange.getIn().getBody(Object.class));

exchange.getOut().setHeaders(localExchange.getIn().getHeaders());

            System.out.println("Polling completed!!!");
     }
}

*My question* : is there any other way to achieve this task more
efficiently? This could have been simply achieved through enrich() &
pollEnrich() had they supported simple expressions. Does camel provide any
similar built-in methods which supports expressions and with which dynamic
polling can be achieved?

Thanks a lot!

Regards,
Bijoy