public void AddSerializer <T>() where T : Message
        {
            Type key = typeof(T);

            if (!_map.ContainsKey(key))
            {
                _map[key] = new TypeSerializer(typeof(T), _serializationFactory.GetSerializer <T>());
            }
        }
Ejemplo n.º 2
0
        private IHaveFulfilledPublishRequirements AddSnsMessagePublisher <T>(Action <SnsWriteConfiguration> configBuilder) where T : Message
        {
            _log.LogInformation("Adding SNS publisher for message type '{MessageType}'.",
                                typeof(T));

            var snsWriteConfig = new SnsWriteConfiguration();

            configBuilder?.Invoke(snsWriteConfig);

            _subscriptionConfig.Topic = typeof(T).ToTopicName();
            var namingStrategy = GetNamingStrategy();

            Bus.SerializationRegister.AddSerializer <T>(_serializationFactory.GetSerializer <T>());

            var topicName = namingStrategy.GetTopicName(_subscriptionConfig.BaseTopicName, typeof(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.SerializationRegister,
                    _loggerFactory, snsWriteConfig,
                    Bus.Config.MessageSubjectProvider)
                {
                    MessageResponseLogger = Bus.Config.MessageResponseLogger
                };

                eventPublisher.CreateAsync().GetAwaiter().GetResult();

                eventPublisher.EnsurePolicyIsUpdatedAsync(Bus.Config.AdditionalSubscriberAccounts).GetAwaiter().GetResult();

                Bus.AddMessagePublisher <T>(eventPublisher, region);
            }

            _log.LogInformation("Created SNS topic publisher on topic '{TopicName}' for message type '{MessageType}'.",
                                _subscriptionConfig.Topic, typeof(T));

            return(this);
        }