示例#1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();
            Console.WriteLine();

            var messageTxt = "";
            // Some message are issued by the constructor on the sender
            var sender = new RabbitSender();


            while (true)
            {
                Console.WriteLine("Enter the message to be sent");
                messageTxt = Console.ReadLine();
                if (messageTxt == "exit")
                {
                    break;
                }
                sender.Send(messageTxt);
                Console.WriteLine("Message has been sent");
            }

            //Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var sender = new RabbitSender();

            Console.WriteLine("Select a number & Press enter key to send a message");
            foreach (var routing in routingDictionary)
            {
                Console.WriteLine($"{routing.Key} = {routing.Value}");
            }


            while (true)
            {
                var input = Console.ReadLine();

                if (input.ToUpper() == "Q")
                {
                    break;
                }
                if (input.ToUpper() != "1" && input.ToUpper() == "2" && input.ToUpper() == "3")
                {
                    continue;
                }

                var routingKey = routingDictionary[input];
                Console.WriteLine($"Sending - {routingKey}");
                sender.Send(routingKey, routingKey);
            }

            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    var message = $"Message: {messageCount}";
                    Console.WriteLine("Sending - {0}", message);
                    sender.Send(message);
                    messageCount++;
                }
            }

            Console.ReadLine();
        }
示例#4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();
            Console.WriteLine();

            var    messageCount = 0;
            string routingKey;
            var    sender = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");
            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    //Used to generate a random routing key so server 1,2 or no one will get the message
                    routingKey = new Random().Next(0, 4).ToString(CultureInfo.InvariantCulture);

                    var message = string.Format("Message: {0} - Routing Key: {1}", messageCount, routingKey);
                    Console.WriteLine("Sending - {0}", message);

                    sender.Send(message, routingKey);
                    messageCount++;
                }
            }

            Console.ReadLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Enter the time delay & Press enter key to send a message");

            while (true)
            {
                var input = Console.ReadLine();
                int delay;

                if (input.ToUpper() == "Q")
                {
                    break;
                }
                if (!int.TryParse(input, out delay))
                {
                    continue;
                }

                var message = $"Message: {messageCount}";
                Console.WriteLine("Sending - {0}", message);
                sender.Send(message, input);
                messageCount++;
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key != ConsoleKey.Enter)
                {
                    continue;
                }
                var message = $"Message: {messageCount}";
                Console.WriteLine("Sending - {0}", message);

                var response = sender.Send(message, new TimeSpan(0, 0, 3, 0));

                Console.WriteLine("Response - {0}", response);
                messageCount++;
            }

            Console.ReadLine();
        }
示例#7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    // Read File
                    Console.WriteLine($"Reading file - {InputFile}");
                    byte[] messageBuffer = File.ReadAllBytes(InputFile);

                    // Send Message
                    Console.WriteLine($"Sending large message - {messageBuffer.Length}");
                    sender.Send(messageBuffer);
                    messageCount++;
                    Console.WriteLine("Message sent");
                }
            }

            Console.ReadLine();
        }
示例#8
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Inicializando Publicador de mensajes RabbitMQ");
            Console.WriteLine();
            Console.WriteLine();

            var messageCount = 0;
            var menssageText = "";
            var sender       = new RabbitSender();

            Console.WriteLine("Presione enter para enviar un mensaje");
            while (true)
            {
                var key = Console.ReadKey();

                menssageText += key.KeyChar;

                if (key.Key == ConsoleKey.Enter)
                {
                    var message = $"Mensaje: {messageCount} - {menssageText}";
                    Console.WriteLine($"Enviando - {message}");
                    sender.Send(message);
                    messageCount++;
                    menssageText = "";
                }
            }

            Console.ReadLine();
        }
示例#9
0
        private static void Main(string[] args)
        {

            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();
            Console.WriteLine();            

            var messageTxt = "";
            // Some message are issued by the constructor on the sender
            var sender = new RabbitSender();

            
            while (true)
            {
                Console.WriteLine("Enter the message to be sent");
                messageTxt = Console.ReadLine();
                if (messageTxt == "exit")
                {
                    break;
                }
                sender.Send(messageTxt);
                Console.WriteLine("Message has been sent");
            }
            
            //Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            SetUp();
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");
            Console.WriteLine("Choose Number from below for the appropriate Routing Key:");
            foreach (var routingKey in routeDictionary)
            {
                Console.WriteLine($"{routingKey.Key} = {routingKey.Value}");
            }

            while (true)
            {
                var number = Console.ReadLine();

                if (number.ToUpper() == "Q") break;

                Console.WriteLine($"Key : {number}");
                if (string.IsNullOrEmpty(number) || !routeDictionary.ContainsKey(number)) continue;

                var routingKey = routeDictionary[number];

                var message = $"Message: {messageCount}";
                Console.WriteLine($"Sending - {message}. Routing Key - {routingKey}");
                sender.Send(message, routingKey);
                messageCount++;
            }

            Console.ReadLine();
        }
示例#11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    var messageObj = new Message {
                        MyMessage = $"Message: {messageCount}"
                    };
                    Console.WriteLine("Sending - {0}", messageObj.MyMessage);

                    var jsonString    = Newtonsoft.Json.JsonConvert.SerializeObject(messageObj);
                    var messageBuffer = Encoding.Default.GetBytes(jsonString);
                    sender.Send(messageBuffer);
                    messageCount++;
                }
            }

            Console.ReadLine();
        }
示例#12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    var routingKey = new Random().Next(0, 4).ToString(CultureInfo.InvariantCulture);

                    var message = $"Message: {messageCount}";
                    Console.WriteLine($"Sending - {message}. Routing Key - {routingKey}");
                    sender.Send(message, routingKey);
                    messageCount++;
                }
            }

            Console.ReadLine();
        }
示例#13
0
        static void Main(string[] args)
        {
            RabbitSender sender = new RabbitSender();

            sender.Connect();
            sender.SendMessages();

            Console.WriteLine("Quitting...");
            sender.Disconnect();
        }
示例#14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Enter a number 1-6 and press Enter");
            int messageNumber = 1;

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                ProcessKeyStroke(ref messageNumber, ref key);

                if (key.Key == ConsoleKey.Enter)
                {
                    if (messageNumber == 0)
                    {
                        Console.WriteLine("Enter a number 1-6 and press Enter");
                    }
                    else
                    {
                        var message = string.Format($"Message ID: {messageNumber}");
                        Console.WriteLine($"Sending - {message}");

                        var responses = sender.Send(message, messageNumber.ToString(),
                                                    new TimeSpan(0, 0, 0, 30), 0);

                        Console.WriteLine();
                        Console.WriteLine($"{responses.Count} replies received");
                        Console.WriteLine();
                        Console.WriteLine("Listing Responses:");
                        foreach (var response in responses)
                        {
                            Console.WriteLine($"Response - {response}");
                        }

                        Console.WriteLine();
                        Console.WriteLine("Enter a number 1-6 and press Enter");
                        messageCount++;
                    }
                }
            }
        }
示例#15
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();
            Console.WriteLine();

            var messageCount = 0;
            var sender       = new RabbitSender();

            Console.WriteLine("Enter a number 1-6 then press enter key to send a message");
            int messageNumber = 0;

            while (true)
            {
                var key = Console.ReadKey();


                ProcessKeyStroke(ref messageNumber, ref key);

                if (key.Key == ConsoleKey.Enter)
                {
                    if (messageNumber == 0)
                    {
                        Console.WriteLine("Please supply a number from 1 - 6 and press enter");
                    }
                    else
                    {
                        var message = string.Format("Message ID: {0}", messageNumber);
                        Console.WriteLine("Sending - {0}", message);

                        var responses = sender.Send(message, messageNumber.ToString(CultureInfo.InvariantCulture), new TimeSpan(0, 1, 0, 3), 2);

                        Console.WriteLine();
                        Console.WriteLine("{0} replies recieved", responses.Count);
                        Console.WriteLine();
                        Console.WriteLine("Listing responses");
                        foreach (var response in responses)
                        {
                            Console.WriteLine("Response - {0}", response);
                        }

                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Please supply a number from 1 - 6 and press enter");
                        messageCount++;
                    }
                }
            }

            Console.ReadLine();
        }
示例#16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");
            Console.WriteLine("Select the number for the Format and press Enter");
            Console.WriteLine("1 = JSON");
            Console.WriteLine("2 = XML");
            Console.WriteLine("3 = Binary");
            Console.WriteLine();

            while (true)
            {
                var number = Console.ReadLine();

                if (number.ToUpper() == "Q")
                {
                    break;
                }

                var format = number;
                if (format != "1" && format != "2" && format != "3")
                {
                    continue;
                }

                var messageObj = new Message {
                    MyMessage = $"Message: {messageCount}"
                };

                var messageBuffer = SerializeMessage(messageObj, format);

                Console.WriteLine($"Foramt - {format}, Sending - {messageObj}");
                sender.Send(messageBuffer, GetContentType(format));
                messageCount++;
            }

            Console.ReadLine();
        }
示例#17
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var sender = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var input = Console.ReadLine();

                if (input.ToUpper() == "Q")
                {
                    break;
                }
                Console.WriteLine($"Sending - {input}");
                sender.Send(input);
            }

            Console.ReadLine();
        }
示例#18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var sender = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    var    outputFileName = $"{Guid.NewGuid()}";
                    var    fileStream     = File.OpenRead(InputFile);
                    var    streamReader   = new StreamReader(fileStream);
                    int    remaining      = (int)fileStream.Length;
                    int    length         = (int)fileStream.Length;
                    var    messageCount   = 0;
                    var    endOfSequence  = false;
                    byte[] buffer;

                    while (true)
                    {
                        if (remaining <= 0)
                        {
                            break;
                        }

                        int read = 0;
                        if (remaining > ChunkSize)
                        {
                            buffer = new byte[ChunkSize];
                            read   = fileStream.Read(buffer, 0, ChunkSize);
                        }
                        else
                        {
                            buffer        = new byte[remaining];
                            read          = fileStream.Read(buffer, 0, remaining);
                            endOfSequence = true;
                        }

                        // Send Message
                        Console.WriteLine($"Sending chunk message - Index = {messageCount}; " +
                                          $"Length =  {length}");
                        sender.Send(buffer, outputFileName, messageCount, endOfSequence);

                        messageCount++;
                        remaining = remaining - read;
                    }
                    Console.WriteLine($"Completed sending {messageCount} chunks");
                }
            }

            Console.ReadLine();
        }
示例#19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var messageCount = 1;
            var sender       = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");
            Console.WriteLine("Select the number for the Format - number of Message Type, and press Enter");
            Console.WriteLine("1 = JSON");
            Console.WriteLine("2 = XML");
            Console.WriteLine("3 = Binary");
            Console.WriteLine();
            Console.WriteLine("1 = FirstMessage");
            Console.WriteLine("2 = SecondMessage");
            Console.WriteLine();

            while (true)
            {
                var input = Console.ReadLine();

                if (input.ToUpper() == "Q")
                {
                    break;
                }
                if (!input.Contains("-"))
                {
                    continue;
                }

                var data        = input.Split('-');
                var format      = data[0];
                var messageType = data[1];

                if (format != "1" && format != "2" && format != "3")
                {
                    continue;
                }
                if (messageType != "1" && messageType != "2")
                {
                    continue;
                }


                object messageObj = null;
                if (messageType == "1")
                {
                    messageObj = new FirstMessage {
                        Message = $"Message: {messageCount}"
                    }
                }
                ;
                else
                {
                    messageObj = new SecondMessage {
                        Message = $"Message: {messageCount}"
                    }
                };

                var messageBuffer = SerializeMessage(messageObj, format);

                Console.WriteLine($"Foramt - {format}, Sending - {messageObj}");
                sender.Send(messageBuffer, GetContentType(format), GetMessageType(messageObj));
                messageCount++;
            }

            Console.ReadLine();
        }
示例#20
0
        static void Main(string[] args)
        {
            Setup();
            Console.WriteLine("Starting RabbitMQ Message Sender");
            Console.WriteLine();

            var sender = new RabbitSender();

            Console.WriteLine("Press enter key to send a message");
            Console.WriteLine("Format to enter: {#material} - {#customertype}");

            Console.WriteLine("Materials:");
            foreach (var material in materialDictionary)
            {
                Console.WriteLine($"{material.Key} = {material.Value}");
            }

            Console.WriteLine();
            Console.WriteLine("Customer Type:");
            foreach (var customerType in customerTypeDictionary)
            {
                Console.WriteLine($"{customerType.Key} = {customerType.Value}");
            }

            while (true)
            {
                var input = Console.ReadLine();

                if (input.ToUpper() == "Q")
                {
                    break;
                }
                if (!input.Contains('-'))
                {
                    continue;
                }

                var inputData        = input.Split('-');
                var materialCode     = inputData[0].Trim();
                var customerTypeCode = inputData[1].Trim();

                if (!materialDictionary.ContainsKey(materialCode) ||
                    !customerTypeDictionary.ContainsKey(customerTypeCode))
                {
                    Console.WriteLine("Invalid Input");
                    continue;
                }

                var material     = materialDictionary[materialCode];
                var customerType = customerTypeDictionary[customerTypeCode];
                Console.WriteLine($"Materail : {material}, Customer Type: {customerType}");

                var headers = new Dictionary <string, string>
                {
                    { "material", material },
                    { "customerType", customerType }
                };

                var message = $"Message: {messageCount}";
                sender.Send(message, headers);
                messageCount++;
            }

            Console.ReadLine();
        }