Пример #1
0
        public Consumer(string queueName)
        {
            _rabbitMqService = new RabbitMqService();
            var connection = _rabbitMqService.GetRabbitMqConnection();
            var channel    = connection.CreateModel();

            ConsumerEvent = new EventingBasicConsumer(channel);
            // Received event'i sürekli listen modunda olacaktır.
            ConsumerEvent.Received += (model, ea) =>
            {
                var body    = ea.Body;
                var message = Encoding.UTF8.GetString(body);
                //var data = $"{queueName} isimli queue üzerinden gelen mesaj: \"{message}\"";
                if (queueName == "MailLog")
                {
                    var data = JsonConvert.DeserializeObject <List <MailLog> >(message);
                    //işlemler
                }
                else if (queueName == "Customer")
                {
                    var data = JsonConvert.DeserializeObject <List <Customer> >(message);
                    //işlemler
                }
            };
            channel.BasicConsume(queueName, true, ConsumerEvent);
        }
Пример #2
0
 static void Main(string[] args)
 {
     RabbitMqService rabbitMqService = new RabbitMqService();
     IConnection connection = rabbitMqService.GetRabbitMqConnection();
     IModel model = connection.CreateModel();
     //model.QueueDeclare(RabbitMqService.BadMessageBufferedQueue, true, false, false, null);
     RunBadMessageDemo(model);
 }
Пример #3
0
        public Consumer(string queueName)
        {
            _rabbitMqService = new RabbitMqService();
            var connection = _rabbitMqService.GetRabbitMqConnection();
            var channel    = connection.CreateModel();

            ConsumerEvent = new EventingBasicConsumer(channel);
            // Received event'i sürekli listen modunda olacaktır.
            ConsumerEvent.Received += (model, ea) =>
            {
                var body    = ea.Body;
                var message = Encoding.UTF8.GetString(body);
                //var data = $"{queueName} isimli queue üzerinden gelen mesaj: \"{message}\"";
                if (queueName == "MailLog")
                {
                    var data = JsonConvert.DeserializeObject <MailLog>(message);
                    //işlemler
                    new Repository.MailLogRepo().Insert(new MailLog()
                    {
                        Id         = data.Id,
                        CustomerId = data.CustomerId,
                        Message    = data.Message,
                        Subject    = data.Subject
                    });
                    Form1.logMailLog++;
                    Form.Text = $"Customer {Form1.logCustomer} - MailLog {Form1.logMailLog}";
                }
                else if (queueName == "Customer")
                {
                    var data = JsonConvert.DeserializeObject <List <Customer> >(message);
                    var repo = new Repository.CustomerRepo();
                    for (var i = 0; i < data.Count; i++)
                    {
                        var item = data[i];
                        Form1.logCustomer++;
                        Form.Text = $"Customer {Form1.logCustomer} - MailLog {Form1.logMailLog}";
                        repo.InsertForMark(new Customer()
                        {
                            Address      = item.Address,
                            Email        = item.Email,
                            Id           = item.Id,
                            Name         = item.Name,
                            Phone        = item.Phone,
                            Surname      = item.Surname,
                            RegisterDate = item.RegisterDate
                        });
                        if (i % 100 == 0)
                        {
                            repo.Save();
                        }
                    }
                    repo.Save();

                    //işlemler
                }
            };
            channel.BasicConsume(queueName, true, ConsumerEvent);
        }
Пример #4
0
        static void Main(string[] args)
        {
            RabbitMqService commonService = new RabbitMqService();
            IConnection     connection    = commonService.GetRabbitMqConnection();
            IModel          model         = connection.CreateModel();

            //ReceiveBufferedMessages(model);
            ReceiveChunkedMessages(model);
        }
Пример #5
0
        static void Main(string[] args)
        {
            RabbitMqService messageService = new RabbitMqService();
            IConnection     connection     = messageService.GetRabbitMqConnection();
            IModel          model          = connection.CreateModel();

            //ReceiveBadMessages(model);
            ReceiveBadMessageExtended(model);
        }
Пример #6
0
        static void Main(string[] args)
        {
            RabbitMqService rabbitMqService = new RabbitMqService();
            IConnection     connection      = rabbitMqService.GetRabbitMqConnection();
            IModel          model           = connection.CreateModel();

            //model.QueueDeclare(RabbitMqService.BadMessageBufferedQueue, true, false, false, null);
            RunBadMessageDemo(model);
        }
Пример #7
0
 public Publisher(string message, string queueName = null)
 {
     if (string.IsNullOrEmpty(queueName))
     {
         queueName = DefaultQueue;
     }
     _rabbitMQService = new RabbitMqService();
     using (var connection = _rabbitMQService.GetRabbitMqConnection())
     {
         using (var channel = connection.CreateModel())
         {
             channel.QueueDeclare(queueName, false, false, false, null);
             channel.BasicPublish(string.Empty, queueName, null, Encoding.UTF8.GetBytes(message));
         }
     }
 }
Пример #8
0
        static void Main(string[] args)
        {
            RabbitMqService rabbitMqService = new RabbitMqService();
            IConnection connection = rabbitMqService.GetRabbitMqConnection();

            IModel model = connection.CreateModel();
            //SetupDurableElements(model);
            SendDurableMessageToDurableQueue(model);

            /*
            IBasicProperties basicProperties = model.CreateBasicProperties();
            basicProperties.SetPersistent(true);
            byte[] payload = Encoding.UTF8.GetBytes("This is a persistent message from Visual Studio");
            PublicationAddress address = new PublicationAddress(ExchangeType.Topic, "exchangeFromVisualStudio", "superstars");

            model.BasicPublish(address, basicProperties, payload);*/
        }
Пример #9
0
        public Publisher(string message, string queueName = null)
        {
            if (string.IsNullOrEmpty(queueName))
            {
                queueName = DefaultQueue;
            }
            _rabbitMqService = new RabbitMqService();

            using (var connection = _rabbitMqService.GetRabbitMqConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queueName, false, false, false, null);
                    channel.BasicPublish(string.Empty, queueName, null, Encoding.UTF8.GetBytes(message));

                    //Console.WriteLine($"{queueName} queue'su üzerine, \"{message}\" mesajı yazıldı.");
                }
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            Console.Write("RabbitMQ Starting Service... \n");
            RabbitMqService rabbitMqService = new RabbitMqService();
            IConnection     connection      = rabbitMqService.GetRabbitMqConnection();
            IModel          model           = connection.CreateModel();

            RabbitMqService.SetupDurableElements(model);
            var range = Enumerable.Range(1, 10);

            foreach (var i in range)
            {
                Thread.Sleep(5000);
                RabbitMqService.SendDurableMessageToDurableQueue(model);


                Console.Write("RabbitMQ : Published => Done \n");
                Console.Write($"RabbitMQ : {Thread.CurrentThread.Name}  \n");
            }
        }
Пример #11
0
        public Consumer(string queueName)
        {
            _rabbitMqService = new RabbitMqService();
            var connection = _rabbitMqService.GetRabbitMqConnection();
            var channel    = connection.CreateModel();

            ConsumerEvent           = new EventingBasicConsumer(channel);
            ConsumerEvent.Received += (model, ea) =>
            {
                var body    = ea.Body;
                var message = Encoding.UTF8.GetString(body);
                if (queueName == "MailLog")
                {
                    var data = JsonConvert.DeserializeObject <List <MailLog> >(message);
                }
                else if (queueName == "Customer")
                {
                    var data = JsonConvert.DeserializeObject <List <Customer> >(message);
                    var repo = new CustomerRepo();

                    foreach (var customer in data)
                    {
                        repo.Insert(new Customer()
                        {
                            Address      = customer.Address,
                            Email        = customer.Email,
                            Id           = customer.Id,
                            Name         = customer.Name,
                            Phone        = customer.Phone,
                            Surname      = customer.Surname,
                            RegisterDate = customer.RegisterDate
                        });
                    }
                }
            };
            channel.BasicConsume(queueName, true, ConsumerEvent);
        }
Пример #12
0
 public MainWindow()
 {
     InitializeComponent();
     connection = rabbitMqService.GetRabbitMqConnection();
     SetUpRequestConsumer();
 }