Beispiel #1
0
        public void Reqest_Resonse()
        {
            using (var sender = MessageQueueFactory.CreateOutbound("ff", MessagePattern.RequestResponse))
                using (var receiver = MessageQueueFactory.CreateInbound("ff", MessagePattern.RequestResponse))
                {
                    var responseQueue = sender.GetResponseQueue();

                    var outgoingMessage = new Message
                    {
                        Body = new[] { "how are you?" },
                        ResponseAddressName = responseQueue.MessageAddress.Address
                    };
                    sender.Send(outgoingMessage);



                    var responseMessage = new Message
                    {
                        Body = new[] { "I am fine, thank you." }
                    };
                    receiver.Receive(incomingMessage =>
                    {
                        var replyQueue = receiver.GetReplyQueue(incomingMessage);
                        replyQueue.Send(responseMessage);
                    });



                    string result = string.Empty;
                    responseQueue.Receive(incomingMessage => result = incomingMessage.BodyAs <string[]>()[0]);

                    result.Should().Be("I am fine, thank you.");
                }
        }
        public override IMessageQueue GetReplyQueue(Message message)
        {
            var replyQueue = MessageQueueFactory.CreateOutbound(message.ResponseAddress, MessagePattern.RequestResponse,
                                                                true);

            return(replyQueue);
        }
Beispiel #3
0
        public void Fire_And_Forget_Async()
        {
            using (var sender = MessageQueueFactory.CreateOutbound("ffasync", MessagePattern.FireAndForget))
                using (var receiver = MessageQueueFactory.CreateInbound("ffasync", MessagePattern.FireAndForget))
                {
                    var outgoingMessage = new Message
                    {
                        Body = new[] { "hello world" }
                    };

                    sender.Send(outgoingMessage);

                    var    cancellationTokenSource = new CancellationTokenSource(2000);
                    var    cancellationToken       = cancellationTokenSource.Token;
                    string result = string.Empty;

                    var task = receiver.Listen(incomingMessage =>
                    {
                        result = incomingMessage.BodyAs <string[]>()[0];
                    },
                                               cancellationToken);
                    task.Wait();
                    cancellationTokenSource.Cancel();

                    result.Should().Be("hello world");
                    Trace.WriteLine(result);
                }
        }
Beispiel #4
0
        public void Pusblish_Subscribe()
        {
            using (var publisher = MessageQueueFactory.CreateOutbound("topic", MessagePattern.PublishSubscribe))
                using (var subscriber1 = MessageQueueFactory.CreateInbound("subscription1", MessagePattern.PublishSubscribe))
                    using (var subscriber2 = MessageQueueFactory.CreateInbound("subscription2", MessagePattern.PublishSubscribe))
                        using (var subscriber3 = MessageQueueFactory.CreateInbound("subscription3", MessagePattern.PublishSubscribe))
                        {
                            var outgoingMessage = new Message
                            {
                                Body = new[] { "hello world" }
                            };

                            publisher.Send(outgoingMessage);


                            string result1, result2, result3;
                            result1 = result2 = result3 = string.Empty;

                            subscriber1.Receive(incomingMessage => result1 = incomingMessage.BodyAs <string[]>()[0]);
                            subscriber2.Receive(incomingMessage => result2 = incomingMessage.BodyAs <string[]>()[0]);
                            subscriber3.Receive(incomingMessage => result3 = incomingMessage.BodyAs <string[]>()[0]);

                            result1.Should().Be("hello world");
                            result2.Should().Be("hello world");
                            result3.Should().Be("hello world");
                        }
        }
        public virtual IMessageQueue GetReplyQueue(Message message)
        {
            if (!(Pattern == MessagePattern.RequestResponse && Direction == Direction.Inbound))
            {
                throw new InvalidOperationException("Cannot get a reply queue except for inbound request-response");
            }

            return(MessageQueueFactory.CreateOutbound(message.ResponseAddressName, MessagePattern.RequestResponse, true, this));
        }
Beispiel #6
0
        public override IMessageQueue GetReplyQueue(Message message)
        {
            if (!(Pattern == MessagePattern.RequestResponse && Direction == Direction.Inbound))
            {
                throw new InvalidOperationException("Cannot get a reply queue except for inbound request-response");
            }

            var responseQueue = MessageQueueFactory.CreateOutbound(message.ResponseAddress, MessagePattern.RequestResponse, true);

            return(responseQueue);
        }
        private static void StartUnsubscribe(string emailAddress)
        {
            var unsubscribeCommand = new UnsubscribeCommand
            {
                EmailAddress = emailAddress
            };
            var queue = MessageQueueFactory.CreateOutbound("unsubscribe", MessagePattern.FireAndForget);

            queue.Send(new Message
            {
                Body = unsubscribeCommand
            });
        }
Beispiel #8
0
        private void SendNotificationEvent()
        {
            var unsubscribedEvent = new UserUnsubscribed
            {
                EmailAddress = EmailAddress
            };
            var queue = MessageQueueFactory.CreateOutbound("unsubscribed-event", MessagePattern.PublishSubscribe);

            queue.Send(new Message
            {
                Body = unsubscribedEvent
            });
        }
Beispiel #9
0
        public void Fire_And_Forget()
        {
            using (var sender = MessageQueueFactory.CreateOutbound("ff", MessagePattern.FireAndForget))
                using (var receiver = MessageQueueFactory.CreateInbound("ff", MessagePattern.FireAndForget))
                {
                    var outgoingMessage = new Message
                    {
                        Body = new[] { "hello world" }
                    };
                    sender.Send(outgoingMessage);


                    string result = string.Empty;
                    receiver.Receive(incomingMessage => result = incomingMessage.BodyAs <string[]>()[0]);

                    result.Should().Be("hello world");
                }
        }
Beispiel #10
0
        private bool DoesUserExist(string emailAddress)
        {
            var exists = false;

            var doesUserExistRequest = new DoesUserExistRequest
            {
                EmailAddress = emailAddress
            };

            var queue         = MessageQueueFactory.CreateOutbound("doesuserexist", MessagePattern.RequestResponse);
            var responseQueue = queue.GetResponseQueue();

            queue.Send(new Message
            {
                Body            = doesUserExistRequest,
                ResponseAddress = responseQueue.Address
            });
            responseQueue.Receive(x => exists = x.BodyAs <DoesUserExistResponse>().Exists);

            return(exists);
        }