/// <inheritdoc /> void IPublicationBuilder <T> .Configure( JustSayingBus bus, IAwsClientFactoryProxy proxy, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <TopicPublicationBuilder <T> >(); logger.LogInformation("Adding SNS publisher for message type '{MessageType}'.", typeof(T)); var config = bus.Config; var readConfiguration = new SqsReadConfiguration(SubscriptionType.ToTopic); var writeConfiguration = new SnsWriteConfiguration(); ConfigureWrites?.Invoke(writeConfiguration); readConfiguration.ApplyTopicNamingConvention <T>(config.TopicNamingConvention); bus.SerializationRegister.AddSerializer <T>(); foreach (var region in config.Regions) { // TODO pass region down into topic creation for when we have foreign topics so we can generate the arn var eventPublisher = new SnsTopicByName( readConfiguration.TopicName, proxy.GetAwsClientFactory().GetSnsClient(RegionEndpoint.GetBySystemName(region)), bus.SerializationRegister, loggerFactory, writeConfiguration, config.MessageSubjectProvider) { MessageResponseLogger = config.MessageResponseLogger }; async Task StartupTask() { if (writeConfiguration.Encryption != null) { await eventPublisher.CreateWithEncryptionAsync(writeConfiguration.Encryption) .ConfigureAwait(false); } else { await eventPublisher.CreateAsync().ConfigureAwait(false); } await eventPublisher.EnsurePolicyIsUpdatedAsync(config.AdditionalSubscriberAccounts) .ConfigureAwait(false); } bus.AddStartupTask(StartupTask()); bus.AddMessagePublisher <T>(eventPublisher, region); } logger.LogInformation( "Created SNS topic publisher on topic '{TopicName}' for message type '{MessageType}'.", readConfiguration.TopicName, typeof(T)); }
/// <inheritdoc /> void ISubscriptionBuilder <T> .Configure( JustSayingBus bus, IHandlerResolver resolver, IVerifyAmazonQueues creator, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <TopicSubscriptionBuilder <T> >(); var subscriptionConfig = new SqsReadConfiguration(SubscriptionType.ToTopic) { QueueName = TopicName }; ConfigureReads?.Invoke(subscriptionConfig); var config = bus.Config; subscriptionConfig.ApplyTopicNamingConvention <T>(config.TopicNamingConvention); subscriptionConfig.ApplyQueueNamingConvention <T>(config.QueueNamingConvention); subscriptionConfig.SubscriptionGroupName ??= subscriptionConfig.QueueName; subscriptionConfig.PublishEndpoint = subscriptionConfig.TopicName; subscriptionConfig.Validate(); var queueWithStartup = creator.EnsureTopicExistsWithQueueSubscribed( config.Region, bus.SerializationRegister, subscriptionConfig, config.MessageSubjectProvider); bus.AddStartupTask(queueWithStartup.StartupTask); bus.AddQueue(subscriptionConfig.SubscriptionGroupName, queueWithStartup.Queue); logger.LogInformation( "Created SQS topic subscription on topic '{TopicName}' and queue '{QueueName}'.", subscriptionConfig.TopicName, subscriptionConfig.QueueName); var resolutionContext = new HandlerResolutionContext(subscriptionConfig.QueueName); var proposedHandler = resolver.ResolveHandler <T>(resolutionContext); if (proposedHandler == null) { throw new HandlerNotRegisteredWithContainerException( $"There is no handler for '{typeof(T)}' messages."); } bus.AddMessageHandler(subscriptionConfig.QueueName, () => resolver.ResolveHandler <T>(resolutionContext)); logger.LogInformation( "Added a message handler for message type for '{MessageType}' on topic '{TopicName}' and queue '{QueueName}'.", typeof(T), subscriptionConfig.TopicName, subscriptionConfig.QueueName); }
/// <inheritdoc /> void ISubscriptionBuilder <T> .Configure( JustSayingBus bus, IHandlerResolver resolver, IVerifyAmazonQueues creator, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <QueueSubscriptionBuilder <T> >(); var subscriptionConfig = new SqsReadConfiguration(SubscriptionType.PointToPoint) { QueueName = QueueName }; ConfigureReads?.Invoke(subscriptionConfig); var config = bus.Config; subscriptionConfig.ApplyTopicNamingConvention <T>(config.TopicNamingConvention); subscriptionConfig.ApplyQueueNamingConvention <T>(config.QueueNamingConvention); subscriptionConfig.SubscriptionGroupName ??= subscriptionConfig.QueueName; subscriptionConfig.Validate(); var queue = creator.EnsureQueueExists(config.Region, subscriptionConfig); bus.AddStartupTask( queue.Queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdatedAsync(subscriptionConfig)); bus.AddQueue(subscriptionConfig.SubscriptionGroupName, queue.Queue); logger.LogInformation( "Created SQS subscriber for message type '{MessageType}' on queue '{QueueName}'.", typeof(T), subscriptionConfig.QueueName); var resolutionContext = new HandlerResolutionContext(subscriptionConfig.QueueName); var proposedHandler = resolver.ResolveHandler <T>(resolutionContext); if (proposedHandler == null) { throw new HandlerNotRegisteredWithContainerException( $"There is no handler for '{typeof(T)}' messages."); } bus.AddMessageHandler(subscriptionConfig.QueueName, () => resolver.ResolveHandler <T>(resolutionContext)); logger.LogInformation( "Added a message handler for message type for '{MessageType}' on topic '{TopicName}' and queue '{QueueName}'.", typeof(T), subscriptionConfig.TopicName, subscriptionConfig.QueueName); }