コード例 #1
0
    public static IServiceCollection AddGateway <TSubscription, TSubscriptionOptions, TProducer, TProduceOptions>(
        this IServiceCollection services,
        string subscriptionId,
        RouteAndTransform <TProduceOptions> routeAndTransform,
        Action <TSubscriptionOptions>?configureSubscription = null,
        Action <SubscriptionBuilder <TSubscription, TSubscriptionOptions> >?configureBuilder = null,
        bool awaitProduce = true
        )
        where TSubscription : EventSubscription <TSubscriptionOptions>
        where TProducer : class, IEventProducer <TProduceOptions>
        where TProduceOptions : class
        where TSubscriptionOptions : SubscriptionOptions
    {
        services.AddSubscription <TSubscription, TSubscriptionOptions>(
            subscriptionId,
            builder => {
            builder.Configure(configureSubscription);
            configureBuilder?.Invoke(builder);

            builder.AddEventHandler(
                sp => new GatewayHandler <TProduceOptions>(
                    new GatewayProducer <TProduceOptions>(sp.GetRequiredService <TProducer>()),
                    routeAndTransform,
                    awaitProduce
                    )
                );
        }
            );

        return(services);
    }
コード例 #2
0
ファイル: ShovelService.cs プロジェクト: paulopez78/eventuous
 public ShovelHandler(
     string subscriptionId,
     TProducer eventProducer,
     RouteAndTransform transform
     )
 {
     _eventProducer = eventProducer;
     _transform     = transform;
     SubscriptionId = subscriptionId;
 }
コード例 #3
0
 public GatewayHandler(
     IEventProducer <TProduceOptions> eventProducer,
     RouteAndTransform <TProduceOptions> transform,
     bool awaitProduce
     )
 {
     _eventProducer = eventProducer;
     _transform     = transform;
     _awaitProduce  = awaitProduce;
 }
コード例 #4
0
ファイル: ShovelService.cs プロジェクト: paulopez78/eventuous
        /// <summary>
        /// Creates a shovel service instance, which must be registered as a hosted service
        /// </summary>
        /// <param name="subscriptionId">Shovel subscription id</param>
        /// <param name="eventSerializer">Event serializer</param>
        /// <param name="createSubscription">Function to create a subscription</param>
        /// <param name="producer">Producer instance</param>
        /// <param name="routeAndTransform">Routing and transformation function</param>
        /// <param name="loggerFactory">Logger factory</param>
        /// <param name="measure">Subscription gap measurement</param>
        public ShovelService(
            string subscriptionId,
            IEventSerializer eventSerializer,
            CreateSubscription createSubscription,
            TProducer producer,
            RouteAndTransform routeAndTransform,
            ILoggerFactory?loggerFactory   = null,
            SubscriptionGapMeasure?measure = null
            )
        {
            _producer = Ensure.NotNull(producer, nameof(producer));

            _subscription = createSubscription(
                Ensure.NotEmptyString(subscriptionId, nameof(subscriptionId)),
                Ensure.NotNull(eventSerializer, nameof(eventSerializer)),
                new[] {
                new ShovelHandler <TProducer>(subscriptionId, producer, Ensure.NotNull(routeAndTransform, nameof(routeAndTransform)))
            },
                loggerFactory,
                measure
                );
        }