private static IBusControl CreateUsingRabbitMq(IServiceCollectionConfigurator massTransit, IServiceProvider sp, IEnumerable <Type> messageTypes) { return(Bus.Factory.CreateUsingRabbitMq( bus => { var options = sp.GetRequiredService <IOptions <RabbitMqOptions> >(); var host = bus.Host(new Uri(options.Value.Host), _ => { }); foreach (var messageType in messageTypes) { var queueName = messageType.Name; var consumerType = CreateConsumerType(messageType); bus.ReceiveEndpoint( host, queueName, endpoint => { endpoint.PrefetchCount = 16; endpoint.Consumer(consumerType, sp.GetRequiredService); MapEndpointConvention(messageType, endpoint.InputAddress); }); } })); }
protected override void ConfigureMassTransit(IServiceCollectionConfigurator configurator) { foreach (var messageType in MessageTypes) { configurator.AddConsumer(messageType.CreateConsumerType()); } }
public static void AddSignalRHubConsumers <THub>(this IServiceCollectionConfigurator configurator, Action <IHubLifetimeManagerOptions <THub> > configureHubLifetimeOptions = null) where THub : Hub { var options = new HubLifetimeManagerOptions <THub>(); configureHubLifetimeOptions?.Invoke(options); configurator.Collection.AddSingleton(options); configurator.Collection.AddSingleton(GetLifetimeManager <THub>); configurator.AddRequestClient <GroupManagement <THub> >(options.RequestTimeout); //TODO: check if use options.UseMessageData // Add Registrations for Regular Consumers configurator.AddConsumer <AllConsumer <THub> >(); configurator.AddConsumer <ConnectionConsumer <THub> >(); configurator.AddConsumer <GroupConsumer <THub> >(); configurator.AddConsumer <GroupManagementConsumer <THub> >(); configurator.AddConsumer <UserConsumer <THub> >(); // Add Registrations for Message Data Consumers configurator.AddConsumer <AllMessageDataConsumer <THub> >(); configurator.AddConsumer <ConnectionMessageDataConsumer <THub> >(); configurator.AddConsumer <GroupMessageDataConsumer <THub> >(); configurator.AddConsumer <GroupManagementConsumer <THub> >(); configurator.AddConsumer <UserMessageDataConsumer <THub> >(); }
/// <summary> /// Adds all sagas in the specified assemblies matching the namespace. If you are using both state machine and regular sagas, be /// sure to call AddSagaStateMachinesFromNamespaceContaining prior to calling this one. /// </summary> /// <param name="configurator"></param> /// <param name="type">The type to use to identify the assembly and namespace to scan</param> /// <param name="filter"></param> public static void AddSagaStateMachinesFromNamespaceContaining(this IServiceCollectionConfigurator configurator, Type type, Func <Type, bool> filter = null) { var registrar = new DependencyInjectionSagaStateMachineRegistrar(configurator.Collection); configurator.AddSagaStateMachinesFromNamespaceContaining(registrar, type, filter); }
private static void ConfigServiceBus(IServiceCollectionConfigurator config) { var serviceAddress = new Uri($"{ConstantForAzureServiceBus.ServiceBusUrl}/{Constant.DemoQueueName}"); config.Collection.AddScoped <IRequestClient <ISubmitOrder, IOrderAccepted> >(x => new MessageRequestClient <ISubmitOrder, IOrderAccepted>(x.GetRequiredService <IBus>(), serviceAddress, TimeSpan.FromSeconds(10)) ); }
/// <summary> /// Adds a SagaStateMachine to the registry, using the factory method, and updates the registrar prior to registering so that the default /// saga registrar isn't notified. /// </summary> /// <param name="configurator"></param> /// <typeparam name="TStateMachine"></typeparam> /// <typeparam name="TInstance"></typeparam> public static void AddSagaStateMachine <TStateMachine, TInstance>(this IServiceCollectionConfigurator configurator) where TStateMachine : class, SagaStateMachine <TInstance> where TInstance : class, SagaStateMachineInstance { var registrar = new DependencyInjectionSagaStateMachineRegistrar(configurator.Collection); configurator.AddSagaStateMachine <TStateMachine, TInstance>(registrar); }
public void ConfigureMassTransit(IServiceCollectionConfigurator configurator, IServiceCollection services) { configurator.AddConsumersFromNamespaceContaining <AllocateInventoryConsumer>(); configurator.AddSagaStateMachine <AllocationStateMachine, AllocationState>(typeof(AllocateStateMachineDefinition)) .MongoDbRepository(r => { r.Connection = "mongodb://mongo"; r.DatabaseName = "allocations"; }); }
public static void AddSignalRHubConsumers <THub>(this IServiceCollectionConfigurator configurator) where THub : Hub { configurator.AddRequestClient <GroupManagement <THub> >(TimeSpan.FromSeconds(10)); var consumers = HubConsumersCache.GetOrAdd <THub>(); foreach (var consumer in consumers) { configurator.AddConsumer(consumer); } }
/// <summary> /// Decorates the IPublishEndpoint and ISendEndpointProvider with a Transaction Outbox. Messages will not be /// released/sent until the ambient transaction is committed. This is only meant to be used outside of a consumer. /// If you want an outbox for Consumers, it is recommended to use the InMemoryOutbox. /// </summary> public static void AddTransactionOutbox(this IServiceCollectionConfigurator configurator) { configurator.Collection.TryAddSingleton(provider => { var busControl = provider.GetRequiredService <IBusControl>(); return(new TransactionOutbox(busControl, busControl, provider.GetService <ILoggerFactory>())); }); // This should override the registrations from AddBus, in favor of the TransactionOutbox implementations configurator.Collection.AddSingleton <IPublishEndpoint>(x => x.GetRequiredService <TransactionOutbox>()); configurator.Collection.AddSingleton <ISendEndpointProvider>(x => x.GetRequiredService <TransactionOutbox>()); }
protected override void ConfigureMassTransit(IServiceCollectionConfigurator configurator) { // Configure scheduler service consumers. configurator.AddConsumer <ScheduleMessageConsumer>(); configurator.AddConsumer <CancelScheduledMessageConsumer>(); // configure workflow consumers configurator.AddWorkflowConsumer <CartCreated>(); configurator.AddWorkflowConsumer <CartItemAdded>(); configurator.AddWorkflowConsumer <OrderSubmitted>(); configurator.AddWorkflowConsumer <CartExpiredEvent>(); // host fake service consumers configurator.AddConsumer <CartRemovedConsumer>(); }
public static IServiceCollectionConfigurator ConfigureBus(this IServiceCollectionConfigurator configurator) { configurator.AddBus(context => Bus.Factory.CreateUsingRabbitMq( busFactoryConfigurator => { var host = busFactoryConfigurator.Host("localhost", "sample.api"); // // we could set a consumer here by using ReceiveEndpoint, // // or use the extension method of AddConsumer* on IServiceCollectionConfigurator // // it is also possible to configure endpoint by xDefinitions, e.g. SagaDefinition<T> // // NOT adding a receive endpoint name, publishes the message to all Consumer instances // // Broadcasting Pub/Sub, not Competitive Consumer, the latter will be available if // // Receive endpoint has a name // busFactoryConfigurator.ReceiveEndpoint(host, e => // { // e.UseRetry(r=>r.Exponential(3,TimeSpan.FromMilliseconds(300),TimeSpan.FromMilliseconds(2000), // TimeSpan.FromMilliseconds(100))); // e.UseInMemoryOutbox(); // e.Consumer( // () => new SubmitOrderConsumer(context.Container.GetService<ILogger<SubmitOrderConsumer>>())); // }); // creates queues, sagas and etc. busFactoryConfigurator.ConfigureEndpoints(context); // busFactoryConfigurator.ReceiveEndpoint( // KebabCaseEndpointNameFormatter.Instance.Consumer<RoutingSlipCompletedBatchConsumer>(), // endpoint => // { // // this should be at least the number of MessageLimit, // // otherwise we always get a time limit // endpoint.PrefetchCount = 20; // // endpoint.Batch<RoutingSlipCompleted>(b => // { // b.MessageLimit = 10; // b.TimeLimit = TimeSpan.FromSeconds(5); // // b.Consumer<RoutingSlipCompletedBatchConsumer, RoutingSlipCompleted>( // context.Container); // }); // }); })); return(configurator); }
private void ConfigureBus(IServiceCollectionConfigurator configurator) { configurator.AddConsumer <ProductAddedToOrderConsumer>(); configurator.AddConsumer <ProductQuantityChangedConsumer>(); configurator.AddConsumer <CommandErrorConsumer>(); configurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg => { var busConfig = Configuration.GetSection("Bus"); var host = cfg.ConfigureHost(busConfig); cfg.ReceiveEndpoint(host, "UISubscriptions", e => { e.ConfigureConsumer <ProductAddedToOrderConsumer>(provider); e.ConfigureConsumer <ProductQuantityChangedConsumer>(provider); e.ConfigureConsumer <CommandErrorConsumer>(provider); }); })); }
public static void AddSignalRHubConsumers <THub>(this IServiceCollectionConfigurator configurator) where THub : Hub { // Add Registrations for Regular Consumers configurator.AddConsumer <AllConsumer <THub> >(); configurator.AddConsumer <ConnectionConsumer <THub> >(); configurator.AddConsumer <GroupConsumer <THub> >(); configurator.AddConsumer <GroupManagementConsumer <THub> >(); configurator.AddConsumer <UserConsumer <THub> >(); // Add Registrations for Message Data Consumers configurator.AddConsumer <AllMessageDataConsumer <THub> >(); configurator.AddConsumer <ConnectionMessageDataConsumer <THub> >(); configurator.AddConsumer <GroupMessageDataConsumer <THub> >(); configurator.AddConsumer <GroupManagementConsumer <THub> >(); configurator.AddConsumer <UserMessageDataConsumer <THub> >(); }
public static IServiceCollectionConfigurator ConfigureBus(this IServiceCollectionConfigurator configurator) { configurator.AddBus(context => Bus.Factory.CreateUsingRabbitMq( busFactoryConfigurator => { var host = busFactoryConfigurator.Host("localhost", "sample.api"); // when using scheduler this line should be added busFactoryConfigurator.UseMessageScheduler(new Uri("queue:quartz-scheduler")); busFactoryConfigurator.ConfigureEndpoints(context); })); return(configurator); }
public static void AddSignalRHub <THub>(this IServiceCollectionConfigurator configurator, Action <IHubLifetimeManagerOptions <THub> > configureHubLifetimeOptions = null) where THub : Hub { var options = new HubLifetimeManagerOptions <THub>(); configureHubLifetimeOptions?.Invoke(options); configurator.Collection.TryAddSingleton <IHubLifetimeScopeProvider, DependencyInjectionHubLifetimeScopeProvider>(); configurator.Collection.AddSingleton(provider => GetMassTransitHubLifetimeManager(provider, options)); configurator.Collection.AddSingleton <HubLifetimeManager <THub> >(sp => sp.GetRequiredService <MassTransitHubLifetimeManager <THub> >()); configurator.AddRequestClient <GroupManagement <THub> >(options.RequestTimeout); RegisterConsumers <THub>(configurator); }
static void RegisterConsumers <THub>(IServiceCollectionConfigurator configurator) where THub : Hub { configurator.Collection.AddSingleton <HubConsumerDefinition <THub> >(); configurator.Collection.TryAddSingleton <IConsumerDefinition <AllConsumer <THub> >, AllConsumerDefinition <THub> >(); configurator.Collection.TryAddSingleton <IConsumerDefinition <ConnectionConsumer <THub> >, ConnectionConsumerDefinition <THub> >(); configurator.Collection.TryAddSingleton <IConsumerDefinition <GroupConsumer <THub> >, GroupConsumerDefinition <THub> >(); configurator.Collection.TryAddSingleton <IConsumerDefinition <GroupManagementConsumer <THub> >, GroupManagementConsumerDefinition <THub> >(); configurator.Collection.TryAddSingleton <IConsumerDefinition <UserConsumer <THub> >, UserConsumerDefinition <THub> >(); configurator.AddConsumer <AllConsumer <THub> >(); configurator.AddConsumer <ConnectionConsumer <THub> >(); configurator.AddConsumer <GroupConsumer <THub> >(); configurator.AddConsumer <GroupManagementConsumer <THub> >(); configurator.AddConsumer <UserConsumer <THub> >(); }
public void ConfigureMassTransit(IServiceCollectionConfigurator configurator, IServiceCollection services) { services.AddScoped <AcceptOrderActivity>(); configurator.AddConsumersFromNamespaceContaining <SubmitOrderConsumer>(); configurator.AddActivitiesFromNamespaceContaining <AllocateInventoryActivity>(); configurator.AddConsumersFromNamespaceContaining <RoutingSlipBatchEventConsumer>(); configurator.AddSagaStateMachine <OrderStateMachine, OrderState>(typeof(OrderStateMachineDefinition)) .MongoDbRepository(r => { r.Connection = "mongodb://mongo"; r.DatabaseName = "orders"; }); configurator.AddRequestClient <AllocateInventory>(); }
private void ConfigureBus(IServiceCollectionConfigurator configurator) { configurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg => { var busConfig = Configuration.GetSection("Bus"); var host = cfg.ConfigureHost(busConfig); cfg.ConfigureSend(sendPipe => { sendPipe.UseSendFilter(new OperationContextEstablisher()); }); EndpointConvention.Map <AddProductToOrder>(new Uri(new Uri(busConfig["Host"]), nameof(AddProductToOrder))); EndpointConvention.Map <CancelOrder>(new Uri(new Uri(busConfig["Host"]), nameof(CancelOrder))); EndpointConvention.Map <PlaceOrder>(new Uri(new Uri(busConfig["Host"]), nameof(PlaceOrder))); EndpointConvention.Map <RemoveProduct>(new Uri(new Uri(busConfig["Host"]), nameof(RemoveProduct))); EndpointConvention.Map <SetProductQuantity>(new Uri(new Uri(busConfig["Host"]), nameof(SetProductQuantity))); EndpointConvention.Map <StartDelivery>(new Uri(new Uri(busConfig["Host"]), nameof(StartDelivery))); EndpointConvention.Map <ReturnOrder>(new Uri(new Uri(busConfig["Host"]), nameof(ReturnOrder))); EndpointConvention.Map <DeliverOrder>(new Uri(new Uri(busConfig["Host"]), nameof(DeliverOrder))); })); }
private static void ConfigureMassTransit(IServiceCollectionConfigurator configurator) { configurator.AddConsumer <CustomerDisabledConsumer>(); configurator.AddConsumer <NewCustomerRegisteredConsumer>(); }
private static void ConfigureMasstransit(IServiceCollectionConfigurator cfg) { }
/// <summary> /// Adds all sagas in the specified assemblies matching the namespace. If you are using both state machine and regular sagas, be /// sure to call AddSagaStateMachinesFromNamespaceContaining prior to calling this one. /// </summary> /// <param name="configurator"></param> /// <typeparam name="T">The anchor type</typeparam> public static void AddSagaStateMachinesFromNamespaceContaining <T>(this IServiceCollectionConfigurator configurator) { var registrar = new DependencyInjectionSagaStateMachineRegistrar(configurator.Collection); configurator.AddSagaStateMachinesFromNamespaceContaining(registrar, typeof(T)); }
/// <summary> /// Registers <see cref="Consumer{IWebHookNotification}"/> as a endpoint receiving <see cref="IWebHookNotification"/>, allowing for receiving and treating <see cref="IWebHookNotification"/> from other applications /// </summary> /// <param name="x"></param> /// <param name="configure"></param> /// <returns></returns> public static IServiceCollectionConfigurator ReceiveNotificationsUsingMassTransit(this IServiceCollectionConfigurator x, Action <IConsumerConfigurator <Consumer <IWebHookNotification> > > configure = null) { x.AddConsumer(configure); return(x); }
/// <summary> /// Adds SagaStateMachines to the registry, using the factory method, and updates the registrar prior to registering so that the default /// saga registrar isn't notified. /// </summary> /// <param name="configurator"></param> /// <param name="types">The state machine types to add</param> public static void AddSagaStateMachines(this IServiceCollectionConfigurator configurator, params Type[] types) { var registrar = new DependencyInjectionSagaStateMachineRegistrar(configurator.Collection); configurator.AddSagaStateMachines(registrar, types); }
/// <summary> /// Registers every services allowing for a pipeline to treat webhooks via a messaging service. /// Some configuration that require a <see cref="IHarpoonBuilder"/> and/or a <see cref="IBusFactoryConfigurator"/> might still be needed. /// </summary> /// <param name="x"></param> /// <returns></returns> public static IServiceCollectionConfigurator UseAllMassTransitDefaults(this IServiceCollectionConfigurator x) { return(x.ReceiveNotificationsUsingMassTransit() .ReceiveWebHookWorkItemsUsingMassTransit()); }
protected abstract void ConfigureMassTransit(IServiceCollectionConfigurator configurator);
public static void AddSignalRHubConsumers <THub>(this IServiceCollectionConfigurator configurator, Action <IHubLifetimeManagerOptions <THub> > configureHubLifetimeOptions = null) where THub : Hub { configurator.AddSignalRHub(configureHubLifetimeOptions); }
/// <summary> /// Registers <see cref="Consumer{IWebHookWorkItem}"/> as a endpoint receiving <see cref="IWebHookWorkItem"/>, allowing for receiving and treating <see cref="IWebHookWorkItem"/> from other applications /// </summary> /// <param name="x"></param> /// <param name="configure"></param> /// <returns></returns> public static IServiceCollectionConfigurator ReceiveWebHookWorkItemsUsingMassTransit(this IServiceCollectionConfigurator x, Action <IConsumerConfigurator <Consumer <IWebHookWorkItem> > >?configure = null) { x.AddConsumer(configure); return(x); }
private static void ConfigServiceBus(IServiceCollectionConfigurator configurator) { //allow consumer and producer to be able to use in DI configurator.AddConsumer <OrderConsumer>(); }
protected virtual void ConfigureMasstransit(IServiceCollectionConfigurator cfg) { }
public void ConfigureMassTransit(IServiceCollectionConfigurator configurator, IServiceCollection services) { configurator.AddConsumer <SampleConsumer>(); }