public async Task PublishAsync(IntegrationEvent @event) { var eventName = @event.GetType().Name; var jsonMessage = JsonConvert.SerializeObject(@event); var body = Encoding.UTF8.GetBytes(jsonMessage); var message = new Message { MessageId = Guid.NewGuid().ToString(), Body = body, Label = eventName, }; // lazy connection if (_topicClient.IsClosedOrClosing) { _topicClient = CreateTopicClient(); } await _topicClient.SendAsync(message); }
public void Publish(IntegrationEvent @event) { if (!_persistentConnection.IsConnected) { _policy.Execute((context) => _persistentConnection.TryConnect(), new Dictionary <string, object>() { { "logmessage", "RabbitMQ Client could not connect " } }); } _persistentConnection.CreateChannel(); var eventName = @event.GetType().Name; string message; if (@event.LegacyOut) { message = JsonConvert.SerializeObject(new LegacyOut(@event, eventName)); eventName = "LegacyOutIntegrationEvent"; } else { message = JsonConvert.SerializeObject(@event); } var body = Encoding.UTF8.GetBytes(message); _policy.Execute((context) => _persistentConnection.Publish(eventName, body), new Dictionary <string, object>() { { "logmessage", $"Could not publish event: {@event.Id} " } }); }
protected abstract Task PublishAsync(Type eventType, IntegrationEvent eventDate);