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}."); }
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); }
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}"); }
public async ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken) { if (IsValueType || lastMessage != null) { await handler.HandleAsync(lastMessage !, cancellationToken); } return(core.Subscribe(handler)); }
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}"); }
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; }
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); }
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); } }
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)); }
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)); } }
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))); }
public ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken) { return(SubscribeAsync(handler, Array.Empty <AsyncMessageHandlerFilter <TMessage> >(), cancellationToken)); }
public IDisposable Subscribe(TKey key, IAsyncMessageHandler <TMessage> handler, params AsyncMessageHandlerFilter <TMessage>[] filters) { return(core.Subscribe(key, handlerFactory.CreateAsyncMessageHandler(handler, filters))); }
public ValueTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken) { handler = handlerFactory.CreateAsyncMessageHandler(handler, filters); return(core.SubscribeAsync(handler, cancellationToken)); }
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))); }
public void Unsubscribe <T>(IAsyncMessageHandler <T> handler) { var evntType = typeof(T); Unsubscribe(handler, evntType); }