AppFabric主题订阅

时间:2011-06-26 17:45:55

标签: appfabric azure-appfabric

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

// 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 个答案:

答案 0 :(得分:3)

您的代码中存在两个问题:

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

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

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

    <强>更新 正如所承诺的,这是getting started with AppFabric Queues, Topics, Subscriptions.

    上我的博客文章的链接
相关问题