apache camel 与 rabbitmq集成

qq_34350475 2019-04-26 05:23:53
我想实现一个功能,在做完数据库操作后,将操作内容作为消息发送到rabbitmq队列中去。
学习了一下Apache camel ,不是很懂,要如何在数据库操作以后启动camel来发送消息,网上查找资料有代码的方式和xml配置两种方式,

from("").to("rabbitmq://localhost:5672/myexchange?username=guest&password=guest&queue=userQueue")


<bean id="customConnectionFactory" class="com.rabbitmq.client.ConnectionFactory">
<property name="host" value="xx.xx.xx.xx" />
<property name="port" value="5672"/>
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="/"/>
<to uri="rabbitmq://xx.xx.xx.xx:5672/myexchange?connectionFactory=#customConnectionFactory"/>
</route>
</camelContext>

这里的from中应该怎么调用?

如果是xml配置的方式,我要如何使它跟随spring一起启动,我已经添加了camel.xml文件并关联,但是好像不生效
...全文
625 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_34350475 2019-05-07
  • 打赏
  • 举报
回复
代码的方式将消息传入direct组件

CamelContext context = new DefaultCamelContext();
ProducerTemplate producerTemplate = context.createProducerTemplate();
context.addRoutes(new RouteBuilder() {
	@Override
	public void configure() throws Exception {
		from("direct:hello").to("rabbitmq://xxx");
				}	        	
	        });
	        
 context.start(); 
String message = "";
producerTemplate.sendBody("direct:hello",message);

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧