Exemplo n.º 1
0
        public async Task SendAsync(QueueMessage message,
                                    CancellationToken cancellationToken = default(CancellationToken))
        {
            var channel = _channels.Create(message.Subject);
            var body    = Encoding.UTF8.GetBytes(message.Body);

            var properties = channel.CreateBasicProperties();

            properties.Persistent = true;

            await Task.Run(() =>
            {
                channel.BasicPublish(
                    exchange: _details.Exchange,
                    routingKey: message.Subject,
                    basicProperties: properties,
                    body: body);
            });
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            foreach (var command in _commands)
            {
                var channel = _channelFactory.Create(command.Key);

                channel.QueueBind(
                    command.Key, _connectionDetails.Exchange, command.Key, null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += OnConsumerRecieved;

                channel.BasicQos(0, 1, false);
                channel.BasicConsume(queue: command.Key,
                                     autoAck: false,
                                     consumer: consumer);

                _commandChannels.Add(command.Key, channel);
            }
        }