public async Task Publish <T>(T @event) where T : IEvent
 {
     using (var p = new ProducerBuilder <Null, T>(_producerConfig).Build())
     {
         var name = EventBusHelper.GetTypeName <T>();
         var dr   = await p.ProduceAsync(name, new Message <Null, T> {
             Value = @event
         });
     }
 }
        public async Task Commit <T>(T message)
        {
            var outboxMessage = new OutboxMessage
            {
                Type = EventBusHelper.GetTypeName <T>(),
                Data = message == null ? "{}" : JsonConvert.SerializeObject(message, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                })
            };

            await _outboxMessages.InsertOneAsync(outboxMessage);
        }
        public async Task <Guid> Add <T>(T message, Guid transactionId) where T : IEvent
        {
            var outboxMessage = new OutboxMessage
            {
                Type = EventBusHelper.GetTypeName <T>(),
                Data = message == null ? "{}" : JsonConvert.SerializeObject(message, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                }),
                TransactionId = transactionId
            };

            await _outboxMessages.InsertOneAsync(outboxMessage);

            return(outboxMessage.Id);
        }
        public void Subscribe(Type type)
        {
            using (var c = new ConsumerBuilder <Ignore, string>(_consumerConfig).Build())
            {
                var name = EventBusHelper.GetTypeName(type);
                c.Subscribe(name);

                try
                {
                    while (true)
                    {
                        c.Consume();
                    }
                }
                catch (OperationCanceledException)
                {
                    // Ensure the consumer leaves the group cleanly and final offsets are committed.
                    c.Close();
                    throw;
                }
            }
        }
 public Resources()
 {
     EventBusHelper = new EventBusHelper();
 }
Exemplo n.º 6
0
        private Action <RawRabbit.Configuration.Exchange.IExchangeDeclarationBuilder> GetExchangeDeclaration(Type type)
        {
            var name = EventBusHelper.GetTypeName(type);

            return(GetExchangeDeclaration(name));
        }