Pub/Sub w/Multiple Subscribers
-
sexta-feira, 13 de abril de 2012 16:13
I’m having problems getting the message to multiple subscribers, the message comes into whatever client picks it up first. Basically, I have a Kiosk that when updated I want to notify everyone running our management center application that something has occurred on the Kiosk. Can anyone point me to a sample or tell me what I’m doing wrong?
Thanks for any assistance.
private void CreateTopic()
{
var managementUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceBusNamespace, string.Empty);
_namespaceManager = new NamespaceManager(managementUri, TokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerKey));
var topicDescription = new TopicDescription(_topicPath)
{
DefaultMessageTimeToLive = TimeSpan.FromMinutes(15),
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10),
EnableBatchedOperations = true,
RequiresDuplicateDetection = true
};
if (_namespaceManager.TopicExists(topicDescription.Path))
{
_namespaceManager.DeleteTopic(topicDescription.Path);
}
_namespaceManager.CreateTopic(topicDescription);
SubDescription = _namespaceManager.CreateSubscription(_topicPath, "Kiosk");
}
private void Subscription()
{var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerKey);
var uri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceBusNamespace, string.Empty);
var messagingFactory = MessagingFactory.Create(uri, tokenProvider);
var subscriptionClient = messagingFactory.CreateSubscriptionClient(_topicPath, "Kiosk");
while (true)
{var message = subscriptionClient.Receive();
if (message != null)
{var data = message.GetBody<string>();
WriteText(data);//message.Complete();
}}}private void SendBrokeredMessage(string messageText)
{var runtimeUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceBusNamespace, string.Empty);
var messagingFactory = MessagingFactory.Create(runtimeUri, TokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerKey));
var topicClient = messagingFactory.CreateTopicClient(_topicPath);
if (!String.IsNullOrEmpty(messageText))
{var data = messageText;
var message = new BrokeredMessage(data);
message.Properties.Add(CategoryPropName, messageText);message.MessageId = "m_" + DateTime.Now.ToLongTimeString();
try
{topicClient.Send(message);txbMessage.Text = string.Empty;
}catch (Exception ex)
{WriteText(ex.Message);}}else
{txbMessage.Text = "Please enter a message!";
}}Brian K. Williams
Todas as Respostas
-
sexta-feira, 13 de abril de 2012 17:00
It appears that you have a single subscription, such that all the subscribers are competing for the same message. Each subscriber needs a separate unique subscription to get all the messages.
You can create separate subscriptions by suffixing the “Kiosk” with a unique identifier and later deleting the subscription when it is no longer needed.
- Editado Lucifure sexta-feira, 13 de abril de 2012 21:45
- Sugerido como Resposta Alan Smith MVPMVP segunda-feira, 16 de abril de 2012 19:15
- Marcado como Resposta Arwind - MSFTModerator quinta-feira, 19 de abril de 2012 07:13
-
segunda-feira, 16 de abril de 2012 19:14
Hi,
I have a sample on my blog were I route messages to multiple subscribers.
http://geekswithblogs.net/asmith/archive/2012/04/16/149332.aspx
Regards,
Alan
http://www.CloudCasts.net - Community Webcasts Powered by Azure
- Marcado como Resposta Arwind - MSFTModerator quinta-feira, 19 de abril de 2012 07:13
-
sexta-feira, 20 de abril de 2012 04:28
Thanks for the help works perfect now, I was thinking it was more like SQL Subscriptions.
Azure ServiceBus is awesome…
Brian K. Williams
-
segunda-feira, 23 de abril de 2012 20:14
Hey Alan…
Thanks for the help again..
Now that everything is working great with WPF client, I need to do the same with a Silverlight 5 application. Can you point me to a sample that explains the best way to accomplish this?
Thanks
-Brian

