Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            _messageTransformer = new MessageTransformer();
            _loanQuoteRequests  = new ConcurrentDictionary <long, LoanQuoteRequest>();
            _bankQuoteReplies   = new ConcurrentDictionary <long, List <BankQuoteReply> >();
            Console.WriteLine("Loan Broker application started.");

            using (var messageGateway = new MessageGateway("host=localhost;timeout=60"))
            {
                messageGateway.Receive <LoanQuoteRequest>("loan.broker.customer.request", HandleLoanQuoteRequest);
                messageGateway.Receive <BankQuoteReply>("loan.broker.bank.reply", HandleBankQuoteReply);


                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Listening on customer request queue.");
                Console.WriteLine("Listening on bank reply queue.");
                Console.ResetColor();
                ConsoleKeyInfo key;
                do
                {
                    Console.WriteLine("Press ESC to exit application.");
                    key = Console.ReadKey(true);
                } while (key.Key != ConsoleKey.Escape);
            }
        }
        public void TestReceiveObject()
        {
            //IMessageReceiverGateway gateway = new MessageReceiverGateway("");
            //object result = gateway.ReceiveObject();

            MessageGateway<string> gateway = new MessageGateway<string>("boomerang");
            gateway.Send("abel");
            string response = gateway.Receive(10000);

            Assert.IsNotNull(response);
            Assert.IsNotEmpty(response);

            Console.WriteLine(response);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Customer application started.");
            var cts = new CancellationTokenSource();

            try
            {
                _messageGateway = new MessageGateway("host=localhost;timeout=60");
                _messageGateway.Receive <LoanQuoteReply>(CustomerAppId, HandleQuoteReply);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Started Listening for Loan Quote Replies.");
                Console.ResetColor();

                ConsoleKeyInfo key;
                do
                {
                    Console.WriteLine("Press: 'S' to send two test messages, ESC to exit application.");
                    key = Console.ReadKey(true);

                    if (key.Key != ConsoleKey.S)
                    {
                        continue;
                    }

                    Task.Factory.StartNew(() =>
                    {
                        var loanQuoteRequest = new LoanQuoteRequest()
                        {
                            CprNr        = 1909991111,
                            LoanAmount   = 10000,
                            LoanTerm     = 46,
                            ReplyQueueId = CustomerAppId
                        };
                        cts.Token.ThrowIfCancellationRequested();
                        _messageGateway.Send(loanQuoteRequest, "loan.broker.customer.request");
                        Console.WriteLine($"Loan Request Sent for {loanQuoteRequest.CprNr}");
                    }, cts.Token);

                    Task.Factory.StartNew(() =>
                    {
                        var loanQuoteRequest = new LoanQuoteRequest()
                        {
                            CprNr        = 1909992222,
                            LoanAmount   = 5000,
                            LoanTerm     = 12,
                            ReplyQueueId = CustomerAppId
                        };
                        cts.Token.ThrowIfCancellationRequested();
                        _messageGateway.Send(loanQuoteRequest, "loan.broker.customer.request");
                        Console.WriteLine($"Loan Request Sent for {loanQuoteRequest.CprNr}");
                    }, cts.Token);
                } while (key.Key != ConsoleKey.Escape);

                cts.Cancel();
            }
            catch (AggregateException e)
            {
                foreach (var ie in e.InnerExceptions)
                {
                    PrintErrorToConsole($"{ie.GetType().Name}: {ie.Message}");
                }
            }
            catch (Exception ex)
            {
                PrintErrorToConsole(ex.Message);
            }
            finally
            {
                cts.Cancel();
                _messageGateway.Dispose();
            }
        }
        public void TestSendReceiveCustomType()
        {
            MessageGateway<MockMessage> gateway = new MessageGateway<MockMessage>(Destination);
            gateway.Send(new MockMessage("Custom Type Test"));
            MockMessage response = gateway.Receive();

            Assert.IsNotNull(response);
            Assert.IsNotEmpty(response.Name);

            Console.WriteLine(response.Name);
        }
        public void TestSendReceiveXmlDocument()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<?xml version=\"1.0\"?><Message><Test>Xml Document Test</Test></Message>");

            MessageGateway<XmlDocument> gateway = new MessageGateway<XmlDocument>(Destination);
            gateway.Send(xml);
            XmlDocument response = gateway.Receive();

            Assert.IsNotNull(response);
            Assert.IsNotEmpty(response.OuterXml);

            Console.WriteLine(response.OuterXml);
        }
        public void TestSendReceiveString()
        {
            MessageGateway<string> gateway = new MessageGateway<string>(Destination);
            gateway.Send("String Message Test");
            string response = gateway.Receive();

            Assert.IsNotNull(response);
            Assert.IsNotEmpty(response);

            Console.WriteLine(response);
        }
        public void TestSendReceiveObject()
        {
            MessageGateway<object> gateway = new MessageGateway<object>(Destination);
            gateway.Send("Object Message Test");
            object response = gateway.Receive();

            Assert.IsNotNull(response);

            Console.WriteLine(response);
        }