Silverlight Client, multiple subscriptions, stops receiving messages.

Mar 8, 2011 at 5:06 PM
Edited Mar 8, 2011 at 5:10 PM

Hi there,

I have a scenario where clients need to subcribe to multiple topics.
I am using the silverlight client and minimizeConnectionUse is set to true, sometimes the clients stop receiving the messages.
If I set minimizeConnectionUse to false, it is working as expected.
I tried to replicate this with a test but can't get a consistent behavior,
in firefox it seems to work every 3-4 times but in ie it works every 10 times. I am using the latest change set (aefc91ad70cf).
I am not sure if it is something similar which was reported as issue #12.

Thanks, Aybars

Here is the test:


        public void SubscribeTwoPublishToBoth()
            int lobbyTopicId = -1;
            int clientMessagesTopicId = -1;
            PubsubClient server = new PubsubClient(this.baseAddress);
            PubsubClient client = new PubsubClient(this.baseAddress);
            //the test passes when minimizeConnectionUse is false
            //PubsubClient client = new PubsubClient(this.baseAddress, false);
            List<string> clientReceivedMessages = new List<string>();
            Action<PubsubMessage> clientMessageHandler = (m) => clientReceivedMessages.Add(m.GetBodyAsString());
            List<Exception> exceptionsOccured = new List<Exception>();

            //server creates a topic at startup
            server.CreateTopicAsync((topicId)=>lobbyTopicId = topicId, exceptionsOccured.Add);
            this.EnqueueConditionalWithTimeout(() => (lobbyTopicId > 0 && exceptionsOccured.Count == 0));

            int callBackConditionCounter = 0;
                Assert.IsTrue(exceptionsOccured.Count == 0, "There's been an error while creating the topic.");
                Assert.IsTrue(lobbyTopicId > 0, "Lobby Topic not created.");
                //client starts up and asks the server the topic Id and subscribes to that topic
                client.SubscribeAsync(lobbyTopicId, (s, m) => clientMessageHandler(m), (s, e) => exceptionsOccured.Add(e));
                //after the client connects to the server, the server publishes a message to the lobby topic id saying, a new client is connected
                //so, any client subscribed to the lobby topic is notified
                server.PublishAsync(lobbyTopicId, "1", (m) => ++callBackConditionCounter, (s, e) => exceptionsOccured.Add(e));
                //also the server creates a topic specific for the client (used for private messages to the client)
                server.CreateTopicAsync(delegate(int topicId) { clientMessagesTopicId = topicId; }, (e) => exceptionsOccured.Add(e));
            this.EnqueueConditionalWithTimeout(() => (clientMessagesTopicId > 0 && callBackConditionCounter == 1));

                Assert.IsTrue(exceptionsOccured.Count == 0, "There's been an error.1.");
                Assert.IsTrue(callBackConditionCounter == 1, "Not all pub/sub operations are completed.1.");
                Assert.IsTrue(clientMessagesTopicId > 0, "Client topic not created.1.");

                callBackConditionCounter = 0;
                //client makes a service call and gets its topic id and subscribes to it
                client.SubscribeAsync(clientMessagesTopicId, (s, m) => clientMessageHandler(m), (s, e) => exceptionsOccured.Add(e));
                //another client connects and the server publishes a message to the lobby notifying the other clients.
                server.PublishAsync(lobbyTopicId, "1", (m) => ++callBackConditionCounter, (s, e) => exceptionsOccured.Add(e));
                //the second client sends a message to the first client
                server.PublishAsync(clientMessagesTopicId, "1", (m) => ++callBackConditionCounter, (s, e) => exceptionsOccured.Add(e));
                //and then another one
                server.PublishAsync(clientMessagesTopicId, "1", (m) => ++callBackConditionCounter, (s, e) => exceptionsOccured.Add(e));
            this.EnqueueConditionalWithTimeout(()=> callBackConditionCounter==3);
            //make sure client receives all messages
            this.EnqueueConditionalWithTimeout(() => clientReceivedMessages.Count == 4);

                Assert.IsTrue(exceptionsOccured.Count == 0, "There's been an error.2.");
                Assert.IsTrue(callBackConditionCounter == 3, "Not all pub/sub operations are completed.2.");
                Assert.IsTrue(clientReceivedMessages.Count == 4, "Client didn't receive all messages =>" + string.Join(",", clientReceivedMessages));


//Test Result: Assert.IsTrue failed. Client didn't receive all messages => 1,1