private void CreateSubscriptionListener(SqsQueueBase queue, string messageTypeName) { var sqsSubscriptionListener = new SqsNotificationListener(queue, Bus.SerialisationRegister, Bus.Monitor, _subscriptionConfig.OnError, Bus.MessageLock); Bus.AddNotificationTopicSubscriber(messageTypeName, sqsSubscriptionListener); if (_subscriptionConfig.MaxAllowedMessagesInFlight.HasValue) { sqsSubscriptionListener.WithMaximumConcurrentLimitOnMessagesInFlightOf(_subscriptionConfig.MaxAllowedMessagesInFlight.Value); } if (_subscriptionConfig.MessageProcessingStrategy != null) { sqsSubscriptionListener.WithMessageProcessingStrategy(_subscriptionConfig.MessageProcessingStrategy); } }
/// <summary> /// Set message handlers for the given topic /// </summary> /// <typeparam name="T">Message type to be handled</typeparam> /// <param name="handler">Handler for the message type</param> /// <returns></returns> public IHaveFulfilledSubscriptionRequirements WithMessageHandler <T>(IHandler <T> handler) where T : Message { _subscriptionConfig.Topic = typeof(T).Name.ToLower(); var publishEndpointProvider = CreatePublisherEndpointProvider(_subscriptionConfig); _subscriptionConfig.PublishEndpoint = publishEndpointProvider.GetLocationName(); _subscriptionConfig.Validate(); var subscriptionEndpointProvider = CreateSubscriptiuonEndpointProvider(_subscriptionConfig); _subscriptionConfig.QueueName = subscriptionEndpointProvider.GetLocationName(); var queue = _amazonQueueCreator.VerifyOrCreateQueue(Bus.Config.Region, Bus.SerialisationRegister, _subscriptionConfig); var sqsSubscriptionListener = new SqsNotificationListener(queue, Bus.SerialisationRegister, Bus.Monitor, _subscriptionConfig.OnError, Bus.MessageLock); Bus.AddNotificationTopicSubscriber(_subscriptionConfig.Topic, sqsSubscriptionListener); if (_subscriptionConfig.MaxAllowedMessagesInFlight.HasValue) { sqsSubscriptionListener.WithMaximumConcurrentLimitOnMessagesInFlightOf(_subscriptionConfig.MaxAllowedMessagesInFlight.Value); } if (_subscriptionConfig.MessageProcessingStrategy != null) { sqsSubscriptionListener.WithMessageProcessingStrategy(_subscriptionConfig.MessageProcessingStrategy); } Log.Info(string.Format("Created SQS topic subscription - Topic: {0}, QueueName: {1}", _subscriptionConfig.Topic, _subscriptionConfig.QueueName)); _subscriptionConfigured = true; if (!_subscriptionConfigured) { ConfigureSubscriptionWith(conf => conf.ErrorQueueOptOut = _subscriptionConfig.ErrorQueueOptOut); } Bus.SerialisationRegister.AddSerialiser <T>(_serialisationFactory.GetSerialiser <T>()); Bus.AddMessageHandler(handler); Log.Info(string.Format("Added a message handler - Topic: {0}, MessageType: {1}, HandlerName: {2}", _subscriptionConfig.Topic, typeof(T).Name, handler.GetType().Name)); return(this); }