public SqsQueueByName VerifyOrCreateQueue(string region, IMessageSerialisationRegister serialisationRegister, SqsConfiguration queueConfig) { var sqsclient = AWSClientFactory.CreateAmazonSQSClient(RegionEndpoint.GetBySystemName(region)); var snsclient = AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(region)); var queue = new SqsQueueByName(queueConfig.QueueName, sqsclient, queueConfig.RetryCountBeforeSendingToErrorQueue); var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister); if (!queue.Exists()) queue.Create(queueConfig.MessageRetentionSeconds, 0, queueConfig.VisibilityTimeoutSeconds, queueConfig.ErrorQueueOptOut, queueConfig.RetryCountBeforeSendingToErrorQueue); //Create an error queue for existing queues if they don't already have one if(queue.ErrorQueue != null && !queue.ErrorQueue.Exists()) queue.ErrorQueue.Create(JustSayingConstants.MAXIMUM_RETENTION_PERIOD, JustSayingConstants.DEFAULT_CREATE_REATTEMPT, JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT, errorQueueOptOut: true); queue.UpdateRedrivePolicy(new RedrivePolicy(queueConfig.RetryCountBeforeSendingToErrorQueue, queue.ErrorQueue.Arn)); if (!eventTopic.Exists()) eventTopic.Create(); if (!eventTopic.IsSubscribed(queue)) eventTopic.Subscribe(queue); if (!queue.HasPermission(eventTopic)) queue.AddPermission(eventTopic); return queue; }
private static SnsTopicByName EnsureTopicExists(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig) { var snsclient = AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(region)); var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister); if (!eventTopic.Exists()) eventTopic.Create(); return eventTopic; }
private SnsTopicByName EnsureTopicExists(RegionEndpoint region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig) { var snsclient = _awsClientFactory.GetAwsClientFactory().GetSnsClient(region); var eventTopic = _topicCache.TryGetFromCache(region.SystemName, queueConfig.PublishEndpoint); if (eventTopic != null) return eventTopic; eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister); _topicCache.AddToCache(region.SystemName, queueConfig.PublishEndpoint, eventTopic); if (!eventTopic.Exists()) eventTopic.Create(); return eventTopic; }
private SnsTopicByName EnsureTopicExists(RegionEndpoint region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig) { var snsclient = _awsClientFactory.GetAwsClientFactory().GetSnsClient(region); var eventTopic = _topicCache.TryGetFromCache(region.SystemName, queueConfig.PublishEndpoint); if (eventTopic != null) { return(eventTopic); } eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister); _topicCache.AddToCache(region.SystemName, queueConfig.PublishEndpoint, eventTopic); if (!eventTopic.Exists()) { eventTopic.Create(); } return(eventTopic); }
/// <summary> /// Register for publishing messages to SNS /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public IHaveFulfilledPublishRequirements WithSnsMessagePublisher<T>() where T : Message { Log.Info("Adding SNS publisher"); _subscriptionConfig.Topic = typeof(T).Name.ToLower(); var publishEndpointProvider = CreatePublisherEndpointProvider(_subscriptionConfig); var eventPublisher = new SnsTopicByName( publishEndpointProvider.GetLocationName(), AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(Bus.Config.Region)), Bus.SerialisationRegister); if (!eventPublisher.Exists()) eventPublisher.Create(); Bus.SerialisationRegister.AddSerialiser<T>(_serialisationFactory.GetSerialiser<T>()); Bus.AddMessagePublisher<T>(eventPublisher); Log.Info(string.Format("Created SNS topic publisher - Topic: {0}", _subscriptionConfig.Topic)); return this; }
private IHaveFulfilledPublishRequirements AddSnsMessagePublisher <T>(Action <SnsWriteConfiguration> configBuilder) where T : Message { _log.LogInformation("Adding SNS publisher"); var snsWriteConfig = new SnsWriteConfiguration(); configBuilder?.Invoke(snsWriteConfig); _subscriptionConfig.Topic = GetMessageTypeName <T>(); var namingStrategy = GetNamingStrategy(); Bus.SerialisationRegister.AddSerialiser <T>(_serialisationFactory.GetSerialiser <T>()); var topicName = namingStrategy.GetTopicName(_subscriptionConfig.BaseTopicName, GetMessageTypeName <T>()); foreach (var region in Bus.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( topicName, _awsClientFactoryProxy.GetAwsClientFactory().GetSnsClient(RegionEndpoint.GetBySystemName(region)), Bus.SerialisationRegister, _loggerFactory, snsWriteConfig) { MessageResponseLogger = Bus.Config.MessageResponseLogger }; eventPublisher.Create(); eventPublisher.EnsurePolicyIsUpdated(Bus.Config.AdditionalSubscriberAccounts); Bus.AddMessagePublisher <T>(eventPublisher, region); } _log.LogInformation($"Created SNS topic publisher - Topic: {_subscriptionConfig.Topic}"); return(this); }
protected override void When() { _topic = new SnsTopicByName(UniqueName, Bus, new MessageSerialisationRegister(), new LoggerFactory()); _createWasSuccessful = _topic.Create(); }