public async Task <IPipeContext> InvokeAsync(Action <IPipeBuilder> pipeCfg, Action <IPipeContext> contextCfg = null, CancellationToken token = default(CancellationToken)) { var pipe = _pipeBuilderFactory.Create(pipeCfg); var context = _contextFactory.CreateContext(); contextCfg?.Invoke(context); await pipe.InvokeAsync(context, token); return(context); }
protected virtual async Task InvokeConsumePipeAsync(IPipeContext context, BasicDeliverEventArgs args, CancellationToken token) { _logger.Debug("Invoking consumer pipe for message {messageId}", args?.BasicProperties?.MessageId); var consumeContext = ContextFactory.CreateContext(context.Properties.ToArray()); consumeContext.Properties.Add(PipeKey.DeliveryEventArgs, args); try { await ConsumePipe.InvokeAsync(consumeContext, token); } catch (Exception e) { _logger.Error(e, "An unhandled exception was thrown when consuming message with routing key {routingKey}", args.RoutingKey); throw; } }
PipeContextHandle <TContext> GetContext() { lock (_contextLock) { if (_context != null && _context.IsDisposed == false) { return(_context); } PipeContextHandle <TContext> context = _context = _contextFactory.CreateContext(this); void ClearContext(Task task) { Interlocked.CompareExchange(ref _context, null, context); } context.Context.ContinueWith(ClearContext, CancellationToken.None, TaskContinuationOptions.NotOnRanToCompletion, TaskScheduler.Default); SetReady(context.Context); return(context); } }