public void Publish<TPayload>(Event<TPayload> @event)
        {
            PublishedEvents.Add(new Event<object>
            {
                Id = @event.Id,
                CreatedAt = @event.CreatedAt,
                Name = @event.Name,
                Payload = @event.Payload
            });

            var type = _eventBinding.GetSubscriberType(@event.Name);

            if (type != null)
            {
                var subscriber = (IEventSubscriber)_serviceProvider.GetRequiredService(type);
                subscriber.Handle(JsonConvert.SerializeObject(@event));
            }
        }
Exemple #2
0
        private async Task HandleMessage(object sender, BasicDeliverEventArgs args)
        {
            try
            {
                using (var scope = _serviceProvider.CreateScope())
                {
                    var type = _eventBinding.GetSubscriberType(args.RoutingKey);

                    if (type != null)
                    {
                        var subscriber = ((IEventSubscriber)scope.ServiceProvider.GetRequiredService(type));
                        var message    = Encoding.UTF8.GetString(args.Body);

                        await subscriber.Handle(message);
                    }
                }
            }
            catch (Exception ex)
            {
                SentrySdk.CaptureException(ex);
            }
        }