예제 #1
0
        public override void Publish(string message, string exchangeName, string routingKey,
                                     IBasicProperties messageProperties = null)
        {
            if (!IsConnected)
            {
                Connect();
            }
            using (var channel = _connection.CreateModel()) {
                var payload = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchangeName, routingKey,
                                     messageProperties ?? RabbitMQProperties.CreateDefaultProperties(channel), payload);
            }
        }
예제 #2
0
        public override void Publish(string message, string queueName, bool createQueue = true,
                                     IBasicProperties messageProperties = null, IDictionary <string, object> queueArgs = null)
        {
            if (!IsConnected)
            {
                Connect();
            }
            using (var channel = _connection.CreateModel()) {
                if (createQueue)
                {
                    channel.QueueDeclare(queueName, true, false, false, queueArgs);
                }
                var payload = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(string.Empty, queueName,
                                     messageProperties ?? RabbitMQProperties.CreateDefaultProperties(channel), payload);
            }
        }