Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            // create the bus
            var bus = new EasyQAmqp("localhost", "5672", "guest", "guest");
            // respond to requests
            await bus.HandleRequest <SecondRequest, SecondResponse>(async request =>
            {
                System.Console.WriteLine($"Request recieve = {request.MessageSecondRequest} Time {DateTime.Now}");

                await Task.Delay(2000);

                System.Console.WriteLine($"Recieving");

                System.Console.WriteLine("Publish start");
                await bus.Publish(new EventMessage
                {
                    Text = "Event Message!" + request.MessageSecondRequest
                }, Exchange.WithMultipleSubscribing);
                System.Console.WriteLine("Publish end");
                return(new SecondResponse {
                    MessageSecondResponse = request.MessageSecondRequest + " Add response"
                });
            });


            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            // create the bus
            var bus = new EasyQAmqp("localhost", "5672", "guest", "guest");
            // respond to requests
            await bus.HandleRequest <FirstRequest, FirstResponse>(async request =>
            {
                System.Console.WriteLine($"Request recieve = {request.MessageFirst} Time {DateTime.Now}");

                await Task.Delay(2000);

                var requestMicr = new SecondRequest();
                requestMicr.MessageSecondRequest = request.MessageFirst + "'Request from First Microservice'";


                System.Console.WriteLine($"Recieving");
                var responseTask = bus.SendRequest <SecondRequest, SecondResponse>(requestMicr);


                await responseTask.ContinueWith((resp) =>
                {
                    System.Console.WriteLine($"Response back = {resp.Result.MessageSecondResponse} Time = {DateTime.Now}");
                });

                request.MessageFirst += responseTask.Result.MessageSecondResponse;
                return(new FirstResponse {
                    MessageFirstResponse = request.MessageFirst + " Response From Microservice First"
                });
            });

            Console.ReadLine();
            //bus. Dispose();
        }