コード例 #1
0
 public MessageHandlerDescriptor(IMessageHandlerAsync <T> handler, Type type)
 {
     _handle = p =>
               Task.Run(async() => await handler.HandleAsync(p).ConfigureAwait(false))
               .Wait(TimeSpan.FromSeconds(30));
     ParameterType = type;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueCreationDecorator" /> class.
 /// </summary>
 /// <param name="metrics">The metrics factory.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="connectionInformation">The connection information.</param>
 public MessageHandlerAsyncDecorator(IMetrics metrics,
     IMessageHandlerAsync handler,
     IConnectionInformation connectionInformation)
 {
     var name = handler.GetType().Name;
     _runCodeTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.HandleTimer", Units.Calls);
     _handler = handler;
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandleMessage" /> class.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="messageHandlerAsync">The message handler asynchronous.</param>
        public HandleMessage(IMessageHandler messageHandler,
                             IMessageHandlerAsync messageHandlerAsync)
        {
            Guard.NotNull(() => messageHandler, messageHandler);
            Guard.NotNull(() => messageHandlerAsync, messageHandlerAsync);

            _messageHandler      = messageHandler;
            _messageHandlerAsync = messageHandlerAsync;
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueCreationDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public MessageHandlerAsyncDecorator(IMetrics metrics,
                                            IMessageHandlerAsync handler,
                                            IConnectionInformation connectionInformation)
        {
            var name = "MessageHandlerAsync";

            _runCodeTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.HandleTimer", Units.Calls);
            _handler      = handler;
        }
コード例 #5
0
        private IMessageHandlerAsync <T> Decorate <T>(IMessageHandlerAsync <T> messageHandler) where T : IMessage
        {
#if DEBUG
            return(new SuppressAsyncExceptionDecorator <T>(
                       new DebugShowErrorMessageDecorator <T>(
                           new DebugShowDurationMessageDecorator <T>(new PerLoggerMessageDecorator <T>(messageHandler),
                                                                     _sessionManager), _sessionManager),
                       _logger));
#else
            return(new SuppressAsyncExceptionDecorator <T>(new PerLoggerMessageDecorator <T>(messageHandler), _logger));
#endif
        }
コード例 #6
0
 public RabbitMQListenerServiceAsync(
     IHostApplicationLifetime appLifetime,
     ILogger <RabbitMQListenerServiceAsync <T> > logger,
     IMessageHandlerAsync <T> messageHandler,
     IOptionsMonitor <RabbitMQOptions> options)
 {
     _appLifetime    = appLifetime;
     _logger         = logger;
     _messageHandler = messageHandler;
     _options        = options.CurrentValue;
     if (string.IsNullOrWhiteSpace(_options.ConnectionString))
     {
         _logger.LogError("RabbitMQ connection string is missing.");
         throw new Exception("Missing connection string.");
     }
 }
コード例 #7
0
 public DebugShowErrorMessageDecorator(IMessageHandlerAsync <T> decorated,
                                       ISessionManager sessionManager)
 {
     _decorated           = decorated;
     _debugMessageManager = new DebugMessageManager(sessionManager);
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageHandlerAsyncDecorator"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="tracer">The tracer.</param>
 /// <param name="headers">The headers.</param>
 public MessageHandlerAsyncDecorator(IMessageHandlerAsync handler, ITracer tracer, IHeaders headers)
 {
     _handler = handler;
     _tracer  = tracer;
     _headers = headers;
 }
 public SuppressAsyncExceptionDecorator(IMessageHandlerAsync <T> decorated, ILogger logger)
 {
     _decorated = decorated;
     _logger    = logger;
 }
コード例 #10
0
 public PerLoggerMessageDecorator(IMessageHandlerAsync <T> decorated)
 {
     _decorated = decorated;
 }
コード例 #11
0
 public void Subscribe <T>(IMessageHandlerAsync <T> handler) where T : IMessage
 {
     _handlers.Add(new MessageHandlerDescriptor <T>(handler, typeof(T)));
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageHandlerAsyncDecorator"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="tracer">The tracer.</param>
 /// <param name="headers">The headers.</param>
 public MessageHandlerAsyncDecorator(IMessageHandlerAsync handler, ActivitySource tracer, IHeaders headers)
 {
     _handler = handler;
     _tracer  = tracer;
     _headers = headers;
 }
コード例 #13
0
 public static IMediator SubscribeAsync <TMessage>(this IMediator mediator, IMessageHandlerAsync <TMessage> handler)
 => mediator.SubscribeAsync <TMessage>(message => handler.Handle(message));