/// <summary> /// Responsible of building instance from segmented data. /// Segmented data is how the producer sending its raw data to /// the consumer. It's in a form of dictionary when /// keys represent the different segments /// and the value represent serialized form of the segment's data. /// </summary> /// <param name="segmentationStrategy">The segmentation strategy.</param> /// <returns></returns> /// <example> /// Examples for segments can be driven from regulation like /// GDPR (personal, non-personal data), /// Technical vs Business aspects, etc. /// </example> IConsumerHooksBuilder IConsumerHooksBuilder.RegisterSegmentationStrategy(IConsumerSegmentationStrategy segmentationStrategy) { var bridge = new ConsumerSegmentationStrategyBridge(segmentationStrategy); var prms = _plan.AddSegmentation(bridge); var result = new ConsumerBuilder(prms); return(result); }
/// <summary> /// Subscribe consumer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory">The factory.</param> /// <param name="consumerGroup"> /// Consumer Group allow a group of clients to cooperate /// consuming a different portion of the same stream of messages /// </param> /// <param name="consumerName"> /// Optional Name of the consumer. /// Can use for observability. /// </param> /// <returns> /// The partition subscription (dispose to remove the subscription) /// </returns> IConsumerLifetime IConsumerSubscribeBuilder.Subscribe <T>( Func <ConsumerMetadata, T> factory, string?consumerGroup, string?consumerName) { #region Validation if (_plan == null) { throw new ArgumentNullException(nameof(_plan)); } #endregion // Validation consumerGroup = consumerGroup ?? $"{DateTime.UtcNow:yyyy-MM-dd HH_mm} {Guid.NewGuid():N}"; ConsumerPlan plan = _plan.WithConsumerGroup(consumerGroup, consumerName); if (plan.SegmentationStrategies.Count == 0) { plan = plan.AddSegmentation(new ConsumerDefaultSegmentationStrategy()); } var consumer = new ConsumerBase <T>(plan, factory); var subscription = consumer.Subscribe(); return(subscription); }