async Task RunAsyncHandler(IAsyncMessageHandler handler, string message, string routingKey)
        {
            _logger.LogDebug($"Starting processing the message by async message handler {handler?.GetType().Name}.");
            await handler.Handle(message, routingKey);

            _logger.LogDebug($"The message has been processed by async message handler {handler?.GetType().Name}.");
        }
Example #2
0
            public IDisposable Subscribe(TKey key, IAsyncMessageHandler <TMessage> handler)
            {
                var subscriptionKey = handlers.Add(handler);
                var subscription    = new Subscription(key, subscriptionKey, this);

                core.diagnotics.IncrementSubscribe(this, subscription);
                return(subscription);
            }
Example #3
0
        private async Task RunAsyncMessageHandler(IAsyncMessageHandler handler, BasicDeliverEventArgs eventArgs, string matchingRoute)
        {
            ValidateMessageHandler(handler);
            _logger.LogDebug($"Starting processing the message by async message handler {handler.GetType().Name}");
            await handler.Handle(eventArgs, matchingRoute);

            _logger.LogDebug($"The message has been processed by async message handler {handler.GetType().Name}");
        }
Example #4
0
 public async ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken)
 {
     if (IsValueType || lastMessage != null)
     {
         await handler.HandleAsync(lastMessage !, cancellationToken);
     }
     return(core.Subscribe(handler));
 }
Example #5
0
        private async Task RunAsyncMessageHandler(IAsyncMessageHandler handler, MessageHandlingContext context, string matchingRoute)
        {
            ValidateMessageHandler(handler);
            _loggingService.LogDebug($"Starting processing the message by async message handler {handler.GetType().Name}");
            await handler.Handle(context, matchingRoute);

            _loggingService.LogDebug($"The message has been processed by async message handler {handler.GetType().Name}");
        }
Example #6
0
        public FilterAttachedAsyncMessageHandler(IAsyncMessageHandler <T> body, IEnumerable <AsyncMessageHandlerFilter <T> > filters)
        {
            Func <T, CancellationToken, ValueTask> next = body.HandleAsync;

            foreach (var f in filters.OrderByDescending(x => x.Order))
            {
                next = new AsyncMessageHandlerFilterRunner <T>(f, next).GetDelegate();
            }

            this.handler = next;
        }
Example #7
0
        public IAsyncMessageHandler <TMessage> CreateAsyncMessageHandler <TMessage>(IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters)
        {
            var(globalLength, globalFilters)   = options.GetGlobalAsyncMessageHandlerFilters(provider, typeof(TMessage));
            var(handlerLength, handlerFilters) = filterProvider.GetAttributeFilters(handler.GetType(), provider);

            if (filters.Length != 0 || globalLength != 0 || handlerLength != 0)
            {
                handler = new FilterAttachedAsyncMessageHandler <TMessage>(handler, globalFilters.Concat(handlerFilters).Concat(filters).Cast <AsyncMessageHandlerFilter <TMessage> >());
            }

            return(handler);
        }
Example #8
0
        public IDisposable Subscribe(IAsyncMessageHandler <TMessage> handler)
        {
            lock (gate)
            {
                if (isDisposed)
                {
                    return(handlingSubscribeDisposedPolicy.Handle(nameof(AsyncMessageBrokerCore <TMessage>)));
                }

                var subscriptionKey = handlers.Add(handler);
                var subscription    = new Subscription(this, subscriptionKey);
                diagnotics.IncrementSubscribe(this, subscription);
                return(subscription);
            }
        }
Example #9
0
        public async ValueTask <IAsyncDisposable> SubscribeAsync(TKey key, IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken)
        {
            handler = asyncMessageHandlerFactory.CreateAsyncMessageHandler(handler, filters); // with filter

            var channel = CreateChannel(key);

            var mq = await connectionFactory.GetConnectionMultiplexer(key).GetSubscriber().SubscribeAsync(channel).ConfigureAwait(false);

            mq.OnMessage(async message =>
            {
                var v = serializer.Deserialize <TMessage>((byte[])message.Message);
                await handler.HandleAsync(v, CancellationToken.None).ConfigureAwait(false);
            });

            return(new Subscription(mq));
        }
Example #10
0
        public IDisposable Subscribe(TKey key, IAsyncMessageHandler <TMessage> handler)
        {
            lock (gate)
            {
                if (isDisposed)
                {
                    return(handlingSubscribeDisposedPolicy.Handle(nameof(AsyncMessageBrokerCore <TKey, TMessage>)));
                }

                if (!handlerGroup.TryGetValue(key, out var holder))
                {
                    handlerGroup[key] = holder = new HandlerHolder(this);
                }

                return(holder.Subscribe(key, handler));
            }
        }
Example #11
0
 public IDisposable Subscribe(IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters)
 {
     return(core.Subscribe(handlerFactory.CreateAsyncMessageHandler(handler, filters)));
 }
        public ValueTask <IAsyncDisposable> SubscribeAsync(TKey key, IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken = default)
        {
            var d = subscriber.Subscribe(key, handler);

            return(new ValueTask <IAsyncDisposable>(new AsyncDisposableBridge(d)));
        }
Example #13
0
 public ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken)
 {
     return(SubscribeAsync(handler, Array.Empty <AsyncMessageHandlerFilter <TMessage> >(), cancellationToken));
 }
Example #14
0
 public IDisposable Subscribe(TKey key, IAsyncMessageHandler <TMessage> handler, params AsyncMessageHandlerFilter <TMessage>[] filters)
 {
     return(core.Subscribe(key, handlerFactory.CreateAsyncMessageHandler(handler, filters)));
 }
Example #15
0
 public ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken)
 {
     handler = handlerFactory.CreateAsyncMessageHandler(handler, filters);
     return(core.SubscribeAsync(handler, cancellationToken));
 }
Example #16
0
        public UniTask <IAsyncDisposable> SubscribeAsync(TKey key, IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken = default)
        {
            var d = subscriber.Subscribe(key, handler, filters);

            return(new UniTask <IAsyncDisposable>(new AsyncDisposableBridge(d)));
        }
Example #17
0
        public void Unsubscribe <T>(IAsyncMessageHandler <T> handler)
        {
            var evntType = typeof(T);

            Unsubscribe(handler, evntType);
        }