osgi7——camel发送rabbitmq
2016-03-21 18:42
253 查看
esb环境下经常需要用时间处理,下面介绍用camel发送rabbitmq。
1.blueprint的配置
2.LoginSendProcessor.java
1.blueprint的配置
<?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:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd" > <cm:property-placeholder persistent-id="con.yyc.rabbitMQ" update-strategy="reload"> <cm:default-properties> <cm:property name="RabbitMQ.password" value="dsfdss23i55423493/fjdsfdsklou545" /> <cm:property name="RabbitMQ.host" value="192.168.1.43" /> <cm:property name="RabbitMQ.port" value="5672"/> <cm:property name="RabbitMQ.username" value="guest" /> <cm:property name="RabbitMQ.password" value="guest" /> <cm:property name="queue_name" value="con.yyc.rabbitMQ.loginlog" /> <cm:property name="exchang_name" value="con.yyc.rabbitMQ.loginlog" /> </cm:default-properties> </cm:property-placeholder> <bean id="customConnectionFactory" class="com.rabbitmq.client.ConnectionFactory"> <property name="host" value="${RabbitMQ.host}"/> <property name="port" value="${RabbitMQ.port}"/> <property name="username" value="${RabbitMQ.username}"/> <property name="password" value="${RabbitMQ.password}"/> </bean> <bean id="LoginSenderBean" class="con.yyc.rabbitMQ.LoginSenderProcessor"> <property name="camelcontext" ref="camel-ssoweb"/> </bean> <camelContext id="camel-ssoweb" xmlns="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <endpoint id="rabbitMQ" uri="rabbitmq://{{RabbitMQ.host}}:{{RabbitMQ.port}}/{{exchang_name}}?queue={{queue_name}}&connectionFactory=#customConnectionFactory&durable=true&autoDelete=false"/> <route> <from uri="vm:_LoginSender" /> <to ref="rabbitMQ" /> </route> </camelContext> </blueprint>
2.LoginSendProcessor.java
package com.yyc.rabbimq; import org.apache.camel.CamelContext; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.ProducerTemplate; import org.slf4j.LoggerFactory; public class LoginSenderProcessor { private static final org.slf4j.Logger log = LoggerFactory.getLogger(LoginSenderProcessor.class); private CamelContext camelcontext; public void setCamelcontext(CamelContext camelcontext) { this.camelcontext = camelcontext; } @EndpointInject(uri = "vm:_LoginSender") private ProducerTemplate producer; @Override public void invoke(String message) { try { Exchange exchg = camelcontext.getEndpoint("vm:_LoginSender").createExchange(); exchg.setPattern(ExchangePattern.InOut); exchg.getIn().setHeader(Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=UTF-8"); exchg.getIn().setBody(message); producer.send(exchg); } catch (Exception e) { log.info("LoginSenderProcessor---invoke:" + e); } } }
相关文章推荐
- osgi8——camel activitimq
- ubuntu 安装qt4
- 电子工程师最关心的10个问题,看完有答案没?
- 编写基于jQuery的插件的方法
- HDU 1509 windows message queue
- osgi6——camel配置学习
- setPluginsEnabled(true) 谁知道android的4.3之后为什么会报错
- 找工作——jvm复习(一)
- Docker安装nginx
- osgi5——camel整合activiti
- [Android4.4.3] Nubia Z5S Mokee4.4.3 RC2.0 by syhost
- activity window 获取setContentView的基视图(getContentView)
- Mastering R plot -1
- treap模版
- Mybatis框架
- osgi4——启动一个servlet
- phpcms调出主栏目下子栏目的内容
- 关于Latch
- Android Support Library
- 如何绕过检测在电脑上观看手机影片