Esempio n. 1
0
        public void ProductRevisionConsumer()
        {
            if (!_rabbitMqFactory.IsConnected)
            {
                _rabbitMqFactory.TryConnect();
            }

            var channel = _rabbitMqFactory.CreateModel();

            channel.QueueDeclare(queue: RabbitMqConstants.ProductRevisionQueue, durable: true, exclusive: false, autoDelete: false, arguments: null);

            var consumer = new AsyncEventingBasicConsumer(channel);

            consumer.Received += SaveProductRevision;

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

            //channel.CallbackException += (sender, ea) =>
            //{
            //    _consumerChannel.Dispose();
            //    _consumerChannel = ProductRevisionConsumer();
            //};
        }
Esempio n. 2
0
        public async Task RabbitMqSender <T>(T model, string queueName)
        {
            if (!_rabbitMqFactory.IsConnected)
            {
                _rabbitMqFactory.TryConnect();
            }

            using (var channel = _rabbitMqFactory.CreateModel())
            {
                channel.QueueDeclare(queue: queueName, durable: true, exclusive: false, autoDelete: false, arguments: null);

                var properties = channel.CreateBasicProperties();
                properties.DeliveryMode = 2;

                var revision = JsonConvert.SerializeObject(model);
                var body     = Encoding.UTF8.GetBytes(revision);

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

            //TODO Async
            await Task.Delay(50);
        }