Пример #1
0
        public async Task Run(
            string namespaceAddress,
            string basicQueueName,
            string basicQueue2Name,
            string sendKeyName,
            string sendKey,
            string receiveKeyName,
            string receiveKey)
        {
            var senderFactory = MessagingFactory.Create(
                namespaceAddress,
                new MessagingFactorySettings
            {
                TransportType = TransportType.Amqp,
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKey)
            });

            var receiverFactory = MessagingFactory.Create(
                namespaceAddress,
                new MessagingFactorySettings
            {
                TransportType = TransportType.Amqp,
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(receiveKeyName, receiveKey)
            });

            var sender   = senderFactory.CreateMessageSender(basicQueueName);
            var receiver = receiverFactory.CreateMessageReceiver(basicQueue2Name);
            var rr       = new RequestReplySender(sender, receiver);

            var replyTokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKey);
            var replyTo            = new Uri(new Uri(namespaceAddress), basicQueue2Name);

            for (int i = 0; i < 10; i++)
            {
                await rr.Request(
                    new BrokeredMessage
                {
                    Label      = "requestA",
                    TimeToLive = TimeSpan.FromMinutes(5),
                    MessageId  = Guid.NewGuid().ToString(),
                    ReplyTo    = await FormatReplyTo(replyTo, replyTokenProvider)
                },
                    TimeSpan.FromMinutes(1),
                    async m =>
                {
                    await Console.Out.WriteLineAsync(string.Format("{0}, {1}", m.CorrelationId, m.Label));
                    return(true);
                });
            }

            // All messages sent
            Console.WriteLine("\nClient complete.");
            Console.ReadLine();
        }
        public async Task Run(
            string namespaceAddress,
            string basicQueueName,
            string basicQueue2Name,
            string sendKeyName,
            string sendKey,
            string receiveKeyName,
            string receiveKey)
        {
            var senderFactory = MessagingFactory.Create(
                namespaceAddress,
                new MessagingFactorySettings
                {
                    TransportType = TransportType.Amqp,
                    TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKey)
                });
            
            var receiverFactory = MessagingFactory.Create(
                namespaceAddress,
                new MessagingFactorySettings
                {
                    TransportType = TransportType.Amqp,
                    TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(receiveKeyName, receiveKey)
                });
            
            var sender = senderFactory.CreateMessageSender(basicQueueName);
            var receiver = receiverFactory.CreateMessageReceiver(basicQueue2Name);
            var rr = new RequestReplySender(sender, receiver);

            var replyTokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKey);
            var replyTo = new Uri(new Uri(namespaceAddress), basicQueue2Name);

            for (int i = 0; i < 10; i++)
            {
                await rr.Request(
                    new BrokeredMessage
                    {
                        Label = "requestA",
                        TimeToLive = TimeSpan.FromMinutes(5),
                        MessageId = Guid.NewGuid().ToString(),
                        ReplyTo = await FormatReplyTo(replyTo, replyTokenProvider)
                    },
                    TimeSpan.FromMinutes(1),
                    async m =>
                    {
                        await Console.Out.WriteLineAsync(string.Format("{0}, {1}", m.CorrelationId, m.Label));
                        return true;
                    });
            }

            // All messages sent
            Console.WriteLine("\nClient complete.");
            Console.ReadLine();
        }