Пример #1
0
        private void HandleMessage(string content, string queue)
        {
            try
            {
                var commandType = TypeProvider.GetTypeFromAnyReferencingAssembly(queue);

                // deserialize event
                var command = JsonConvert.DeserializeObject(content, commandType);

                using (var scope = serviceProvider.CreateScope())
                {
                    var commandBus =
                        scope.ServiceProvider.GetRequiredService <ICommandBus>();

                    // publish event to internal event bus
                    commandBus.Send(command as ICommand);
                }
            }
            catch (Exception e)
            {
                _logger.LogInformation("Error consuming message: " + e.Message + e.StackTrace);
            }
            // we just print this message
            _logger.LogInformation($"consumer received {content}");
        }
Пример #2
0
        private async Task ConsumeNextEvent(IConsumer <string, string> consumer, CancellationToken cancellationToken)
        {
            try
            {
                //lol ^_^ - remove this hack when this GH issue is solved: https://github.com/dotnet/extensions/issues/2149#issuecomment-518709751
                await Task.Yield();

                // wait for the upcoming message, consume it when arrives
                var message = consumer.Consume(cancellationToken);

                // get event type from name storred in message.Key
                var eventType = TypeProvider.GetTypeFromAnyReferencingAssembly(message.Message.Key);

                // deserialize event
                var @event = JsonConvert.DeserializeObject(message.Message.Value, eventType);

                using (var scope = serviceProvider.CreateScope())
                {
                    var eventBus =
                        scope.ServiceProvider.GetRequiredService <IEventBus>();

                    // publish event to internal event bus
                    await eventBus.Publish(@event as IEvent, cancellationToken);
                }
            }
            catch (Exception e)
            {
                logger.LogInformation("Error consuming message: " + e.Message + e.StackTrace);
            }
        }
Пример #3
0
        private async Task ConsumeNextEvent(IConsumer <string, string> consumer, CancellationToken cancellationToken)
        {
            try
            {
                // wait for the upcoming message, consume it when arrives
                var message = consumer.Consume(cancellationToken);

                // get event type from name storred in message.Key
                var eventType = TypeProvider.GetTypeFromAnyReferencingAssembly(message.Key);

                // deserialize event
                var @event = JsonConvert.DeserializeObject(message.Value, eventType);

                using (var scope = serviceProvider.CreateScope())
                {
                    var eventBus =
                        scope.ServiceProvider.GetRequiredService <IEventBus>();

                    // publish event to internal event bus
                    await eventBus.Publish(@event as IEvent);
                }
            }
            catch (Exception e)
            {
                logger.LogInformation("Error consuming message: " + e.Message + e.StackTrace);
            }
        }