Apache camel,RabbitMQ如何发送消息/对象 [英] Apache camel,RabbitMQ how to send messages/objects
问题描述
我希望有人可以在此问题上提供一些帮助.
I hope someone can provide some help on this matter.
我正在使用骆驼Rabbitmq,出于测试目的,我试图将消息发送到队列,并尝试在Rabbitmq界面中显示该消息,然后再将其读回.
I am using camel rabbitmq and for testing purpose I am trying to send a message to the queue, which I'm trying to display in rabbitmq interface and then also read it back.
但是我无法正常工作.
However I can't get this working.
我认为有效的是,我在rabbitmq管理界面的交换选项卡中创建了一个新交换. 在我的Java代码中,我将消息发送到该交易所.执行代码后,我可以在Web界面中看到一个尖峰,表明已经收到了一些东西,但是看不到收到了什么. 当我尝试阅读时,我无法阅读并得到以下错误: <在路由中:Route(route2)[[From [rabbitmq://192.168.59.103:5672/rt ...因为路由route2没有输出处理器.您需要将输出添加到路由,例如to("log:foo").
What I believe works is that I created, in the exchange tab of rabbitmq management interface, a new exchange. In my java code I send the message to that exchange. When the code is executed, I can see a spike in the web interface showing that something has been received but I can't see what has been received. When I try to read, I can't read and get the following errror: < in route: Route(route2)[[From[rabbitmq://192.168.59.103:5672/rt... because of Route route2 has no output processors. You need to add outputs to the route such as to("log:foo").
有人可以给我提供有关如何发送消息,在网络界面中查看消息并阅读消息的实际示例吗?任何显示此过程的教程也将不胜感激.
Can someone provide me a practical example on how to send a message,see it in the web interace and also read it? any tutorial showing this process will be also appreciated.
谢谢
================= 第二部分
================= SECOND PART
我现在遇到的错误如下:
The error I'm getting now is the following:
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - cannot redeclare exchange 'rhSearchExchange' in vhost '/' with different type, durable, internal or autodelete value, class-id=40, method-id=10), null, ""}
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
... 47 more
我有以下设置:
我收到此错误,我认为URI做错了,我必须定义一些我遗漏的额外参数 我的交易是直接交易 我的队列是耐用型 我的uri是: rabbitmq://192.168.59.105:5672/rhSearchExchange?username = guest& password = guest& routingKey = rhSearchQueue
I get this error, I believe I’m doing something wrong with the URI and I have to define some extra parameters that I’m missing My exchange is of direct type My queue is of durable type And my uri is : rabbitmq://192.168.59.105:5672/rhSearchExchange?username=guest&password=guest&routingKey=rhSearchQueue
对此有何投入?
谢谢
推荐答案
所以我昨天能够弄清楚这一点,我遇到了相同(或至少相似)的问题.
So I was able to figure this out yesterday, I had the same (or at least similar) problems you were having.
RabbitMQ URI中的选项必须与创建交换所使用的选项完全匹配.例如,在我的配置中,我有一个名为tasks
的交换,该交换是直接类型的,具有持久性,并且未配置为自动删除.请注意,rabbitmq骆驼组件中autodelete选项的默认值为true
.另外,我想使用路由键camel
来获取消息.这意味着我的Rabbitmq URI必须看起来像:
The options you have in the RabbitMQ URI must exactly match the options that your exchange was created with. For example, in my configuration, I had an exchange called tasks
that was a direct type, was durable, and was not configured to autodelete. Note that the default value for the autodelete option in the rabbitmq camel component is true
. Additionally, I wanted to get the messages with the routing key camel
. That means my rabbitmq URI needed to look like:
rabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel
此外,我想从一个名为task_queue
的现有队列中读取数据,而不是让Rabbitmq骆驼组件声明它自己的队列.因此,我还需要添加一个附加的查询参数,所以我的Rabbitmq URI是
Additionally, I wanted to read from an existing queue, called task_queue
rather than have the rabbitmq camel component declare it's own queue. Therefore, I also needed to add an additional query parameter, so my rabbitmq URI was
rabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel&queue=task_queue
此配置对我有用.在下面,我从配置交换和队列并发送消息的代码以及我的Camel Route配置中添加了一些Java代码片段.
This configuration worked for me. Below, I added some Java code snippets from the code that configures the exchange and queue and sends a message, and my Camel Route configuration.
rabbitConnFactory = new ConnectionFactory();
rabbitConnFactory.setHost("localhost");
final Connection conn = rabbitConnFactory.newConnection();
final Channel channel = conn.createChannel();
// declare a direct, durable, non autodelete exchange named 'tasks'
channel.exchangeDeclare("tasks", "direct", true);
// declare a durable, non exclusive, non autodelete queue named 'task_queue'
channel.queueDeclare("task_queue", true, false, false, null);
// bind 'task_queue' to the 'tasks' exchange with the routing key 'camel'
channel.queueBind("task_queue", "tasks", "camel");
发送消息:
channel.basicPublish("tasks", "camel", MessageProperties.PERSISTENT_TEXT_PLAIN, "hello, world!".getBytes());
骆驼路线:
@Override
public void configure() throws Exception {
from("rabbitmq:localhost:5672/tasks?username=guest&password=guest&autoDelete=false&routingKey=camel&queue=task_queue")
.to("mock:result");
}
我希望这会有所帮助!
这篇关于Apache camel,RabbitMQ如何发送消息/对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!