コード例 #1
0
        public async Task SendIntegrationEvent(IIntegrationEvent evento)
        {
            var sender = _senders.SingleOrDefault(x => x.EntityPath == evento.GetType().Name);

            if (sender == null)
            {
                throw new NotImplementedException(
                          $"No hay un sender implementado para la cola {evento.GetType().Name}");
            }


            string jsonString = JsonSerializer.Serialize(evento, evento.GetType());

            byte[]            objBytes = Encoding.UTF8.GetBytes(jsonString);
            ServiceBusMessage message  = new ServiceBusMessage(new BinaryData(objBytes))
            {
                ContentType = "application/json"
            };

            if (evento is ISessionIntegrationEvent sessionEvent)
            {
                if (string.IsNullOrEmpty(sessionEvent.IdSessionId))
                {
                    throw new InvalidOperationException(
                              $"Si el evento herada {nameof(ISessionIntegrationEvent)} es necesario especificar la session, si no dese sesiones use {nameof(IIntegrationEvent)}");
                }
                message.SessionId = sessionEvent.IdSessionId;
            }



            await sender.SendMessageAsync(message);
        }
コード例 #2
0
        public async Task PublishAsync(IIntegrationEvent @event)
        {
            _logger.LogTrace($"Publishing message of type {{{@event.GetType().Name}}}.");
            await _client.PublishAsync(@event);

            _logger.LogTrace($"Successfully published message of type {{{@event.GetType().Name}}}.");
        }
コード例 #3
0
        /// <inheritdoc />
        public void Publish(IIntegrationEvent @event)
        {
            if (!_persistentConnection.IsConnected)
            {
                _persistentConnection.TryConnect();
            }

            var policy = Policy.Handle <BrokerUnreachableException>()
                         .Or <SocketException>()
                         .WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
            {
                _logger.LogWarning(ex.ToString());
            });

            using (var channel = _persistentConnection.CreateModel())
            {
                var eventName = @event.GetType().Name;
                channel.ExchangeDeclare(exchange: _brokerName, type: "direct");

                var message = JsonConvert.SerializeObject(@event);
                var body    = Encoding.UTF8.GetBytes(message);
                policy.Execute(() =>
                {
                    channel.BasicPublish(exchange: _brokerName, routingKey: eventName, basicProperties: null, body: body);
                });
            }
        }
コード例 #4
0
        public void Publish(IIntegrationEvent integrationEvent)
        {
            using IModel channel = connection.CreateModel();

            channel.ExchangeDeclare(exchange: brokerName, type: ExchangeType.Direct);

            channel.BasicPublish(exchange: brokerName, routingKey: integrationEvent.GetType().Name, basicProperties: null, body: Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(integrationEvent)));
        }
コード例 #5
0
        public void LogIntegrationEventError(ServiceComponentEnumeration serviceComponent, IIntegrationEvent integrationEvent, string message,
                                             params object[] args)
        {
            var errorMessage = "serviceComponent={serviceComponent}, integrationEvent={integrationEvent}, correlationId={correlationId}, " + message;

            args = args.Prepend(integrationEvent.CorrelationId).Prepend(integrationEvent.GetType().Name).Prepend(serviceComponent.DisplayName).ToArray();
            _logger.LogError(errorMessage, args);
        }
コード例 #6
0
 public IntegrationEventLogEntry(IIntegrationEvent @event, Guid transactionId)
 {
     EventId       = @event.EventId;
     TimeStamp     = @event.TimeStamp;
     EventTypeName = @event.GetType().FullName;
     Content       = JsonConvert.SerializeObject(@event);
     State         = EventStateEnum.NotPublished;
     TimesSent     = 0;
     TransactionId = transactionId.ToString();
 }
コード例 #7
0
            public DomainStoreEntity(IIntegrationEvent integrationEvent)
                : this()
            {
                TypeName     = integrationEvent.GetType().AssemblyQualifiedName;
                PartitionKey = EntityPartitionKey;
                RowKey       = GetRowKey(integrationEvent.Created);
                IsCompressed = true;

                var json = JsonConvert.SerializeObject(integrationEvent, TableStorageJsonSerializerSettings.GetDefault());

                Data = IsCompressed ? json.Zip() : json;
            }
コード例 #8
0
        public void Publish(IIntegrationEvent @event)
        {
            //TODO: move "magic strings" to configuration

            using (var connection = connectionFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "iss-exchange", type: "direct");


                    channel.BasicPublish(exchange: "iss-exchange",
                                         routingKey: @event.GetType().Name,
                                         basicProperties: null,
                                         body: PrepareMessage(@event));
                }
        }
コード例 #9
0
        public async Task PublishIntegrationEventAsync(IIntegrationEvent integrationEvent)
        {
            var eventName   = integrationEvent.GetType().Name.Replace(IntegrationEventSuffix, "");
            var jsonMessage = JsonConvert.SerializeObject(integrationEvent);
            var body        = Encoding.UTF8.GetBytes(jsonMessage);

            var message = new Message
            {
                MessageId     = Guid.NewGuid().ToString(),
                Body          = body,
                Label         = eventName,
                CorrelationId = integrationEvent.CorrelationId.ToString()
            };

            var topicClient = _serviceBusPersisterConnection.CreateTopicClient();
            await topicClient.SendAsync(message);
        }
コード例 #10
0
        /// <inheritdoc />
        public void Publish(IIntegrationEvent @event)
        {
            var eventName   = @event.GetType().Name.Replace(IntegrationEventSufix, "");
            var jsonMessage = JsonConvert.SerializeObject(@event);

            var message = new Message
            {
                MessageId = new Guid().ToString(),
                Body      = Encoding.UTF8.GetBytes(jsonMessage),
                Label     = eventName,
            };

            var topicClient = _serviceBusPersisterConnection.CreateModel();

            topicClient.SendAsync(message)
            .GetAwaiter()
            .GetResult();
        }
コード例 #11
0
 public static string GetLabel(this IIntegrationEvent integrationEvent)
 {
     return(GetLabelForType(integrationEvent.GetType()));
 }