一demo
工程
路基工程安全技术交底工程项目施工成本控制工程量增项单年度零星工程技术标正投影法基本原理
1.下面给出一个从from到to有中间流程process处理的例子publicclassFileMoveWithCamel{publicstaticvoidmain(String[]args)throwsException{CamelContextcontext=newDefaultCamelContext();context.addRoutes(newRouteBuilder(){//将d:/temp/inbox/下的文件经过process处理移到d:/temp/outboxpublicvoidconfigure(){from("file:d:/temp/inbox?noop=true").process(newFileConvertProcessor()).to("file:d:/temp/outbox");}});context.start();booleanloop=true;while(loop){Thread.sleep(9000);}context.stop();}}classFileConvertProcessorimplementsProcessor{@Overridepublicvoidprocess(Exchangeexchange)throwsException{try{InputStreambody=exchange.getIn().getBody(InputStream.class);BufferedReaderin=newBufferedReader(newInputStreamReader(body));StringBufferstrbf=newStringBuffer("");Stringstr=null;str=in.readLine();while(str!=null){System.out.println(str);strbf.append(str+"");str=in.readLine();}exchange.getOut().setHeader(Exchange.FILE_NAME,"converted.txt");exchange.getOut().setBody(strbf.toString());}catch(IOExceptione){e.printStackTrace();}}}2.下面这个例子是每隔10秒访问一次http请求,并将访问到的内容写入文件/***1CreateaCamelContext.2Optionally,configurecomponentsorendpoints.3AddwhateverroutingrulesyouwishusingtheDSLandRouteBuilderorusingXmlConfiguration.4Startthecontext.*/publicclassHttpPollWithQuartzCamel{publicstaticvoidmain(Stringargs[])throwsException{CamelContextcontext=newDefaultCamelContext();context.addRoutes(newRouteBuilder(){publicvoidconfigure(){from("quartz://report?cron=10****?&stateful=true").to("http://www.baidu.com").to("file:d:/temp/outbox?fileName=httpindex2.csv");}});context.start();booleanloop=true;while(loop){Thread.sleep(25000);}context.stop();}}3.在做系统集成的时候,必不可少的任务就是将数据从一种格式转换为另一种格式,再把转换后的格式发到目标系统,在此用实例介绍一下Camel中利用Freemarker做数据转换.a:Freemarker的模板如下:
<#escapexasx?xml> <#listbody.peopleListasp> ${p.fname} ${p.gname} ${p.email} <#ifp.level=="L1"> xxx #if> #list> #escape>b:与之对应的Java对象如下:每一个person节点对应一个ValueObject放在XMLTemplateParameter的peopleList里面.publicclassXMLTemplateParameter{ privateStringfileName; privateList
peopleList=newArrayList(); publicListgetPeopleList(){ returnpeopleList; } publicvoidsetPeopleList(ListpeopleList){ this.peopleList=peopleList; } publicStringgetFileName(){ returnfileName; } publicvoidsetFileName(StringfileName){ this.fileName=fileName; }}publicclassValueObject{ privateStringfname; privateStringgname; privateStringemail; privateStringmanager; privateStringlevel;c:Route代码如下:publicclassCamelFreemarkerRouteextendsRouteBuilder{ publicvoidconfigure()throwsException{ from("quartz://report?cron=10****?&stateful=true") .beanRef("fmBean","prepareFMValues") .to("freemarker:com/test/camel/freemarker/test.ftl") .to("file:d:/temp/outbox?fileName=fm.xml"); }}d:Route里用到的bean如下:xmlTemplateParameter做为顶级对象放在body里面,Freemarker里取数据的body.peopleList就对应于xmlTemplateParameter.peopleListpublicclassFmProcessorBean{ publicvoidprepareFMValues(Exchangeexchange){ XMLTemplateParameterxmlTemplateParameter=newXMLTemplateParameter(); ValueObjectval=null; for(inti=0;i<3;i++){ val=newValueObject(); val.setFname("Yao"); val.setGname("Yorker"+i); val.setEmail("test@mail.com"); val.setManager("m&an com.test.camel.freemarker f:启动Spring,在D:tempoutbox文件夹下,每隔10秒钟,会根据freemarker模板生成一个fm.xml文件. ApplicationContextac=newClassPathXmlApplicationContext("config/camelFreemarker.xml"); while(true){ Thread.sleep(2000); }对本例beanRef("fmBean","prepareFMValues")的解释:其意思是调用fmBean的prepareFMValues方法,Camel会负责将message的body绑定到要调用方法的第一个参数上面,其中可能做相应的类型转换.(本例中的方法的第一个参数为Exchange,没有转换的过程),这里给一个如下示例图解释这个绑定转换的过程:Camel将Exchange的的inputmessage(exchange.getIn())转换为String,绑定到mtd方法的name参数上.4.下面是一个路由选择的例子publicclassEIP{/***@param*@return*@方法描述*@authorCaiWen*@throwsException*@createTime2014-11-19*@接口名*/publicstaticvoidmain(String[]args)throwsException{ConnectionFactoryconn=newActiveMQConnectionFactory("vm://localhost");CamelContextcontext=newDefaultCamelContext();context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(conn));context.addRoutes(newRouteBuilder(){publicvoidconfigure(){from("file:d:/temp/inbox?noop=true").to("jms:incomingOrders");from("jms:incomingOrders").choice().when(header("CamelFileName").endsWith(".xml")).to("jms:xmlOrders").when(header("CamelFileName").endsWith(".csv")).to("jms:csvOrders");from("jms:csvOrders").process(newProcessor(){@Overridepublicvoidprocess(Exchangearg0)throwsException{System.out.println("Recivexmlorder:"+arg0.getIn().getHeader("CamelFileName"));InputStreamis=arg0.getIn().getBody(InputStream.class);BufferedReaderbr=newBufferedReader(newInputStreamReader(is));Stringstr=br.readLine();while(str!=null){System.out.println(str);str=br.readLine();}}});from("jms:xmlOrders").process(newProcessor(){@Overridepublicvoidprocess(Exchangearg0)throwsException{System.out.println("Recivexmlorder:"+arg0.getIn().getHeader("CamelFileName"));}});}});context.start();booleanloop=true;while(loop){Thread.sleep(9000);}context.stop();}}5.附加pom.xml4.0.0org.apache.camelexamples2.14.0camel-example-activemq-tomcatCamel::Example::ActiveMQ::TomcatAnexampleusingActiveMQBrokerandCamelwithApacheTomcatwarorg.codehaus.mojotomcat-maven-pluginmyTomcat${tomcat.url}/${project.build.finalName}org.codehaus.mojoexec-maven-pluginorg.apache.camel.example.cxf.CamelRouteClientfalsejava.util.logging.config.filelogging.propertiescamel-example-activemq-tomcatorg.apache.camelcamel-coreorg.apache.camelcamel-springorg.apache.camelcamel-streamorg.springframeworkspring-weborg.apache.camelcamel-jmsorg.apache.activemqactivemq-camelorg.apache.activemqactivemq-brokerorg.apache.activemqactivemq-springorg.apache.activemqactivemq-kahadb-storeorg.apache.activemqactivemq-clientorg.apache.activemqactivemq-poolorg.apache.xbeanxbean-springorg.apache.camelcamel-quartzorg.apache.camelcamel-httporg.apache.camelcamel-freemarkerlog4jlog4jorg.slf4jslf4j-log4j12Tomcat7truehttp://localhost:8080/manager/textTomcat6http://localhost:8080/manager二.应用场景及项目应用 EnterpriseApplicationIntegration企业应用集成(EAI) 企业应用集成是必要的,几乎每家公司都有很多新产品及应用,如何集成这些应用程序是一个问题。来每十年诞生一个新范式,例如客户端/服务器通信,面向服务的架构(SOA)或云计算(http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http://www.jdon.com/soa/when-to-use-apache-camel.html&p=baidu&c=news&n=10&t=tpclicked3_hc&q=banq_cpr&k=%D4%C6%BC%C6%CB%E3&k0=%B1%E0%B3%CC&kdi0=8&k1=%C2%E6%CD%D5&kdi1=8&k2=java&kdi2=8&k3=%D4%C6%BC%C6%CB%E3&kdi3=8&k4=%B1%E0%B3%CC%D3%EF%D1%D4&kdi4=8&sid=f9fa801534a41137&ch=0&tu=u1683405&jk=eafa96a8022d0c32&cf=29&fv=15&stid=9&urlid=0&luki=4&seller_id=1&di=128"\t"http://www.jdon.com/soa/_blank)。 此外,不同的接口或
协议
离婚协议模板下载合伙人协议 下载渠道分销协议免费下载敬业协议下载授课协议下载
和技术的出现。过去数据存储在文件,SQL数据库在今天很通用。有时,还需要NoSQL数据库。同步远程过程调用RPC或异步消息是通过如RMI,SOAP的Web服务,REST或JMS进行通信的。很多软件筒仓还存在。EnterpriseIntegrationPatterns企业集成模式(EIP) 当然,你可以推倒重来,然后再写一些意大利面条代码,让应用程序协同工作。不幸的是,你的管理者不会喜欢这个缺少长远眼光的解决
方案
气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载
。 企业集成模式(www.eaipatterns.com)帮助碎片的问题,并使用标准化的方法来集成应用程序。使用相同的概念路由消息来改造。因此,每次有问题时重新发明轮子不是个好主意。集成的替代方案解决方案1:自定义解决方案实现一个单独的解决方案,适用于您的问题还没有分离切成碎片。此工程可能是最快的替代的小型用例。你必须自己编写所有。维护成本可能会高,特别是如果团队成员改变。解决方案2:集成框架使用这类框架有助于将多个集成模式集成在一个标准化的方式。它减少了损耗。每个开发人员会很容易明白你做了什么(如果他知道所使用的架构)。解决方案3:企业服务总线(ESB)应用企业服务总线在您的应用程序集成中。ESB还有更多的功能,如业务流程管理,注册表或业务活动监控。通常,您可以在图形用户界面配置路由实现这些功能-通常情况下,一个ESB是一个复杂的产品。学习曲线要高得多。但是提供您一个非常强大的工具。三.性能分析及应用价值ApacheCamel是什么? ApacheCamel是一个轻量级的集成框架,它实现了所有EIP。因此,您可以使用EIP所需的图案容易地集成不同的应用。您可以使用Java,Spring的XML,scala或Groovy。几乎每一个技术,你可以想像是可用的,例如HTTP,FTP,JMS,EJB,JPA,RMI,JMS,JMX,LDAP的Netty,和很多很多(当然大多数ESB还提供了对他们的支持)。此外,自定义的组件可以很容易地被创建。 您可以部署Apache的骆驼(http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http://www.jdon.com/soa/when-to-use-apache-camel.html&p=baidu&c=news&n=10&t=tpclicked3_hc&q=banq_cpr&k=%C2%E6%CD%D5&k0=%B1%E0%B3%CC&kdi0=8&k1=%C2%E6%CD%D5&kdi1=8&k2=java&kdi2=8&k3=%D4%C6%BC%C6%CB%E3&kdi3=8&k4=%B1%E0%B3%CC%D3%EF%D1%D4&kdi4=8&sid=f9fa801534a41137&ch=0&tu=u1683405&jk=eafa96a8022d0c32&cf=29&fv=15&stid=9&urlid=0&luki=2&seller_id=1&di=128"\t"http://www.jdon.com/soa/_blank)作为独立的应用程序,在Web容器(如Tomcat或Jetty),在JEE应用服务器(如JBoss应用服务器或WebSphereAS),在OSGi环境或与Spring容器组合。什么时候使用Camel 如果你想多个应用程序使用不同的协议和技术集成,ApacheCamel是真棒。除了支持如此多的技术和除了支持不同的编程语言(http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http://www.jdon.com/soa/when-to-use-apache-camel.html&p=baidu&c=news&n=10&t=tpclicked3_hc&q=banq_cpr&k=%B1%E0%B3%CC%D3%EF%D1%D4&k0=%B1%E0%B3%CC&kdi0=8&k1=%C2%E6%CD%D5&kdi1=8&k2=java&kdi2=8&k3=%D4%C6%BC%C6%CB%E3&kdi3=8&k4=%B1%E0%B3%CC%D3%EF%D1%D4&kdi4=8&sid=f9fa801534a41137&ch=0&tu=u1683405&jk=eafa96a8022d0c32&cf=29&fv=15&stid=9&urlid=0&luki=5&seller_id=1&di=128"\t"http://www.jdon.com/soa/_blank),每个集成使用EIP下的相同概念!无论您使用何种协议。无论您使用什么技术。无论您使用何种领域特定语言(DSL)-它可以通过Java,Scala,Groovy的或Spring的XML。做同样的方式。永远!(有一个生产者,消费者,端点endpoint,有EIP概念,有定制处理器参数(如凭据)。比如使用JavaDSL表达如下:from(„activeMQ:orderQueue“)..transaction().log(„processingorder“).to(mock:“notYetExistingInterface“)使用ScalaDSL:„file:incomingOrders?noop=true“process(newTransformationProcessor)to„jdbc:orderDatastore“另外两个非常重要的特点是对错误处理(例如使用死信队列)和自动测试的支持。什么时候不使用Camel 在自己的定制集成,集成框架,企业服务总线这三种方案中不使用Camel,难易程度如下: 如果你要整合一个或两个技术,如读取某个文件或发送JMS消息,使用一些众所周知的库可能是更容易和更快,如ApacheCommonsIO或SpringJmsTemplate的。但是,请不要总是使用这些helper类,纯文件或try-catch捕捉代码错误的JMS集成是SOOOO难看的! FuseSource虽然提供商业支持,我不会使用Apache骆驼在非常大的集成项目中。ESB是在大多数情况下,正确的工具选择。它提供了许多额外的功能,如BPM或BAM。当然,你也可以使用多个单框架或产品和“创造”自己的ESB,但是这是在浪费时间和金钱。 通常情况下,开放源代码解决方案相比商业产品如WebSphereMessageBroker更轻量级(你安装此产品的试用版可能需要一两天)!著名的开源ESB有Apache的ServiceMix的,骡子ESB和WSO2ESB。顺便说一句:你知道基于ApacheCamel框架基础上一些ESB?(如Apache的服务组合和TalendESB)。因此,如果你喜欢Apache的骆驼(http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http://www.jdon.com/soa/when-to-use-apache-camel.html&p=baidu&c=news&n=10&t=tpclicked3_hc&q=banq_cpr&k=%C2%E6%CD%D5&k0=%B1%E0%B3%CC&kdi0=8&k1=%C2%E6%CD%D5&kdi1=8&k2=java&kdi2=8&k3=%D4%C6%BC%C6%CB%E3&kdi3=8&k4=%B1%E0%B3%CC%D3%EF%D1%D4&kdi4=8&sid=f9fa801534a41137&ch=0&tu=u1683405&jk=eafa96a8022d0c32&cf=29&fv=15&stid=9&urlid=0&luki=2&seller_id=1&di=128"\t"http://www.jdon.com/soa/_blank),你也可以使用ApacheServiceMix这样的ESB。(注:可编辑下载,若有不当之处,请指正,谢谢!)推荐精选推荐精选推荐精选