gpt4 book ai didi

AppFabric 主题订阅

转载 作者:行者123 更新时间:2023-12-04 06:21:37 25 4
gpt4 key购买 nike

我正在尝试组装一个简单的 AppFabric 主题,其中使用 SessionId 发送和接收消息。代码不会中止,但 brokeredMessage 始终为空。这是代码:

// BTW, the topic already exists

var messagingFactory = MessagingFactory.Create(uri, credentials);
var topicClient = messagingFactory.CreateTopicClient(topicName);
var sender = topicClient.CreateSender();
var message = BrokeredMessage.CreateMessage("Top of the day!");
message.SessionId = "1";
sender.Send(message);

var subscription = topic.AddSubscription("1", new SubscriptionDescription { RequiresSession = true});
var mikeSubscriptionClient = messagingFactory.CreateSubscriptionClient(subscription);
var receiver = mikeSubscriptionClient.AcceptSessionReceiver("1");
BrokeredMessage brokeredMessage;
receiver.TryReceive(TimeSpan.FromMinutes(1), out brokeredMessage); // brokeredMessage always null

最佳答案

您的代码中有两个问题:

  • 您创建订阅 你发送消息。您需要在发送之前创建订阅,因为订阅告诉主题在某种意义上将消息复制到几个不同的“存储桶”。
  • 您正在使用 TryReceive 但没有检查其结果。如果收到消息,则返回 true,否则返回 false(例如发生超时)。

  • 我正在编写我的示例应用程序,今天将其发布在我们的博客上。我也会在这里发布链接。但在那之前,将订阅逻辑移到发送消息之前,然后将接收者移到之后,您将开始看到结果。

    更新:
    正如所 promise 的,这是我在 getting started with AppFabric Queues, Topics, Subscriptions. 上的博客文章的链接。

    关于AppFabric 主题订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6485623/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com