public void Publish(IntegrationEvent @event) { if (!_persistentConnection.IsConnected) { _persistentConnection.TryConnect(); } _logger.LogTrace("Creating RabbitMQ consumer channel"); using (var channel = _persistentConnection.CreateModel()) { _logger.LogTrace("Declaring RabbitMQ exchange to publish event: {EventId}", @event.Id); channel.ExchangeDeclare(exchange: BROKER_NAME, type: "direct"); var eventName = @event.GetType().Name; var message = @event.SerializeObject(); var body = Encoding.UTF8.GetBytes(message); var properties = channel.CreateBasicProperties(); properties.DeliveryMode = 2; // persistent _logger.LogTrace("Publishing event to RabbitMQ: {EventId}", @event.Id); channel.BasicPublish( exchange: BROKER_NAME, routingKey: eventName, mandatory: true, basicProperties: properties, body: body); } }