Ejemplo n.º 1
0
        public async Task PrepareAsync(EventDescriptor descriptor, IDbConnection dbConnection, IDbTransaction dbTransaction)
        {
            var message = new Internal.Model.Message
            {
                Id           = _identityGenerator.NextIdentity(),
                MessageId    = _identityGenerator.NextIdentity(),
                TransactId   = TransactID,
                Content      = descriptor.Message.GetTransferJson(),
                CreationDate = DateTime.Now,
                State        = MessageState.Processing,
                Type         = MessageType.Published,
                Exchange     = descriptor.Exchange,
                RouteKey     = descriptor.RouteKey
            };
            var metaData = new MetaData();

            metaData.Set("ContentType", descriptor.ContentType);
            metaData.Set("TransactID", message.TransactId.ToString());
            metaData.Set("MessageID", message.MessageId.ToString());
            metaData.Contact(descriptor.Message.MetaData);

            message.MetaData = metaData.ToJson();

            await _publishedEventPersistenter.InsertAsync(message, dbConnection, dbTransaction);

            var jsonTransafer = FeiniuBus.Util.FeiniuBusJsonConvert.SerializeObject(new { MetaData = metaData.GetDictionary(), Content = descriptor.Message.Content });
            await _messageQueueTransaction.PublishAsync(descriptor.Exchange, descriptor.RouteKey, Encoding.UTF8.GetBytes(jsonTransafer));
        }
Ejemplo n.º 2
0
 public EventPublisher(IServiceProvider serviceProvider)
 {
     _serviceProvider            = serviceProvider;
     _identityGenerator          = serviceProvider.GetRequiredService <IIdentityGenerator>();
     _publishedEventPersistenter = serviceProvider.GetRequiredService <IPublishedEventPersistenter>();
     _messageQueueTransaction    = serviceProvider.GetRequiredService <IMessageQueueTransaction>();
     _messageSerializer          = serviceProvider.GetRequiredService <IMessageSerializer>();
     _logger    = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <EventPublisher>();
     TransactID = _identityGenerator.NextIdentity();
 }