Example #1
0
        public void StartReceiving()
        {
            var factory = new ConnectionFactory()
            {
                HostName = Properties.Settings.Default.HostName, UserName = Properties.Settings.Default.UserName, Password = Properties.Settings.Default.Password
            };

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: Properties.Settings.Default.Queue,
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var body    = ea.Body;
                        var message = Encoding.ASCII.GetString(body);

                        Console.WriteLine("Получил: {0}", message);
                        if (Received != null)
                        {
                            Received(message);
                        }
                        string DecryptMessage = decryption.unscramble(message, rsaCryp.ExportParameters(true));
                        Put.JsonCon(DecryptMessage);

                        Console.WriteLine("Расшифрованные: {0}", DecryptMessage);
                        Console.WriteLine("Данные перемещены");
                    };
                    channel.BasicConsume(queue: Properties.Settings.Default.Queue,
                                         autoAck: true,
                                         consumer: consumer);

                    //Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
            }
        }