public void Publish(T message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var channel = _rabbitMqChannelProvider.OpenChannel(); var exchangeName = _queueBuilder.GetExchangeName(); var routingKey = _queueBuilder.GetRoutingKey(message); var queueName = _queueBuilder.GetQueueName(); var body = Serialize(message); var props = channel.CreateBasicProperties(); props.Persistent = true; props.MessageId = Guid.NewGuid().ToString(); channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicPublish(exchangeName, routingKey, props, body); _logger.Information("Message published to {queueName}: {messageId}", queueName, props.MessageId); }
public void ExchangeNameIsEmpty() { var builder = new RabbitMqDefaultQueueBuilder <TestMessage>(); var exchangeName = builder.GetExchangeName(); Assert.AreEqual(string.Empty, exchangeName); }