/// <inheritdoc /> void IPublicationBuilder <T> .Configure( JustSayingBus bus, IAwsClientFactoryProxy proxy, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <QueuePublicationBuilder <T> >(); logger.LogInformation("Adding SQS publisher for message type '{MessageType}'.", typeof(T)); var config = bus.Config; var region = config.Region ?? throw new InvalidOperationException($"Config cannot have a blank entry for the {nameof(config.Region)} property."); var writeConfiguration = new SqsWriteConfiguration(); ConfigureWrites?.Invoke(writeConfiguration); writeConfiguration.ApplyQueueNamingConvention <T>(config.QueueNamingConvention); bus.SerializationRegister.AddSerializer <T>(); var regionEndpoint = RegionEndpoint.GetBySystemName(region); var sqsClient = proxy.GetAwsClientFactory().GetSqsClient(regionEndpoint); var eventPublisher = new SqsMessagePublisher( sqsClient, bus.SerializationRegister, loggerFactory) { MessageResponseLogger = config.MessageResponseLogger }; #pragma warning disable 618 var sqsQueue = new SqsQueueByName( regionEndpoint, writeConfiguration.QueueName, sqsClient, writeConfiguration.RetryCountBeforeSendingToErrorQueue, loggerFactory); #pragma warning restore 618 async Task StartupTask(CancellationToken cancellationToken) { if (!await sqsQueue.ExistsAsync(cancellationToken).ConfigureAwait(false)) { await sqsQueue.CreateAsync(writeConfiguration, cancellationToken : cancellationToken).ConfigureAwait(false); } eventPublisher.QueueUrl = sqsQueue.Uri; } bus.AddStartupTask(StartupTask); bus.AddMessagePublisher <T>(eventPublisher); logger.LogInformation( "Created SQS publisher for message type '{MessageType}' on queue '{QueueName}'.", typeof(T), writeConfiguration.QueueName); }
/// <inheritdoc /> void IPublicationBuilder <T> .Configure( JustSayingBus bus, IAwsClientFactoryProxy proxy, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <QueuePublicationBuilder <T> >(); logger.LogInformation("Adding SQS publisher for message type '{MessageType}'.", typeof(T)); var config = bus.Config; var writeConfiguration = new SqsWriteConfiguration(); ConfigureWrites?.Invoke(writeConfiguration); writeConfiguration.ApplyQueueNamingConvention <T>(config.QueueNamingConvention); bus.SerializationRegister.AddSerializer <T>(); var regionEndpoint = RegionEndpoint.GetBySystemName(config.Region); var sqsClient = proxy.GetAwsClientFactory().GetSqsClient(regionEndpoint); #pragma warning disable 618 var eventPublisher = new SqsPublisher( regionEndpoint, writeConfiguration.QueueName, sqsClient, writeConfiguration.RetryCountBeforeSendingToErrorQueue, bus.SerializationRegister, loggerFactory) { MessageResponseLogger = config.MessageResponseLogger }; #pragma warning restore 618 async Task StartupTask() { if (!await eventPublisher.ExistsAsync().ConfigureAwait(false)) { await eventPublisher.CreateAsync(writeConfiguration).ConfigureAwait(false); } } bus.AddStartupTask(StartupTask); bus.AddMessagePublisher <T>(eventPublisher); logger.LogInformation( "Created SQS publisher for message type '{MessageType}' on queue '{QueueName}'.", typeof(T), writeConfiguration.QueueName); }