public PipelineGlobalInboxContextTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.Register <MyCommand, MyGlobalInboxCommandHandler>(); var container = new ServiceCollection(); container.AddTransient <MyGlobalInboxCommandHandler>(); container.AddSingleton <IAmAnInboxSync>(_inbox); container.AddTransient <UseInboxHandler <MyCommand> >(); container.AddSingleton <IBrighterOptions>(new BrighterOptions() { HandlerLifetime = ServiceLifetime.Transient }); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration( scope: InboxScope.All, context: (handlerType) => CONTEXT_KEY); _chainBuilder = new PipelineBuilder <MyCommand>(registry, (IAmAHandlerFactorySync)handlerFactory, _inboxConfiguration); PipelineBuilder <MyCommand> .ClearPipelineCache(); }
public PipelineGlobalInboxWhenUseInboxAsyncTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.RegisterAsync <MyCommand, MyCommandInboxedHandlerAsync>(); var container = new ServiceCollection(); container.AddTransient <MyCommandInboxedHandlerAsync>(); container.AddSingleton <IAmAnInboxAsync>((IAmAnInboxAsync)_inbox); container.AddTransient <UseInboxHandlerAsync <MyCommand> >(); container.AddSingleton <IBrighterOptions>(new BrighterOptions() { HandlerLifetime = ServiceLifetime.Transient }); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration( scope: InboxScope.All, onceOnly: true, actionOnExists: OnceOnlyAction.Throw); _chainBuilder = new PipelineBuilder <MyCommand>(registry, (IAmAHandlerFactoryAsync)handlerFactory, _inboxConfiguration); }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="asyncMessageProducer">The messaging gateway that supports async/await.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="outboxWriteTimeout">How long to wait when writing to the outbox</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> /// <param name="useInbox">Do we want to create an inbox globally i.e. on every handler (as opposed to by hand). Defaults to null, by hand</param> public MessagingConfiguration( IAmAMessageProducerAsync asyncMessageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int outboxWriteTimeout = 300, int messagingGatewaySendTimeout = 300, InboxConfiguration useInbox = null ) { MessageProducerAsync = asyncMessageProducer; MessageMapperRegistry = messageMapperRegistry; OutboxWriteTimeout = outboxWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; UseInbox = useInbox; }
public CommandProcessorBuildDefaultInboxPublishAsyncTests() { var handler = new MyEventHandlerAsync(new Dictionary <string, Guid>()); var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.RegisterAsync <MyEvent, MyEventHandlerAsync>(); var container = new ServiceCollection(); container.AddSingleton <MyEventHandlerAsync>(handler); container.AddSingleton <IAmAnInboxAsync>(_inbox); container.AddTransient <UseInboxHandlerAsync <MyEvent> >(); container.AddSingleton <IBrighterOptions>(new BrighterOptions() { HandlerLifetime = ServiceLifetime.Transient }); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); var retryPolicy = Policy .Handle <Exception>() .RetryAsync(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="outboxWriteTimeout">How long to wait when writing to the outbox</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> /// <param name="responseChannelFactory">in a request-response scenario how do we build response pipelie</param> /// <param name="useInbox">Do we want to create an inbox globally i.e. on every handler (as opposed to by hand). Defaults to null, ,by hand</param> public MessagingConfiguration( IAmAMessageProducer messageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int outboxWriteTimeout = 300, int messagingGatewaySendTimeout = 300, IAmAChannelFactory responseChannelFactory = null, InboxConfiguration useInbox = null ) { MessageProducer = messageProducer; MessageMapperRegistry = messageMapperRegistry; OutboxWriteTimeout = outboxWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; ResponseChannelFactory = responseChannelFactory; UseInbox = useInbox; }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="outboxAsync">The OutBox which supports async/await.</param> /// <param name="asyncmessageProducer">The messaging gateway that supports async/await.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="messageStoreWriteTimeout">How long to wait when writing to the message store</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> /// <param name="useInbox">Do we want to create an inbox globally i.e. on every handler (as opposed to by hand). Defaults to null, by hand</param> public MessagingConfiguration( IAmAnOutboxAsync <Message> outboxAsync, IAmAMessageProducerAsync asyncmessageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int messageStoreWriteTimeout = 300, int messagingGatewaySendTimeout = 300, InboxConfiguration useInbox = null ) { OutboxAsync = outboxAsync; MessageProducerAsync = asyncmessageProducer; MessageMapperRegistry = messageMapperRegistry; MessageStoreWriteTimeout = messageStoreWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; UseInbox = useInbox; }
public CommandProcessorBuildDefaultInboxSendTests() { var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.Add(typeof(MyCommand), typeof(MyCommandHandler)); var container = new ServiceCollection(); container.AddTransient <MyCommandHandler>(); container.AddSingleton <IAmAnInboxSync, InMemoryInbox>(); container.AddTransient <UseInboxHandler <MyCommand> >(); container.AddSingleton <IBrighterOptions>(new BrighterOptions() { HandlerLifetime = ServiceLifetime.Transient }); _provider = container.BuildServiceProvider(); var handlerFactory = new ServiceProviderHandlerFactory(_provider); var retryPolicy = Policy .Handle <Exception>() .Retry(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); PipelineBuilder <MyCommand> .ClearPipelineCache(); }
public CommandProcessorBuildDefaultInboxPublishTests() { var handler = new MyGlobalInboxEventHandler(new Dictionary <string, Guid>()); var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.Add(typeof(MyEvent), typeof(MyGlobalInboxEventHandler)); var container = new ServiceCollection(); container.AddSingleton <MyGlobalInboxEventHandler>(handler); container.AddSingleton <IAmAnInbox>(_inbox); container.AddSingleton <UseInboxHandler <MyEvent> >(); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); var retryPolicy = Policy .Handle <Exception>() .Retry(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, (IAmAHandlerFactory)handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); PipelineBuilder <MyEvent> .ClearPipelineCache(); }
public PipelineGlobalInboxNoInboxAttributeTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.Register <MyCommand, MyNoInboxCommandHandler>(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); container.Register <IHandleRequests <MyCommand>, MyNoInboxCommandHandler>(); container.Register <IAmAnInbox>(_inbox); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration(); _chainBuilder = new PipelineBuilder <MyCommand>(registry, handlerFactory, _inboxConfiguration); }
public CommandProcessorBuildDefaultInboxSendAsyncTests() { var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>()); var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.RegisterAsync <MyCommand, MyCommandHandlerAsync>(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactoryAsync(container); container.Register <MyCommandHandlerAsync>(handler); container.Register <IAmAnInboxAsync>(_inbox); var retryPolicy = Policy .Handle <Exception>() .RetryAsync(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); }
public PipelineGlobalInboxTestsAsync() { _inbox = new InMemoryInbox(); var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>()); var registry = new SubscriberRegistry(); registry.RegisterAsync <MyCommand, MyCommandHandlerAsync>(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactoryAsync(container); container.Register <MyCommandHandlerAsync>(handler); container.Register <IAmAnInboxAsync>(_inbox); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration(); _chainBuilder = new PipelineBuilder <MyCommand>(registry, handlerFactory, _inboxConfiguration); }
public PipelineGlobalInboxNoInboxAttributeTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.Register <MyCommand, MyNoInboxCommandHandler>(); var container = new ServiceCollection(); container.AddTransient <MyNoInboxCommandHandler>(); container.AddSingleton <IAmAnInbox>(_inbox); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration(); _chainBuilder = new PipelineBuilder <MyCommand>(registry, (IAmAHandlerFactory)handlerFactory, _inboxConfiguration); }
public CommandProcessorBuildDefaultInboxSendTests() { var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.Add(typeof(MyCommand), typeof(MyCommandHandler)); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); container.Register <IHandleRequests <MyCommand>, MyCommandHandler>(); container.Register <IAmAnInbox>(_inbox); var retryPolicy = Policy .Handle <Exception>() .Retry(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); PipelineBuilder <MyCommand> .ClearPipelineCache(); }
/// <summary> /// Uses an external Brighter Inbox to record messages received to allow "once only" or diagnostics (how did we get here?) /// Advantages: by using an external inbox then you can share "once only" across multiple threads/processes and support a competing consumer /// model; an internal inbox is useful for testing but outside of single consumer scenarios won't work as intended /// If not null, registers singletons with the service collecion :- /// - IAmAnInboxSync - what messages have we received /// - IAmAnInboxAsync - what messages have we received (async pipeline compatible) /// </summary> /// <param name="brighterBuilder">Extension method to support a fluent interface</param> /// <param name="inbox">The external inbox to use</param> /// <param name="inboxConfiguration">If this is null, configure by hand, if not, will auto-add inbox to handlers</param> /// <returns></returns> public static IBrighterBuilder UseExternalInbox( this IBrighterBuilder brighterBuilder, IAmAnInbox inbox, InboxConfiguration inboxConfiguration = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { if (inbox is IAmAnInboxSync) { brighterBuilder.Services.Add(new ServiceDescriptor(typeof(IAmAnInboxSync), _ => inbox, serviceLifetime)); } if (inbox is IAmAnInboxAsync) { brighterBuilder.Services.Add(new ServiceDescriptor(typeof(IAmAnInboxAsync), _ => inbox, serviceLifetime)); } if (inboxConfiguration != null) { brighterBuilder.Services.AddSingleton <InboxConfiguration>(inboxConfiguration); } return(brighterBuilder); }
public PipelineGlobalInboxContextTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.Register <MyCommand, MyCommandHandler>(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); container.Register <IHandleRequests <MyCommand>, MyCommandHandler>(); container.Register <IAmAnInbox>(_inbox); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration( scope: InboxScope.All, context: (handlerType) => CONTEXT_KEY); _chainBuilder = new PipelineBuilder <MyCommand>(registry, handlerFactory, _inboxConfiguration); PipelineBuilder <MyCommand> .ClearPipelineCache(); }
public PipelineGlobalInboxWhenUseInboxAsyncTests() { _inbox = new InMemoryInbox(); var registry = new SubscriberRegistry(); registry.RegisterAsync <MyCommand, MyCommandInboxedHandlerAsync>(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactoryAsync(container); container.Register <IHandleRequestsAsync <MyCommand>, MyCommandInboxedHandlerAsync>(); container.Register <IAmAnInboxAsync>((IAmAnInboxAsync)_inbox); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration( scope: InboxScope.All, onceOnly: true, actionOnExists: OnceOnlyAction.Throw); _chainBuilder = new PipelineBuilder <MyCommand>(registry, handlerFactory, _inboxConfiguration); }
private static INeedARequestContext AddExternalBusMaybe( IBrighterOptions options, IAmAProducerRegistry producerRegistry, INeedMessaging messagingBuilder, MessageMapperRegistry messageMapperRegistry, InboxConfiguration inboxConfiguration, IAmAnOutboxSync <Message> outbox, IAmABoxTransactionConnectionProvider overridingConnectionProvider, IUseRpc useRequestResponse) { ExternalBusType externalBusType = GetExternalBusType(producerRegistry, useRequestResponse); if (externalBusType == ExternalBusType.None) { return(messagingBuilder.NoExternalBus()); } else if (externalBusType == ExternalBusType.FireAndForget) { return(messagingBuilder.ExternalBus( new ExternalBusConfiguration(producerRegistry, messageMapperRegistry, useInbox: inboxConfiguration), outbox, overridingConnectionProvider)); } else if (externalBusType == ExternalBusType.RPC) { return(messagingBuilder.ExternalRPC( new ExternalBusConfiguration( producerRegistry, messageMapperRegistry, responseChannelFactory: options.ChannelFactory, useInbox: inboxConfiguration), outbox, useRequestResponse.ReplyQueueSubscriptions)); } throw new ArgumentOutOfRangeException("The external bus type requested was not understood"); }
public PipelineGlobalInboxTestsAsync() { _inbox = new InMemoryInbox(); var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>()); var registry = new SubscriberRegistry(); registry.RegisterAsync <MyCommand, MyCommandHandlerAsync>(); var container = new ServiceCollection(); container.AddSingleton <MyCommandHandlerAsync>(handler); container.AddSingleton <IAmAnInboxAsync>(_inbox); container.AddTransient <UseInboxHandlerAsync <MyCommand> >(); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); _requestContext = new RequestContext(); _inboxConfiguration = new InboxConfiguration(); _chainBuilder = new PipelineBuilder <MyCommand>(registry, (IAmAHandlerFactoryAsync)handlerFactory, _inboxConfiguration); }