AppFabric主题订阅

标签 appfabric azure-appfabric

我正在尝试组装一个简单的 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

最佳答案

您的代码中有两个问题:

  1. 您在发送消息之后创建订阅。您需要在发送之前创建订阅,因为订阅告诉主题在某种意义上将消息复制到几个不同的“存储桶”。

  2. 您正在使用 TryReceive,但没有检查其结果。如果收到消息,则返回 true;如果未收到消息,则返回 false(例如发生超时)。

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

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

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

相关文章:

c# - 如何以编程方式识别 Windows AppFabric 服务是否正在运行?

caching - 估计并发 Azure Appfabric 缓存连接

c# - AppFabric DataCache 按键获取值?

c# - Azure 服务结构 : not accepting normal or portable class libraries

.net - AppFabric 与 System.Runtime.Caching

caching - 在 ASP.NET MVC 中使用 Azure AppFabric 缓存

c# - Azure 服务结构实例计数

azure - ACS 中的 MyOpenID : adding required claim types

azure - 在 Azure 上使用 asp.net session 的推荐方法