osgi9——camel动态路由
来源:互联网 发布:设计餐厅菜单软件 编辑:程序博客网 时间:2024/05/16 08:53
1.camel路由uri都是静态的,一般容器启动的时候,它会去预执行。但是有些时候需要动态的去执行一些uri,好比mq,mq有exchange和queue,这两项有些时候是动态的办法,用普通的配置是不行的,所以我们解决的时候就需要动态路由
请看下面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"xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"xmlns:cxfcore="http://cxf.apache.org/blueprint/core"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://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.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="yyc.com.MQ"update-strategy="reload"><cm:default-properties><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: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="dynamicRouter" class="yyc.com.camel.DynamicRouter"><property name="host" value="${RabbitMQ.host}" /><property name="port" value="${RabbitMQ.port}" /></bean><camelContext id="RabbitmqCamelContext"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"><!--动态的发送mq --><route><from uri="direct-vm:toRabbitmq" /><dynamicRouter><method ref="dynamicRouter" method="dynamicToRabbitmq" /></dynamicRouter></route></camelContext></blueprint>yyc.com.camel.DynamicRouter 实现
import java.util.Map;import org.apache.camel.Headers;import org.apache.camel.Properties;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * * @author yyc */public class DynamicRouter { private static final Logger log = LoggerFactory.getLogger(DynamicRouter.class); private String host; private String port; public String dynamicToRabbitmq(@Headers Map<String, Object> headers, @Properties Map<String, Object> properties) { int invoked = 0; Object current = properties.get("invoked"); if (current != null) { invoked = Integer.valueOf(current.toString()); } invoked++; properties.put("invoked", invoked); log.info("调用动态的mq:"+properties); if (invoked == 1 && properties.get("queue")!=null && properties.get("exchange")!=null) { String queue = (String) properties.get("queue"); String exchange = (String) properties.get("exchange"); String routingKey = (String) properties.get("routingKey"); String result = "rabbitmq://"+host+":"+port+"/"+exchange+"?connectionFactory=#customConnectionFactory&durable=true&autoDelete=false&exchangeType=topic&queue=" + queue + "&routingKey=" + routingKey; log.info("发送mq到"+exchange); return result; } return null; } public void setHost(String host) { this.host = host; } public void setPort(String port) { this.port = port; } }
这样的话就能实现动态的发送mq消息
0 0
- osgi9——camel动态路由
- Apache Camel添加动态路由
- Camel路由构建过程
- Camel添加路由过程
- Camel路由启动过程
- Camel路由启动过程--续
- camel 路由跳转组件使用
- ActiveMQ + Camel 实现消息路由
- ActiveMQ + Camel 实现消息路由
- osgi8——camel activitimq
- vue router学习——动态路由和嵌套路由
- Apache Camel框架之FTP路由
- Apache Camel框架之JMS路由
- Apache Camel框架之HTTP路由
- ServiceMix - [Quickstart]3.通过Camel路由
- Apache Camel框架之FTP路由
- Apache Camel框架之JMS路由
- Apache Camel框架之HTTP路由
- 数据库ORA-01033错误解决办法
- Codeforces Round #330 (Div. 2) 595AB题解
- url中的中文传参乱码问题
- 使用Drawble文件实现圆角,填充颜色,边框等属性的设置(Android)
- 科目二 不通过 反思
- osgi9——camel动态路由
- 维度模型数据仓库(十) —— 快照
- 流式大数据处理的三种框架:Storm,Spark和Samza
- Delphi怎么判断一个文件存在与否,文件还是文件夹?
- openwrt uci的使用
- Swoole-真正的PHP Web开发框架
- CYC- OC中@protected等关键字概述
- LeetCode Add Two Numbers
- sessionstage和localstage的应用实例