public async Task PublishAsync <T>(T @event, string correlationId) where T : class { var properties = new EventProperties() { CorrelationId = correlationId }; var message = CreateMessage(@event, properties); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public async Task ScheduleAsync <T>(T @event, DateTime scheduledEnqueueTimeUtc, string correlationId) where T : class { var properties = new EventProperties() { CorrelationId = correlationId }; var message = CreateMessage(@event, properties, scheduledEnqueueTimeUtc); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public Task PublishAsync <T>(T @event, string correlationId) where T : class { var properties = new EventProperties() { CorrelationId = correlationId }; var message = CreateMessage(@event, properties); return(InnerSendAsync(message, properties)); }
public Task ScheduleAsync <T>(T @event, DateTime scheduledEnqueueTimeUtc, string correlationId) where T : class { var properties = new EventProperties() { CorrelationId = correlationId }; var message = CreateMessage(@event, properties, scheduledEnqueueTimeUtc); return(InnerSendAsync(message, properties)); }
private async Task InnerSendAsync(Message message, EventProperties properties) { using (Logger.BeginScope(new Dictionary <string, object> { ["CorrelationId"] = message.Properties.CorrelationId, ["MessageId"] = message.Properties.MessageId, ["MessageType"] = message.Properties.GroupId })) { Logger.LogTrace($"Publishing message {message.Properties.MessageId} to {properties.Address} with body: {message.Body}"); var disconnectAfter = false; if (conn == null) { Connect(); disconnectAfter = true; } var session = new Session(conn); var attach = new Attach() { Target = new Target() { Address = properties.Address, Durable = Settings.Durable }, Source = new Source() }; var sender = new SenderLink(session, Settings.AppName + Guid.NewGuid().ToString(), attach, null); sender.Closed += OnClosed; try { await sender.SendAsync(message).ConfigureAwait(false); Logger.LogInformation($"Published message {message.Properties.MessageId}"); } finally { if (sender.Error != null) { Error = new DomainEventError(); Error.Condition = sender.Error.Condition.ToString(); Error.Description = sender.Error.Description; Closed?.Invoke(this, Error); } if (disconnectAfter) { if (!sender.IsClosed) { await sender.CloseAsync(TimeSpan.FromSeconds(5)).ConfigureAwait(false); } await session.CloseAsync().ConfigureAwait(false); await session.Connection.CloseAsync().ConfigureAwait(false); } } } }
private async Task InnerSendAsync(Message message, EventProperties properties) { using (Logger.BeginScope(new Dictionary <string, object> { ["CorrelationId"] = message.Properties.CorrelationId, ["MessageId"] = message.Properties.MessageId, ["MessageType"] = message.Properties.GroupId })) { Logger.LogTrace("Publishing message {MessageId} to {Address} with body: {MessageBody}", message.Properties.MessageId, properties.Address, message.Body); await SendAsync(message, properties); } }
protected override async Task SendAsync(Message message, EventProperties properties) { var disconnectAfter = false; if (conn == null) { Connect(); disconnectAfter = true; } var session = new Session(conn); var attach = new Attach() { Target = new Target() { Address = properties.Address, Durable = Settings.Durable }, Source = new Source() }; var sender = new SenderLink(session, Settings.AppName + Guid.NewGuid().ToString(), attach, null); sender.Closed += OnClosed; try { await sender.SendAsync(message).ConfigureAwait(false); Logger.LogInformation($"Published message {message.Properties.MessageId}"); } finally { if (sender.Error != null) { Error = new DomainEventError(); Error.Condition = sender.Error.Condition.ToString(); Error.Description = sender.Error.Description; Closed?.Invoke(this, Error); } if (disconnectAfter) { if (!sender.IsClosed) { await sender.CloseAsync(TimeSpan.FromSeconds(5)).ConfigureAwait(false); } await session.CloseAsync().ConfigureAwait(false); await session.Connection.CloseAsync().ConfigureAwait(false); } } }
private Message CreateMessage(object @event, EventProperties properties, DateTime?scheduledEnqueueTimeUtc = null) { string data; if (Settings.SerializerSettings != null) { data = JsonConvert.SerializeObject(@event, Settings.SerializerSettings); } else { data = JsonConvert.SerializeObject(@event); } properties.EventType = properties.EventType ?? @event.GetType().FullName; properties.Topic = properties.Topic ?? Settings.Topic; properties.RoutingKey = properties.RoutingKey ?? @event.GetType().Name; return(CreateMessage(data, properties, scheduledEnqueueTimeUtc)); }
public async Task PublishAsync(string body, EventProperties properties) { var message = CreateMessage(body, properties); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public async Task PublishAsync <T>(T @event, EventProperties properties) where T : class { var message = CreateMessage(@event, properties); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public Task ScheduleAsync <T>(T @event, DateTime scheduledEnqueueTimeUtc, EventProperties properties) where T : class { var message = CreateMessage(@event, properties, scheduledEnqueueTimeUtc); return(InnerSendAsync(message, properties)); }
public Task PublishAsync(string body, EventProperties properties) { var message = CreateMessage(body, properties); return(InnerSendAsync(message, properties)); }
public Task PublishAsync <T>(T @event, EventProperties properties) where T : class { var message = CreateMessage(@event, properties); return(InnerSendAsync(message, properties)); }
protected abstract Task SendAsync(Message message, EventProperties properties);
public async Task ScheduleAsync <T>(T @event, DateTime scheduledEnqueueTimeUtc, EventProperties properties) where T : class { var message = CreateMessage(@event, properties, scheduledEnqueueTimeUtc); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public async Task ScheduleAsync(string body, DateTime scheduledEnqueueTimeUtc, EventProperties properties) { var message = CreateMessage(body, properties, scheduledEnqueueTimeUtc); await InnerSendAsync(message, properties).ConfigureAwait(false); }
public Task ScheduleAsync(string body, DateTime scheduledEnqueueTimeUtc, EventProperties properties) { var message = CreateMessage(body, properties, scheduledEnqueueTimeUtc); return(InnerSendAsync(message, properties)); }