ActiveMQ - 将消息发送到使用字符串指定的临时队列(C# 中的 NMS)

发布于 2024-10-12 16:22:03 字数 1452 浏览 1 评论 0原文

我的系统中有一个同步消息事务,该过程大致遵循以下流程:

  1. “A 点”在消息代理上创建一个临时队列(“目的地 2”);
  2. 消息从A点发送到目的地1(消息代理上的普通队列),ReplyTo地址设置为目的地2;
  3. A点阻塞等待目的地2的响应;
  4. B点收到目的地1的消息;
  5. 点 B 创建一个工作对象 - 其属性是目标 2 的名称(使用 .ToString()" 派生”。该工作对象被序列化并存储在 DB 中;

...

  1. 当满足某些参数时从 DB 检索对象,发生变化,并且响应被发送到目的地 2 - 使用 SessionUtil 从存储为工作对象的字符串属性的回复地址派生一个新的 IDestination 对象;
  2. “点 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:

  1. "Point A" creates a temporary queue ("destination 2") on the message broker;
  2. Message sent from point A to destination 1 (a normal queue on the message broker), with the ReplyTo address set as destination 2;
  3. point A blocks waiting for response on destination 2;
  4. point B receives message from destination 1;
  5. 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;

...

  1. 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;
  2. "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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

树深时见影 2024-10-19 16:22:03

临时目的地就是临时的。一旦创建临时目标的连接对象关闭,目标就会自动从代理中删除。因此,存储临时目标以供以后使用并不是一个好主意。此外,仅允许创建临时目标的连接使用它。

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.

夏天碎花小短裙 2024-10-19 16:22:03

我确实注意到,如果代理配置为不使用“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文