static void SendMessages(QueueClient requestClient, QueueClient responseClient)
        {
            // Send request messages to queue:
            Console.WriteLine("Sending request messages to queue {0}", requestClient.Path);
            Console.WriteLine("Receiving response messages on queue {0}", responseClient.Path);

            MessageSession receiver = responseClient.AcceptMessageSession(ReplyToSessionId);

            for (int i = 0; i < SampleManager.NumMessages; ++i)
            {
                // send request message
                BrokeredMessage message = CreateRequestMessage(i);
                requestClient.Send(message);
                SampleManager.OutputMessageInfo("REQUEST: ", message);

                // receive response message
                BrokeredMessage receivedMessage = receiver.Receive(TimeSpan.FromSeconds(ResponseMessageTimeout));
                if (receivedMessage != null)
                {
                    SampleManager.OutputMessageInfo("RESPONSE: ", message);
                    receivedMessage.Complete();
                }
                else
                {
                    Console.WriteLine("ERROR: Response timed out.");
                }
            }
            receiver.Close();

            Console.WriteLine();
        }
        static void SendMessages(TopicClient topicClient, SubscriptionClient responseClient)
        {
            // Send request messages to queue:
            Console.WriteLine("Sending request messages to topic {0}", topicClient.Path);
            Console.WriteLine("Receiving response messages on subscription {0}", responseClient.Name);


            MessageSession session = responseClient.AcceptMessageSession(ClientId);

            for (int i = 0; i < SampleManager.NumMessages; ++i)
            {
                // send request message
                BrokeredMessage message = new BrokeredMessage
                {
                    ReplyToSessionId = ClientId,
                    MessageId        = i.ToString(),
                    CorrelationId    = SampleManager.RequestSubName
                };

                topicClient.Send(message);
                SampleManager.OutputMessageInfo("REQUEST: ", message);

                // start asynchronous receive operation
                //TODO: Fix
                //session.ReceiveAsync ( TimeSpan.FromSeconds(ResponseMessageTimeout), ProcessResponse, session);

                var brokeredMessage = session.Receive(TimeSpan.FromSeconds(ResponseMessageTimeout));

                ProcessResponse(brokeredMessage);
            }


            Console.WriteLine();
        }
Example #3
0
        static void ProcessResponse(IAsyncResult result)
        {
            MessageSession  session = result.AsyncState as MessageSession;
            BrokeredMessage message = session.EndReceive(result);

            if (message == null)
            {
                Console.WriteLine("ERROR: Message Receive Timeout.");
            }
            else
            {
                SampleManager.OutputMessageInfo("RESPONSE: ", message);
            }
        }
        static void ReceiveMessages(QueueClient requestClient, QueueClient responseClient)
        {
            // Read messages from queue until queue is empty:
            Console.WriteLine("Reading messages from queue {0}", requestClient.Path);

            BrokeredMessage request = requestClient.Receive(TimeSpan.FromSeconds(ReceiveMessageTimeout));

            while (request != null)
            {
                SampleManager.OutputMessageInfo("REQUEST: ", request);

                BrokeredMessage response = new BrokeredMessage();
                response.SessionId = request.ReplyToSessionId;
                response.MessageId = request.MessageId;
                responseClient.Send(response);
                request = requestClient.Receive(TimeSpan.FromSeconds(ReceiveMessageTimeout));
            }
        }
        static void ReceiveMessages(TopicClient topicClient, SubscriptionClient requestClient)
        {
            // Read all the messages from subscription:
            BrokeredMessage request;

            while ((request = requestClient.Receive(TimeSpan.FromSeconds(ReceiveMessageTimeout))) != null)
            {
                SampleManager.OutputMessageInfo("REQUEST: ", request);

                BrokeredMessage response = new BrokeredMessage
                {
                    SessionId     = request.ReplyToSessionId,
                    MessageId     = request.MessageId,
                    CorrelationId = SampleManager.ResponseSubName
                };

                topicClient.Send(response);
                SampleManager.OutputMessageInfo("RESPONSE: ", response);
            }
        }