public IRecieveOnlyBus RegisterTopic <T>(string route, HandlerConfiguration config = null) { routes.AddRoute <T>(route); var handlers = container.GetAllInstances <ITopicMessageHandler <T> >(); var handlerConfiguration = config ?? new HandlerConfiguration(); foreach (var handler in handlers) { var client = new SubscriptionClient(configuration.ConnectionString, route, handler.Subscription); client.RegisterMessageHandler((message, token) => handler.Handle(message, client, token), handlerConfiguration.Options(handler.OnException)); if (topicClients.ContainsKey(route)) { topicClients[route].Add(client); } else { topicClients.Add(route, new List <IClientEntity> { client }); } } return(this); }
void DoSequenceOrParallelOrAdd(IActivityMonitor monitor, Action <ActionConfiguration> collector, XElement xml) { if (xml.Name == "Parallel" || xml.Name == "Sequence") { Action <ActionConfiguration> elementCollector; if (xml.Name == "Parallel") { var p = new ActionParallelConfiguration(xml.AttributeRequired("Name").Value); elementCollector = a => p.AddAction(a); collector(p); } else { var s = new ActionSequenceConfiguration(xml.AttributeRequired("Name").Value); elementCollector = a => s.AddAction(a); collector(s); } foreach (var action in xml.Elements()) { DoSequenceOrParallelOrAdd(monitor, collector, action); } } else { if (xml.Name != "Add") { throw new XmlException(String.Format("Unknown element '{0}': only <Add>, <Parallel> or <Sequence>.", xml.Name)); } string type = xml.AttributeRequired("Type").Value; Type t = FindConfigurationType(type); HandlerConfiguration hC = (HandlerConfiguration)Activator.CreateInstance(t, xml.AttributeRequired("Name").Value); hC.DoInitialize(monitor, xml); collector(hC); } }
public FakeJobHandler(HandlerConfiguration handlerConfiguration, bool canProcess, bool hangOnProcessing, bool throwOnProcessing) { _canProcess = canProcess; _hangOnProcessing = hangOnProcessing; _throwOnProcessing = throwOnProcessing; _configuration = handlerConfiguration; }
/// <summary> /// Supplies the specified handler configuration, so that we can register subscribers and the handler factory used to create instances of them /// </summary> /// <param name="handlerConfiguration">The handler configuration.</param> /// <returns>INeedPolicy.</returns> public INeedPolicy Handlers(HandlerConfiguration handlerConfiguration) { _registry = handlerConfiguration.SubscriberRegistry; _handlerFactory = handlerConfiguration.HandlerFactory; _asyncHandlerFactory = handlerConfiguration.AsyncHandlerFactory; return(this); }
private static CommandProcessor BuildCommandProcessor(IServiceProvider provider) { var options = provider.GetService <IBrighterOptions>(); var subscriberRegistry = provider.GetService <ServiceCollectionSubscriberRegistry>(); var handlerFactory = new ServiceProviderHandlerFactory(provider); var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory, handlerFactory); var messageMapperRegistry = MessageMapperRegistry(provider); var policyBuilder = CommandProcessorBuilder.With() .Handlers(handlerConfiguration); var messagingBuilder = options.PolicyRegistry == null ? policyBuilder.DefaultPolicy() : policyBuilder.Policies(options.PolicyRegistry); var builder = options.BrighterMessaging == null ? messagingBuilder.NoTaskQueues() : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.MessageStore, options.BrighterMessaging.Producer, messageMapperRegistry)); var commandProcessor = builder .RequestContextFactory(options.RequestContextFactory) .Build(); return(commandProcessor); }
public static IBrighterHandlerBuilder AddBrighter(this IServiceCollection services, Action <BrighterOptions> configure = null) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var options = new BrighterOptions(); configure?.Invoke(options); var subscriberRegistry = new AspNetSubscriberRegistry(services, options.HandlerLifetime); var handlerFactory = new AspNetHandlerFactory(services); var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory, handlerFactory); var policyBuilder = CommandProcessorBuilder.With() .Handlers(handlerConfiguration); var messagingBuilder = options.PolicyRegistry == null ? policyBuilder.DefaultPolicy() : policyBuilder.Policies(options.PolicyRegistry); var builder = options.MessagingConfiguration == null ? messagingBuilder.NoTaskQueues() : messagingBuilder.TaskQueues(options.MessagingConfiguration); var commandProcessor = builder .RequestContextFactory(options.RequestContextFactory) .Build(); services.AddSingleton <IAmACommandProcessor>(commandProcessor); return(new AspNetHandlerBuilder(services, subscriberRegistry)); }
private void RegisterCommandProcessor(ILifetimeScope container) { var builder = new ContainerBuilder(); builder .RegisterType <CreateAnEmailCommandHandler>() .AsSelf(); IAmASubscriberRegistry subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <CreateAnEmailCommand, CreateAnEmailCommandHandler>(); IAmAHandlerFactory handlerFactory = new InMemoryHandlerFactory(container); var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory); IAmARequestContextFactory requestContextFactory = new InMemoryRequestContextFactory(); var commnadProcessor = CommandProcessorBuilder .With() .Handlers(handlerConfiguration) .DefaultPolicy() .Logger(container.Resolve <ILog>()) .NoTaskQueues() .RequestContextFactory(requestContextFactory) .Build(); builder.Register(context => commnadProcessor) .AsImplementedInterfaces() .SingleInstance(); builder.Update(container.ComponentRegistry); }
public static QueueCreationOptions ToQueueCreationOptions(this HandlerConfiguration handlerConfiguration) { return(new QueueCreationOptions { QueueId = handlerConfiguration.QueueId, QueueName = handlerConfiguration.QueueName, ThrottleInterval = handlerConfiguration.ThrottleInterval }); }
internal FakeJobHandler AddFakeHandler(HandlerConfiguration handlerConfiguration, bool canProcess = true, bool hangOnProcessing = false, bool throwOnProcessing = false) { var fakeHandler = new FakeJobHandler(handlerConfiguration, canProcess, hangOnProcessing, throwOnProcessing); _handlers.Add(fakeHandler.Configuration.QueueId, fakeHandler); return(fakeHandler); }
private static CommandProcessor BuildCommandProcessor(IServiceProvider provider) { var options = provider.GetService <IBrighterOptions>(); var subscriberRegistry = provider.GetService <ServiceCollectionSubscriberRegistry>(); var handlerFactory = new ServiceProviderHandlerFactory(provider); var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory, handlerFactory); var messageMapperRegistry = MessageMapperRegistry(provider); var policyBuilder = CommandProcessorBuilder.With() .Handlers(handlerConfiguration); var messagingBuilder = options.PolicyRegistry == null ? policyBuilder.DefaultPolicy() : policyBuilder.Policies(options.PolicyRegistry); var loggerFactory = provider.GetService <ILoggerFactory>(); ApplicationLogging.LoggerFactory = loggerFactory; INeedARequestContext taskQueuesBuilder; if (options.ChannelFactory is null) { //TODO: Need to add async outbox taskQueuesBuilder = options.BrighterMessaging == null ? messagingBuilder.NoTaskQueues() : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.OutBox, options.BrighterMessaging.AsyncOutBox, options.BrighterMessaging.Producer, options.BrighterMessaging.AsyncProducer, messageMapperRegistry)); } else { if (options.BrighterMessaging == null) { taskQueuesBuilder = messagingBuilder.NoTaskQueues(); } else { taskQueuesBuilder = options.BrighterMessaging.UseRequestReplyQueues ? messagingBuilder.RequestReplyQueues(new MessagingConfiguration( options.BrighterMessaging.OutBox, options.BrighterMessaging.Producer, messageMapperRegistry, responseChannelFactory: options.ChannelFactory)) : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.OutBox, options.BrighterMessaging.AsyncOutBox, options.BrighterMessaging.Producer, options.BrighterMessaging.AsyncProducer, messageMapperRegistry)); } } var commandProcessor = taskQueuesBuilder .RequestContextFactory(options.RequestContextFactory) .Build(); return(commandProcessor); }
public WebApiCoreService(HttpClient http) { BASEURI = HandlerConfiguration.GetConfiguration().WebApi; this.client = http; if (this.client.BaseAddress == null) { this.client.BaseAddress = new Uri(BASEURI); } }
public FallbackPolicyTests() { _handlerFactory = new Mock <IQueryHandlerFactory>(); _decoratorFactory = new Mock <IQueryHandlerDecoratorFactory>(); _handlerRegistry = new QueryHandlerRegistry(); var handlerConfiguration = new HandlerConfiguration(_handlerRegistry, _handlerFactory.Object, _decoratorFactory.Object); _queryProcessor = new QueryProcessor(handlerConfiguration, new InMemoryQueryContextFactory()); }
public void StartDispatcher(IContainer container) { var handlerFactory = container.Resolve <IAmAHandlerFactory>(); var messageMapperFactory = container.Resolve <IAmAMessageMapperFactory>(); var options = container.Resolve <IOptions <FourSettings> >(); var authSettings = options.Value; var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <ArticoloCreated, ArticoloCreatedEventHandler>(); subscriberRegistry.Register <ClienteCreated, ClienteCreatedEventHandler>(); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(ArticoloCreated), typeof(ArticoloCreatedMapper) }, { typeof(ClienteCreated), typeof(ClienteCreatedMapper) }, }; var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory); var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri(authSettings.RabbitMq.Uri)), Exchange = new Exchange(authSettings.RabbitMq.Events, "topic") }; this._commandProcessor = CommandProcessorBuilder.With() .Handlers(handlerConfiguration) .Policies(PolicyRegistry()) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); this._dispatcher = DispatchBuilder.With() .CommandProcessor(this._commandProcessor) .MessageMappers(messageMapperRegistry) .DefaultChannelFactory(new InputChannelFactory(new RmqMessageConsumerFactory(rmqConnnection))) .Connections(new Connection[] { new Connection <ArticoloCreated>(new ConnectionName("ArticoloCreatedEvent"), new ChannelName("ArticoloCreated"), new RoutingKey("ArticoloCreated"), timeoutInMilliseconds: 200), new Connection <ClienteCreated>(new ConnectionName("ClienteCreatedEvent"), new ChannelName("ClienteCreated"), new RoutingKey("ClienteCreated"), timeoutInMilliseconds: 200), }).Build(); this._dispatcher.Receive(); }
public JobQueue Create(HandlerConfiguration configuration) { try { var newQueue = _jobQueueFactory.Create(configuration); _queues.Add(newQueue.QueueId, newQueue); return(newQueue); } catch (Exception ex) { Trace.TraceError($"Error creating queue '{configuration.QueueId}'.{Environment.NewLine}{ex}"); throw; } }
public SubscriptionConfiguration( ConsumerSettings settings, BatchConfiguration batchConfiguration, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEvents = true, int consumerInstances = 1) : this(settings, serializer, handlerConfig, skipUnknownEvents, consumerInstances) { BatchConfiguration = batchConfiguration; BatchProcessingRequired = true; }
public JobQueue Create(HandlerConfiguration handlerConfiguration) { var jobQueue = new JobQueue( MockMessageQueueFactory, MockMessageFactory.Object, MockFormatter.Object, MockSerializer.Object, handlerConfiguration); _jobQueues.Add(jobQueue); return(jobQueue); }
public static Fakes.FakeJobHandler AddFakeHandler( this JobQueueListener listener, HandlerConfiguration handlerConfiguration, bool canProcess, bool hangOnProcessing = false, bool throwOnProcessing = false) { var fakeHandler = new Fakes.FakeJobHandler(handlerConfiguration, canProcess, hangOnProcessing, throwOnProcessing); listener.AddHandler(fakeHandler); return(fakeHandler); }
public static void RegisterServices(IServiceCollection services) { ContextConfiguration.Register(services); BusConfiguration.Register(services); EventConfiguration.Register(services); ValidationConfiguration.Register(services); HandlerConfiguration.Register(services); ServiceConfiguration.Register(services); RepositoryConfiguration.Register(services); // Infra - Identity Services //services.AddTransient<IEmailSender, AuthEmailMessageSender>(); //services.AddTransient<ISmsSender, AuthSMSMessageSender>(); // Infra - Identity //services.AddScoped<IUser, AspNetUser>(); }
public IEventHandler Create(HandlerConfiguration config) { IEventHandler handler = new EventHandler(_scopeFactory, config.RunHandlersInParallel); handler = config.RetryPolicy != null ? new RetryingEventHandler(handler, config.RetryPolicy) : new RetryingEventHandler( handler, _loggerFactory, config.RetryAttempts); if (config.IsLoggingEnabled) { handler = new LoggingEventHandler(_loggerFactory, handler); } return(handler); }
public EndpointConfiguration AddSubscription( ConsumerSettings settings, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEventTypes = true, int instances = 1) { var subscription = new SubscriptionConfiguration( settings, serializer, handlerConfig, skipUnknownEventTypes, instances); _subscriptions.Add(subscription); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="JobQueue"/> class /// </summary> /// <param name="queueFactory">Factory for creating the queue</param> /// <param name="messageFactory">Factory for creating new messages</param> /// <param name="formatter">Formatter for formatting payloads</param> /// <param name="serializer">Serializer for serializing requests</param> /// <param name="handlerConfiguration">Configuration creating handlers (used to copy into a <see cref="QueueCreationOptions"/> object</param> public JobQueue( IMessageQueueFactory queueFactory, IMessageFactory messageFactory, IPayloadFormatter formatter, IRequestSerializer serializer, HandlerConfiguration handlerConfiguration) { if (handlerConfiguration == null) { throw new ArgumentNullException(nameof(handlerConfiguration)); } _messageQueueFactory = queueFactory ?? throw new ArgumentNullException(nameof(queueFactory)); _messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory)); _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter)); _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); _queue = _messageQueueFactory.Create(handlerConfiguration.ToQueueCreationOptions()); _queue.ReceivedMessage += OnReceivedJob; }
internal static async Task Main() { var registry = new SubscriberRegistry(); var handlerConfiguration = new HandlerConfiguration(registry, new SimpleHandlerFactory()); var builder = CommandProcessorBuilder.With() .Handlers(handlerConfiguration) .DefaultPolicy() .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()); registry.RegisterAsync <InformationCommand, InformationCommandHandler>(); registry.RegisterAsync <FetchDataFromUrlCommand, FetchDataFromUrlRequestHandler>(); registry.RegisterAsync <ParseDataFromHtmlCommand, ParseDataFromHtmlCommandHandler>(); registry.RegisterAsync <BestMatchCarParkCommand, BestMatchCarParkCommandHandler>(); registry.RegisterAsync <CarParkToOutputCommand, CarParkToOutputCommandHandler>(); var commandProcessor = builder.Build(); await Run(commandProcessor); }
public IRecieveOnlyBus RegisterQueue <T>(string route, HandlerConfiguration config = null) { routes.AddRoute <T>(route); var handler = container.GetInstance <IHandler <T> >(); var client = new QueueClient(configuration.ConnectionString, route); var handlerConfiguration = config ?? new HandlerConfiguration(); client.RegisterMessageHandler((message, token) => handler.Handle(message, client, token), handlerConfiguration.Options(handler.OnException)); if (queueClients.ContainsKey(route)) { throw new Exception("Queues can only have a single handler registered."); } queueClients.Add(route, client); return(this); }
public SubscriptionConfiguration( ConsumerSettings settings, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEvents = true, int consumerInstances = 1) { if (consumerInstances < 1) { throw new ArgumentOutOfRangeException( nameof(consumerInstances), consumerInstances, "Instances should be >= 1."); } Settings = settings ?? throw new ArgumentNullException(nameof(settings)); Serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); SkipUnknownEvents = skipUnknownEvents; ConsumerInstances = consumerInstances; HandlerConfig = handlerConfig ?? new HandlerConfiguration(); }
public EndpointConfiguration AddBatchSubscription( ConsumerSettings settings, BatchConfiguration batchConfig, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEventTypes = true, int instances = 1, bool isLongRunning = true) { var subscription = new SubscriptionConfiguration( isLongRunning ? settings.ToLongRunning() : settings, batchConfig, serializer, handlerConfig, skipUnknownEventTypes, instances); _subscriptions.Add(subscription); return(this); }
public static INeedAQueryContext SimpleInjectorHandlers(this INeedHandlers handlerBuilder, Container container, Action <HandlerSettings> settings) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var factory = new SimpleInjectorHandlerFactory(container); var handlerRegistry = new QueryHandlerRegistry(); var handlerSettings = new HandlerSettings(container, handlerRegistry); settings(handlerSettings); var handlerConfiguration = new HandlerConfiguration(handlerRegistry, factory); return(handlerBuilder.Handlers(handlerConfiguration)); }
private static Container ServiceProvider(Container container, out MessageMapperRegistry messageMapperRegistry, out HandlerConfiguration handlerConfiguration) { container.Register <IHandleRequests <TaskCompletedEvent>, TaskCompletedEventHandler>(); container.Register <IAmAMessageMapper <TaskCompletedEvent>, TaskCompletedEventMessageMapper>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <TaskCompletedEvent, TaskCompletedEventHandler>(); var handlerFactory = new ServiceProviderHandlerFactory(container); var messageMapperFactory = new ServiceProviderMessageMapperFactory(container); messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(TaskCompletedEvent), typeof(TaskCompletedEventMessageMapper) } }; handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory); return(container); }
public void Initialize( IntegrationConfiguration configuration, HandlerConfiguration handlers, IViewRenderer viewRenderer, ILogger logger, IClient client, RouteOptionsBase options) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (viewRenderer == null) { throw new ArgumentNullException(nameof(viewRenderer)); } if (client == null) { throw new ArgumentNullException(nameof(client)); } if (handlers == null) { throw new ArgumentNullException(nameof(handlers)); } _configuration = configuration; _viewRenderer = viewRenderer; _logger = logger; _client = client; _handlers = handlers; _options = options; _initialized = true; }
static void Main(string[] args) { var defaultHandlerConfig = new HandlerConfiguration { MaxConcurrentCalls = 10, AutoComplete = true }; var bus = RecieveOnlyBus.Initialise(new BusConfigutration()) .WithDependencyRegistrations(x => { x.RegisterQueueHandler <MyQueueMessage, MyMessageQueueMessageHandler>(); x.RegisterTopicHandler <MyTopicMessage, MyMessageTopicMessageHandler>(); x.RegisterTopicHandler <MyTopicMessage, AnotherMyMessageTopicMessageHandler>(); }) .RegisterQueue <MyQueueMessage>("my-message-queue", defaultHandlerConfig) .RegisterTopic <MyTopicMessage>("my-message-topic", defaultHandlerConfig); Console.WriteLine("Waiting......."); Console.ReadKey(); bus.Dispose(); }
public MessagingConfiguration() { Handling = new HandlerConfiguration(Graph); Handling.GlobalPolicy <SagaFramePolicy>(); }