ActiveMQ - 将消息发送到使用字符串指定的临时队列(C# 中的 NMS)
我的系统中有一个同步消息事务,该过程大致遵循以下流程:
- “A 点”在消息代理上创建一个临时队列(“目的地 2”);
- 消息从A点发送到目的地1(消息代理上的普通队列),ReplyTo地址设置为目的地2;
- A点阻塞等待目的地2的响应;
- B点收到目的地1的消息;
- 点 B 创建一个工作对象 - 其属性是目标 2 的名称(使用 .ToString()" 派生”。该工作对象被序列化并存储在 DB 中;
...
- 当满足某些参数时从 DB 检索对象,发生变化,并且响应被发送到目的地 2 - 使用 SessionUtil 从存储为工作对象的字符串属性的回复地址派生一个新的 IDestination 对象;
- “点 A”从目的地 2 接收消息并继续
该过程 。
需要使用返回目标的名称(目标 2),而不是完整的 IDestination 对象,因为我必须序列化该对象并存储在数据库中
。我 永久队列或主题作为目标 2,该过程工作正常,但是,尝试使用临时队列的字符串名称创建它时总是失败。
没有错误,消息无法到达
?
。有什么想法吗 显示的发送返回消息的代码:(
IDestination myDestination = SessionUtil.GetDestination(stateSession, instance.ReplyTo, DestinationType.Queue);
stateConnection.Start();
using (IMessageProducer myProducer = stateSession.CreateProducer(myDestination))
{
myProducer.DeliveryMode = MsgDeliveryMode.NonPersistent;
var response = myProducer.CreateTextMessage();
response.NMSCorrelationID = instance.CorrelationID;
response.Properties["RoutingDestination"] = instance.RoutingOriginator;
response.Text = "Test Response";
try
{
myProducerBroadcast.Send(response);
myProducer.Send(response);
Log.InfoFormat("Sent response {0} to {1}", instance.UniqueId, instance.ReplyTo);
}
catch (Exception ex)
{
Log.Error("Unable to send execution update onwards", ex);
}
}
“实例”是工作对象 - 其中包含 ReplyTo 地址和其他信息)
I have a synchronous message transaction within my system, and the process broadly follows this flow:
- "Point A" creates a temporary queue ("destination 2") on the message broker;
- Message sent from point A to destination 1 (a normal queue on the message broker), with the ReplyTo address set as destination 2;
- point A blocks waiting for response on destination 2;
- point B receives message from destination 1;
- point B creates a work object - a property of which is the name of destination 2 (derived using .ToString()". This work object is serialized and stored in the DB;
...
- Object retrieved from DB when certain parameters are met, changes ocurr, and a response is sent to destination 2 - using SessionUtil to derive a new IDestination object from the replyto address stored as a string property of the work object;
- "Point A" recieves message from destination 2 and continues on.
This process can take anything from a split second to several seconds to accomplish.
I need to use the name of the return destination (destination 2), rather than the full IDestination object, as I have to serialize the object and store in the DB.
If I use a permanent queue or a topic as destination 2, the process works fine. However, it always fails when attempting to create it using the string name of the temporary queue.
There are no errors, the message just fails to arrive
Any ideas why?
Example code for sending return message shown:
IDestination myDestination = SessionUtil.GetDestination(stateSession, instance.ReplyTo, DestinationType.Queue);
stateConnection.Start();
using (IMessageProducer myProducer = stateSession.CreateProducer(myDestination))
{
myProducer.DeliveryMode = MsgDeliveryMode.NonPersistent;
var response = myProducer.CreateTextMessage();
response.NMSCorrelationID = instance.CorrelationID;
response.Properties["RoutingDestination"] = instance.RoutingOriginator;
response.Text = "Test Response";
try
{
myProducerBroadcast.Send(response);
myProducer.Send(response);
Log.InfoFormat("Sent response {0} to {1}", instance.UniqueId, instance.ReplyTo);
}
catch (Exception ex)
{
Log.Error("Unable to send execution update onwards", ex);
}
}
("instance" is the work object - which contains the ReplyTo address and other information)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
临时目的地就是临时的。一旦创建临时目标的连接对象关闭,目标就会自动从代理中删除。因此,存储临时目标以供以后使用并不是一个好主意。此外,仅允许创建临时目标的连接使用它。
A temporary destination is just that, temporary. Once the Connection object that created the Temporary Destination closes, the destination is automatically removed from the broker. Storing the temp destination for later use is not a good idea for this reason. Also, only the Connection that created the temp destination is allowed to consume on it.
我确实注意到,如果代理配置为不使用“advisorySupport”,临时队列将不起作用
重新启用该功能后,队列就可以为我工作了。
I did notice temp queues don't work if the broker is configured to not use "advisorySupport"
Reenabling that got the queues to work for me.