public async Task <SqsQueueByName> EnsureTopicExistsWithQueueSubscribedAsync(
            string region,
            IMessageSerializationRegister serializationRegister,
            SqsReadConfiguration queueConfig,
            IMessageSubjectProvider messageSubjectProvider)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queue = await EnsureQueueExistsAsync(region, queueConfig).ConfigureAwait(false);

            if (TopicExistsInAnotherAccount(queueConfig))
            {
                var arnProvider = new ForeignTopicArnProvider(regionEndpoint, queueConfig.TopicSourceAccount, queueConfig.PublishEndpoint);

                var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                await SubscribeQueueAndApplyFilterPolicyAsync(snsClient, topicArn, sqsClient, queue.Uri, queueConfig.FilterPolicy).ConfigureAwait(false);
            }
            else
            {
                var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsClient, serializationRegister, _loggerFactory, messageSubjectProvider);
                await eventTopic.CreateAsync().ConfigureAwait(false);

                await SubscribeQueueAndApplyFilterPolicyAsync(snsClient, eventTopic.Arn, sqsClient, queue.Uri, queueConfig.FilterPolicy).ConfigureAwait(false);

                await SqsPolicy.SaveAsync(eventTopic.Arn, queue.Arn, queue.Uri, sqsClient).ConfigureAwait(false);
            }

            return(queue);
        }
 protected SnsTopicBase(
     IMessageSerializationRegister serializationRegister,
     ILoggerFactory loggerFactory,
     IMessageSubjectProvider messageSubjectProvider)
 {
     _serializationRegister  = serializationRegister;
     _messageSubjectProvider = messageSubjectProvider;
     _logger = loggerFactory.CreateLogger("JustSaying");
 }
 protected SnsTopicBase(IMessageSerialisationRegister serialisationRegister,
                        ILoggerFactory loggerFactory, SnsWriteConfiguration snsWriteConfiguration,
                        IMessageSubjectProvider messageSubjectProvider)
 {
     _serialisationRegister = serialisationRegister;
     _log      = loggerFactory.CreateLogger("JustSaying");
     _eventLog = loggerFactory.CreateLogger("EventLog");
     _snsWriteConfiguration  = snsWriteConfiguration;
     _messageSubjectProvider = messageSubjectProvider;
 }
Beispiel #4
0
 public SnsTopicByName(string topicName, IAmazonSimpleNotificationService client,
                       IMessageSerialisationRegister serialisationRegister,
                       ILoggerFactory loggerFactory, SnsWriteConfiguration snsWriteConfiguration,
                       IMessageSubjectProvider messageSubjectProvider)
     : base(serialisationRegister, loggerFactory, snsWriteConfiguration, messageSubjectProvider)
 {
     TopicName = topicName;
     Client    = client;
     _log      = loggerFactory.CreateLogger("JustSaying");
 }
        public QueueWithAsyncStartup <SqsQueueByName> EnsureTopicExistsWithQueueSubscribed(
            string region,
            IMessageSerializationRegister serializationRegister,
            SqsReadConfiguration queueConfig,
            IMessageSubjectProvider messageSubjectProvider)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queueWithStartup = EnsureQueueExists(region, queueConfig);

            async Task StartupTask()
            {
                await queueWithStartup.StartupTask.ConfigureAwait(false);

                var queue = queueWithStartup.Queue;

                if (TopicExistsInAnotherAccount(queueConfig))
                {
                    var arnProvider = new ForeignTopicArnProvider(regionEndpoint,
                                                                  queueConfig.TopicSourceAccount,
                                                                  queueConfig.PublishEndpoint);

                    var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  topicArn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);
                }
                else
                {
                    var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint,
                                                        snsClient,
                                                        serializationRegister,
                                                        _loggerFactory,
                                                        messageSubjectProvider);
                    await eventTopic.CreateAsync().ConfigureAwait(false);

                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  eventTopic.Arn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);

                    await SqsPolicy
                    .SaveAsync(eventTopic.Arn, queue.Arn, queue.Uri, sqsClient)
                    .ConfigureAwait(false);
                }
            }

            // This StartupTask is intentionally not awaited, as it will be run when the bus is started.
            return(new QueueWithAsyncStartup <SqsQueueByName>(StartupTask(), queueWithStartup.Queue));
        }
Beispiel #6
0
 public SnsMessagePublisher(
     string topicArn,
     IAmazonSimpleNotificationService client,
     IMessageSerializationRegister serializationRegister,
     ILoggerFactory loggerFactory,
     IMessageSubjectProvider messageSubjectProvider,
     Func <Exception, Message, bool> handleException = null)
     : this(client, serializationRegister, loggerFactory, messageSubjectProvider, handleException)
 {
     Arn = topicArn;
 }
Beispiel #7
0
 public SnsMessagePublisher(
     IAmazonSimpleNotificationService client,
     IMessageSerializationRegister serializationRegister,
     ILoggerFactory loggerFactory,
     IMessageSubjectProvider messageSubjectProvider,
     Func <Exception, Message, bool> handleException = null)
 {
     Client = client;
     _serializationRegister = serializationRegister;
     _logger                 = loggerFactory.CreateLogger("JustSaying.Publish");
     _handleException        = handleException;
     _messageSubjectProvider = messageSubjectProvider;
 }
 /// <summary>
 /// Specifies the <see cref="IMessageSubjectProvider"/> to use.
 /// </summary>
 /// <param name="subjectProvider">The <see cref="IMessageSubjectProvider"/> to use.</param>
 /// <returns>
 /// The current <see cref="MessagingConfigurationBuilder"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="subjectProvider"/> is <see cref="null"/>.
 /// </exception>
 public MessagingConfigurationBuilder WithMessageSubjectProvider(IMessageSubjectProvider subjectProvider)
 {
     MessageSubjectProvider = subjectProvider ?? throw new ArgumentNullException(nameof(subjectProvider));
     return(this);
 }
 public static JustSayingFluentlyDependencies WithMessageSubjectProvider(this JustSayingFluentlyDependencies dependencies,
                                                                         IMessageSubjectProvider messageSubjectProvider)
 {
     dependencies.MessageSubjectProvider = messageSubjectProvider;
     return(dependencies);
 }
        public QueueWithAsyncStartup EnsureTopicExistsWithQueueSubscribed(
            string region,
            IMessageSerializationRegister serializationRegister,
            SqsReadConfiguration queueConfig,
            IMessageSubjectProvider messageSubjectProvider)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queueWithStartup = EnsureQueueExists(region, queueConfig);

            async Task StartupTask()
            {
                await queueWithStartup.StartupTask.Invoke().ConfigureAwait(false);

                var queue = queueWithStartup.Queue;

                if (TopicExistsInAnotherAccount(queueConfig))
                {
                    var arnProvider = new ForeignTopicArnProvider(regionEndpoint,
                                                                  queueConfig.TopicSourceAccount,
                                                                  queueConfig.PublishEndpoint);

                    var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  topicArn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);
                }
                else
                {
#pragma warning disable 618
                    var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint,
                                                        snsClient,
                                                        serializationRegister,
                                                        _loggerFactory,
                                                        messageSubjectProvider);
#pragma warning restore 618
                    await eventTopic.CreateAsync().ConfigureAwait(false);

                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  eventTopic.Arn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);

                    var sqsDetails = new SqsPolicyDetails
                    {
                        SourceArn = eventTopic.Arn,
                        QueueArn  = queue.Arn,
                        QueueUri  = queue.Uri
                    };
                    await SqsPolicy
                    .SaveAsync(sqsDetails, sqsClient)
                    .ConfigureAwait(false);
                }
            }

            return(new QueueWithAsyncStartup(StartupTask, queueWithStartup.Queue));
        }
 public MessageSerializationRegister(IMessageSubjectProvider messageSubjectProvider, IMessageSerializationFactory serializationFactory)
 {
     _messageSubjectProvider = messageSubjectProvider ?? throw new ArgumentNullException(nameof(messageSubjectProvider));
     _serializationFactory   = serializationFactory;
 }
 public MessageSerialisationRegister(IMessageSubjectProvider messageSubjectProvider)
 {
     _messageSubjectProvider = messageSubjectProvider;
 }
 public TopicAddressPublisher(IAmazonSimpleNotificationService snsClient, ILoggerFactory loggerFactory, IMessageSubjectProvider subjectProvider, IMessageSerializationRegister serializationRegister, Func <Exception, Message, bool> handleException, TopicAddress topicAddress)
     : base(topicAddress.TopicArn, snsClient, serializationRegister, loggerFactory, subjectProvider, handleException)
 {
 }