none
Pub/Sub w/Multiple Subscribers RRS feed

  • Question

  • 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

    Friday, April 13, 2012 4:13 PM

Answers

  • 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.

    Friday, April 13, 2012 5:00 PM
  • 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

    • Marked as answer by Arwind - MSFT Thursday, April 19, 2012 7:13 AM
    Monday, April 16, 2012 7:14 PM

All replies

  • 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.

    Friday, April 13, 2012 5:00 PM
  • 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

    • Marked as answer by Arwind - MSFT Thursday, April 19, 2012 7:13 AM
    Monday, April 16, 2012 7:14 PM
  • Thanks for the help works perfect now, I was thinking it was more like SQL Subscriptions.

    Azure ServiceBus is awesome…


    Brian K. Williams

    Friday, April 20, 2012 4:28 AM
  • 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

    Monday, April 23, 2012 8:14 PM