Exemplo n.º 1
0
        /// <summary>
        /// Publish a new message on the Amazon simple notification service
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <typeparam name="T">Event type</typeparam>
        /// <returns>Publish response</returns>
        public async Task <EbPublishResponse> PublishAsync <T>(string message, CancellationToken cancellationToken)
            where T : IntegrationEvent
        {
            if (!_subscriptionsManager.HasEventTopic <T>())
            {
                return(null);
            }

            var topicArn = _subscriptionsManager.GetEventTopicArn <T>();

            var response = await _snsClient.PublishAsync(topicArn, message, cancellationToken);

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                return(null);
            }

            var instance = await _integrationEventsRespository.CreateInstanceAsync <T>();

            if (instance == null)
            {
                throw new Exception($"Error on creation of the integration event {typeof(T).Name} instance");
            }

            return(new EbPublishResponse(response.HttpStatusCode)
            {
                MessageId = response.MessageId
            });
        }