`
hiphunter921
  • 浏览: 67207 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

My first ride apache camel

    博客分类:
  • Java
阅读更多

These days I have create my first route of apache camel for a real enterprise bizz.

Just as what 《Camel in Action》 says: "Camel is an integration framework that aims to make your integration projects productive and fun" , It`s awsome that the Java DSL looks so directly and the Spring DSL is so powerful that you can just config the Spring xml to route for your own without java compiling.

 

The route as follows:

 

<route id="lz" autoStartup="false" trace="true">
	   	   <from uri="ftp://lori@127.0.0.1:21?password=123&amp;filter=#lzFtpFileNameFilter&amp;maximumReconnectAttempts=1&amp;reconnectDelay=3000&amp;disconnect=true&amp;pollStrategy=#lzPollingConsumerPollStrategy&amp;throwExceptionOnConnectFailed=true"/>
	   	   <camel:onCompletion>
	   	       <process ref="stopLZRouteProcessor"/>
	   	   </camel:onCompletion>
	   	   
	   	   <camel:log loggingLevel="INFO" message="Picked up ${file:name}"/>
	   	   <process ref="zipFileSplittingProcessor"/>
	   	   <split>
	   	   	   <simple>${body}</simple>
	   	   	   <unmarshal><csv /></unmarshal>
	   	   	   <bean ref="lzServiceBean" method="csv2MapList"/>
	   	   	   <split>
	   	   	   		<simple>${body}</simple>
	   	   	   		<camel:setHeader headerName="Subject"><camel:constant>Test subject</camel:constant></camel:setHeader>
	   	   	   		<camel:setHeader headerName="From"><camel:constant>Lori</camel:constant></camel:setHeader>
	   	   	   		<camel:setHeader headerName="contentType"><camel:constant>text/html;charset=UTF-8</camel:constant></camel:setHeader>
	   	   	   		<camel:setHeader headerName="to"><camel:simple>${body[dest]}</camel:simple></camel:setHeader>
	   	   	   		<to uri="velocity://template/test.vm?contentCache=true&amp;encoding=utf-8"/>
	   	   	   		<to uri="smtp://mail.elitecrm.com?username=loriling@elitecrm.com&amp;password=0308"/>
	   	   	   </split>
	   	   </split>
	   </route>
 

 

With this route, the bigest problem is that I want to catch errors in the FTP endpoint (invalid login, server down, etc). I have tried errorHandler() but it only catches the errors produced after the message enters the exchange i.e. after from().

 

i try to set the FTP endpoint properties:

throwExceptionOnConnectFailed=true and pollStrategy=#lzPollingConsumerPollStrategy

then the FTPConsumer will  thrown an exception if a successful connection and login could not be establish and using the custom PollingConsumerPollStrategy which coded:

consumer.stop();

 in the rollback method.

Then the problem solved, it will only consume once if there is an exception of which FTP endpoint throws.

 

There are many features and EIPs that I havenot deal with and much more things i need to learn.

Last i extend my heartfelt gratitude to each camel authors and committers for bringing us so pretty project. Thanks again.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics