/// <summary> /// Classifies the operation's argument. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="plan">The plan.</param> /// <param name="payload">The payload.</param> /// <param name="operation">The operation.</param> /// <param name="argumentName">Name of the argument.</param> /// <param name="producedData">The produced data.</param> /// <returns></returns> private async ValueTask <Bucket> ClassifyArgumentAsync <T>( ProducerPlan plan, Bucket payload, string operation, string argumentName, T producedData) { foreach (var strategy in plan.SegmentationStrategies) { Bucket newSerments = await ClassifyArgumentAsync(strategy, plan.Options, operation, argumentName, producedData); #region Validation if (newSerments == Bucket.Empty) { continue; } #endregion // Validation payload = payload.AddRange(newSerments); } return(payload); }
/// <summary> /// Sends the produced data via the channel. /// </summary> /// <param name="plan">The plan.</param> /// <param name="id">The identifier.</param> /// <param name="payload">The payload.</param> /// <param name="interceptorsData">The interceptors data.</param> /// <param name="operation">The operation.</param> /// <param name="classifyAdaptors">The classify strategy adaptors.</param> /// <returns></returns> private async ValueTask SendAsync( ProducerPlan plan, string id, Bucket payload, Bucket interceptorsData, string operation, Func <ProducerPlan, Bucket, ValueTask <Bucket> >[] classifyAdaptors) { Metadata metadata = new Metadata { MessageId = id, Partition = plan.Partition, Shard = plan.Shard, Operation = operation }; foreach (var classify in classifyAdaptors) { payload = await classify(plan, payload); } interceptorsData = await InterceptAsync( plan.Interceptors, metadata, payload, interceptorsData); var announcement = new Announcement { Metadata = metadata, Segments = payload, InterceptorsData = interceptorsData }; if (plan.Forwards.Count == 0) // merged { await plan.Channel.SendAsync(announcement); return; } foreach (var forward in plan.Forwards) { // merged scenario await SendAsync( forward.Plan, id, payload, interceptorsData, operation, classifyAdaptors); } }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="copyFrom">The copy from.</param> /// <param name="channel">The channel.</param> /// <param name="partition">The partition.</param> /// <param name="shard">The shard.</param> /// <param name="logger">The logger.</param> /// <param name="options">The options.</param> /// <param name="segmentationStrategies">The segmentation strategies.</param> /// <param name="interceptors">The interceptors.</param> /// <param name="routes">The routes.</param> /// <param name="forwards">Result of merging multiple channels.</param> private ProducerPlan( ProducerPlan copyFrom, IProducerChannelProvider?channel = null, string?partition = null, string?shard = null, ILogger?logger = null, IEventSourceOptions?options = null, IImmutableList <IProducerAsyncSegmentationStrategy>?segmentationStrategies = null, IImmutableList <IProducerAsyncInterceptor>?interceptors = null, IImmutableList <IProducerHooksBuilder>?routes = null, IImmutableList <IProducerHooksBuilder>?forwards = null) { Channel = channel ?? copyFrom.Channel; Partition = partition ?? copyFrom.Partition; Shard = shard ?? copyFrom.Shard; Options = options ?? copyFrom.Options; SegmentationStrategies = segmentationStrategies ?? copyFrom.SegmentationStrategies; Interceptors = interceptors ?? copyFrom.Interceptors; Routes = routes ?? copyFrom.Routes; Forwards = forwards ?? copyFrom.Forwards; Logger = logger; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="plan">The plan.</param> public ProducerPipeline(ProducerPlan plan) { _plan = plan; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="plan">The plan.</param> internal ProducerBuilder(ProducerPlan plan) { Plan = plan; }