Following the MS documentation it was not tough to obtain message(s) from subscription. Nevertheless, if I would like my utility to obtain a message each time new message is posted – a continuing polling. Therefore the OnMessage() methodology of the SubscriptionClient class.

MS documentation says:…When calling OnMessage, the consumer begins an inner message pump that always polls the queue or subscription. This message pump consists of an infinite loop that points a Obtain() name. If the decision occasions out, it points the subsequent Obtain() name. …

However when the applying is operating, the second OnMessage() methodology is known as solely newest message(s) is acquired. When new messages are posted the fixed polling doesn’t appear to be working. After attempting many various approaches the one means I might make this work and have the applying react the second new message is acquired is to put the code right into a separate activity with infinite loop. This appears completely incorrect on so many ranges! (see code under).

Can anybody assist me to right my code or submit a working pattern to perform the identical performance with out the loop? Thanks!

 public void ReceiveMessageFromSubscription(string topicName, string subscriptionFilter)
            var newMessage = new MessageQueue();
            int i = 0;

            Process listener = Process.Manufacturing unit.StartNew(() =>
                whereas (true)
                    SubscriptionClient Consumer = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionFilter);

                    Dictionary retrievedMessage = new Dictionary();

                    OnMessageOptions choices = new OnMessageOptions();
                                     choices.AutoComplete = false;
                                     choices.AutoRenewTimeout = TimeSpan.FromMinutes(1);

                    Consumer.OnMessage((message) =>
                            retrievedMessage.Add("messageGuid", message.Properties["MessageGuid"].ToString());
                            retrievedMessage.Add("instanceId", message.Properties["InstanceId"].ToString());
                            retrievedMessage.Add("pId", message.Properties["ProcessId"].ToString());
                            retrievedMessage.Add("processKey", message.Properties["ProcessKey"].ToString());
                            retrievedMessage.Add("message", message.Properties["Message"].ToString());

                            newMessage.AnnounceNewMessage(retrievedMessage); // occasion ->

                            message.Full(); // Take away message from subscription.
                        catch (Exception ex)
                            string exmes = ex.Message;

                    }, choices);





Leave a Reply

Your email address will not be published. Required fields are marked *