public Publisher(string queueName, IList <Person> persons)
        {
            _rabbitMQService = new RabbitMQService();
            using (IConnection connection = _rabbitMQService.GetRabbitMQConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    channel.QueueDeclare(
                        queue: queueName,
                        durable: false,
                        exclusive: false,
                        autoDelete: false,
                        arguments: null
                        );
                    string jsonMessage = JsonConvert.SerializeObject(persons);
                    byte[] body        = Encoding.UTF8.GetBytes(jsonMessage);

                    channel.BasicPublish(
                        exchange: "",
                        routingKey: queueName,
                        basicProperties: null,
                        body: body
                        );

                    Console.WriteLine("{0} queue'su üzerine mesaj yazıldı.", queueName);
                }
            }
        }
Exemple #2
0
 public Publisher(string queueName, IList <Person> persons)
 {
     _rabbitMqService = new RabbitMQService();
     using (var connection = _rabbitMqService.GetRabbitMQConnection())
     {
         using (var channel = connection.CreateModel())
         {
             channel.QueueDeclare(queueName, false, false, false, null);
             String jsonified     = JsonConvert.SerializeObject(persons);
             byte[] personsBuffer = Encoding.UTF8.GetBytes(jsonified);
             channel.BasicPublish("", queueName, null, personsBuffer);
             Console.WriteLine("{0} queue'su üzerine {1}  mesajı yazıldı.", queueName, "Yazıldı");
         }
     }
 }
Exemple #3
0
        public Consumer(string queueName)
        {
            _rabbitMQService = new RabbitMQService();
            using (IConnection connection = _rabbitMQService.GetRabbitMQConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    channel.QueueDeclare(
                        queue: queueName,
                        durable: false,
                        exclusive: false,
                        autoDelete: false,
                        arguments: null
                        );

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {// Received event'i sürekli listen modunda olacaktır.
                        try
                        {
                            var           body    = ea.Body.Span;
                            string        message = Encoding.UTF8.GetString(body);
                            List <Person> persons = JsonConvert.DeserializeObject <List <Person> >(message);

                            Console.WriteLine("{0} isimli queue üzerinden gelen mesaj geldi", queueName);
                            foreach (var item in persons)
                            {
                                Console.WriteLine("{0} isimli queue üzerinden gelen mesaj: \"{1}\"", queueName, $"{item.Name} {item.SurName}");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("{0} consumer hata mesajı:", ex.Message);
                        }
                    };

                    channel.BasicConsume(
                        queue: queueName,
                        autoAck: true,
                        consumer: consumer);

                    Console.WriteLine("Veri alımı tamamlandı.");
                }
            }
        }
Exemple #4
0
        public Consumer(string queueName, string test)
        {
            _rabbitMQService = new RabbitMQService();

            using (var connection = _rabbitMQService.GetRabbitMQConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var consumer = new EventingBasicConsumer(channel);
                    // Received event'i sürekli listen modunda olacaktır.
                    consumer.Received += (model, ea) =>
                    {
                        var body    = ea.Body;
                        var message = Encoding.UTF8.GetString(body);

                        Console.WriteLine("{0} isimli queue üzerinden gelen mesaj: \"{1}\"", queueName, message);
                    };

                    channel.BasicConsume(queueName, false, consumer);
                    Console.ReadLine();
                }
            }
        }
Exemple #5
0
        public Consumer(string queueName)
        {
            _rabbitMQService = new RabbitMQService();
            using (var connection = _rabbitMQService.GetRabbitMQConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var consumer = new EventingBasicConsumer(channel);
                    // Received event'i sürekli listen modunda olacaktır.
                    consumer.Received += (model, ea) =>
                    {
                        var body    = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        var test    = JsonConvert.DeserializeObject <List <Person> >(message);
                        Console.WriteLine("{0} isimli # queue üzerinden gelen mesaj: \"{1}\"", queueName, "test");
                    };

                    //MessageReceiver messageReceiver = new MessageReceiver(channel);
                    channel.BasicConsume(queueName, true, consumer);
                    // channel.BasicConsume(queueName, false, messageReceiver);
                    Console.ReadLine();
                }
            }
        }