コード例 #1
0
        static void Main(string[] args)
        {
            Console.Title = "System A";
            Console.WriteLine("System A. Sending content of the XML file to System B.");

            channel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AToBChannel);

            new Thread(() =>
            {
                SendMessageToSystemB();
                while (keepAutomaticallySendingMessages)
                {
                    var sleepDuration = random.Next(20, 50) * 100;
                    Console.WriteLine($"Waiting {sleepDuration} ms");
                    Thread.Sleep(sleepDuration);
                    SendMessageToSystemB();
                }
                while (Console.ReadLine() != "exit")
                {
                    SendMessageToSystemB();
                }
                Environment.Exit(-1);
            }).Start();

            Console.ReadLine();
        }
コード例 #2
0
        private static void SendMessagesToSubsystemB(string addresss)
        {
            var channel = MessageQueueGenerator.GenerateMessageQueue(addresss);
            var guids   = new string[]
            {
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString()
            };

            for (var i = 0; i < 4; i++)
            {
                var message = new Message()
                {
                    Body = new MessageWithInteger()
                    {
                        Value   = random.Next(1, 50),
                        Guid    = guids[i / 2],
                        ReplyTo = MessageQueueGenerator.BToAChannel
                    }
                };
                Console.WriteLine($"Sending message {i + 1}: {(MessageWithInteger)message.Body}");
                channel.Send(message);
                if (i % 2 == 1)
                {
                    Console.WriteLine($"Id of sent message is {message.Id}\n");
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.Title = "Weather project. Receives queries and returns corresponding datatype.";

            var airTrafficControlCenterInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AirTrafficControlCenter_To_Weather);
            var airTrafficControlCenterOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_AirTrafficControlCenter);

            var airportInformationCenterInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AirportInformationCenter_To_Weather);
            var airportInformationCenterOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_AirportInformationCenter);

            var airlineSASInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_SAS_To_Weather);
            var airlineSASOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_SAS);

            var airlineKLMInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_KLM_To_Weather);
            var airlineKLMOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_KLM);

            var airlineSWAInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_SWA_To_Weather);
            var airlineSWAOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_SWA);

            var airlineBritishAirwaysInput  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_BritishAirways_To_Weather);
            var airlineBritishAirwaysOutput = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_BritishAirways);

            ReceiveInputFromAirTrafficControlCenter(airTrafficControlCenterInput, airTrafficControlCenterOutput);
            ReceiveInputFromAirportInformationCenter(airportInformationCenterInput, airportInformationCenterOutput);
            ReceiveInputFromAirlineSAS(airlineSASInput, airlineSASOutput);
            ReceiveInputFromAirlineKLM(airlineKLMInput, airlineKLMOutput);
            ReceiveInputFromAirlineSWA(airlineSWAInput, airlineSWAOutput);
            ReceiveInputFromAirlineBritishAirways(airlineBritishAirwaysInput, airlineBritishAirwaysOutput);

            while (Console.ReadLine() != "exit")
            {
                Console.WriteLine("Type 'exit' to exit");
            }
        }
コード例 #4
0
        private static void ReceiveMessageFromSubsystemA(MessageQueue channel)
        {
            channel.Formatter         = new XmlMessageFormatter(new Type[] { typeof(string) });
            channel.ReceiveCompleted += (object source, ReceiveCompletedEventArgs asyncResult) =>
            {
                MessageQueue messageQueue  = (MessageQueue)source;
                var          message       = messageQueue.EndReceive(asyncResult.AsyncResult);
                var          returnAddress = (string)message.Body;

                var addressB = MessageQueueGenerator.AToBChannel;
                Console.WriteLine("Received request from Subsytem A");
                Console.WriteLine("Sending response to: " + returnAddress);
                Console.WriteLine("Body of response: " + addressB);

                var returnChannel = MessageQueueGenerator.GenerateMessageQueue(returnAddress);
                returnChannel.Send(new Message()
                {
                    Body          = addressB,
                    CorrelationId = message.Id
                });

                messageQueue.BeginReceive();
            };
            channel.BeginReceive();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.Title = "Subsystem B";

            var messageFromSubsystemAChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AToBChannel);

            ReceiveMessageFromSubsystemA(messageFromSubsystemAChannel);

            Console.ReadLine();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Console.Title = "System E (Receiver)";
            Console.WriteLine("System E (Receiver). Waiting for aggregated messages from System D.");

            inputChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.DToEChannel);

            ReceiveInputFromSystemD();

            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Console.Title = "System B (Splitter)";
            Console.WriteLine("System B (Splitter). Waiting for XML message from System A.");

            inputChannel           = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AToBChannel);
            outputLuggageChannel   = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.BToCChannel);
            outputPassangerChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.BToDChannel);

            ReceiveInputFromSystemA();

            Console.ReadLine();
        }
コード例 #8
0
        private static void RequestAdressFromSubsystemC()
        {
            var channel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AToCChannel);
            // The message queue is solely for retrieving the Address of channel B. So no actual content is needed for the message.
            // Instead we will just set the body to a string containing the Return Address.
            var message = new Message()
            {
                Body = MessageQueueGenerator.CToAChannel
            };

            Console.WriteLine("Requesting the address of Subsystem B through Subsystem C");
            channel.Send(message);
        }
コード例 #9
0
        static void Main(string[] args)
        {
            Console.Title = "Subsystem A";

            var messageFromSubsystemCChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.CToAChannel);
            var messageFromSubsystemBChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.BToAChannel);

            ReceiveMessageFromSubsystemC(messageFromSubsystemCChannel);
            ReceiveMessageFromSubsystemB(messageFromSubsystemBChannel);
            RequestAdressFromSubsystemC();

            Console.ReadLine();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            Console.Title = "Air Traffic Control Center. Receives object.";
            inputChannel  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_AirTrafficControlCenter);
            outputChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.AirTrafficControlCenter_To_Weather);

            ReceiveResponse();

            while (true)
            {
                var query = Console.ReadLine();
                outputChannel.Send(query, query);
            }
        }
        static void Main(string[] args)
        {
            Console.Title = "Airline British Airways. Receives XML document.";
            inputChannel  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_BritishAirways);
            outputChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_BritishAirways_To_Weather);

            ReceiveResponse();

            while (true)
            {
                var query = Console.ReadLine();
                outputChannel.Send(query, query);
            }
        }
コード例 #12
0
        static void Main(string[] args)
        {
            Console.Title = "Airline KLM. Receives text-string.";
            inputChannel  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Weather_To_Airline_KLM);
            outputChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.Airline_KLM_To_Weather);

            ReceiveResponse();

            while (true)
            {
                var query = Console.ReadLine();
                outputChannel.Send(query, query);
            }
        }
コード例 #13
0
        static void Main(string[] args)
        {
            Console.Title = "System C (Resequencer)";
            Console.WriteLine("System C (Resequencer). Waiting for luggage messages from System B.");

            luggageReceived = new Dictionary <string, PackageWrapper <Luggage>[]>();

            inputChannel  = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.BToCChannel);
            outputChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.CToDChannel);

            ReceiveInputFromSystemB();

            Console.ReadLine();
        }
コード例 #14
0
        static void Main(string[] args)
        {
            Console.Title = "System D (Aggregator)";
            Console.WriteLine("System D (Aggregator). Waiting for passenger messages from System B or luggage messages from System C.");

            inputPassengerWithLuggage = new Dictionary <Guid, PassengerWithLuggage>();

            inputPassengerChannel = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.BToDChannel);
            inputLuggageChannel   = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.CToDChannel);
            outputChannel         = MessageQueueGenerator.GenerateMessageQueue(MessageQueueGenerator.DToEChannel);

            ReceiveInputFromSystemB();
            ReceiveInputFromSystemC();

            Console.ReadLine();
        }
コード例 #15
0
        private static void ReceiveMessageFromSubsystemA(MessageQueue channel)
        {
            channel.Formatter         = new XmlMessageFormatter(new Type[] { typeof(MessageWithInteger) });
            channel.ReceiveCompleted += (object source, ReceiveCompletedEventArgs asyncResult) =>
            {
                MessageQueue messageQueue = (MessageQueue)source;
                var          message      = messageQueue.EndReceive(asyncResult.AsyncResult);
                var          body         = (MessageWithInteger)message.Body;

                lock (lockObject)
                {
                    Console.WriteLine("Received integer from Subsytem A " + body);
                    if (savedValues.ContainsKey(body.Guid))
                    {
                        Console.WriteLine("We've received this Guid previously. Calculating sum and sending reply to System A\n");

                        var sum = savedValues[body.Guid] + body.Value;
                        savedValues.Remove(body.Guid);

                        var returnChannel = MessageQueueGenerator.GenerateMessageQueue(body.ReplyTo);
                        returnChannel.Send(new Message()
                        {
                            Body          = sum,
                            CorrelationId = message.Id
                        });
                    }
                    else
                    {
                        Console.WriteLine("This is the first message with this Guid. Saving value in state.");
                        savedValues[body.Guid] = body.Value;
                    }

                    messageQueue.BeginReceive();
                }
            };
            channel.BeginReceive();
        }