//private void ConfigureSendHeader(IBusFactoryConfigurator cfg)
        //{
        //    cfg.ConfigureSend(x => x.UseSendExecute(sendContext =>
        //    {
        //        //1. get current thread identity object.
        //        var currentThreadIdentityObject = Thread.CurrentPrincipal.Identity is BarcodeIdentity ? ((BarcodeIdentity)Thread.CurrentPrincipal.Identity).IdentityObject : null;

        //        if (currentThreadIdentityObject != null)
        //        {
        //            //2. set the headers.
        //            sendContext.Headers.Set(AppSettingConfig.RabbitMqIdentityHeaderKey, currentThreadIdentityObject.StaffID.ToString());
        //        }
        //    }));
        //}

        private void ConfigureEndPoints(IBusFactoryConfigurator cfg, IComponentContext context, params ReceiveEndPoint[] receiveEndPoints)
        {
            if (receiveEndPoints?.Length > 0)
            {
                var baseQueueName       = AppSettingConfig.BaseQueueName;
                var rpcQueuePostfix     = AppSettingConfig.RpcQueueNamePostfix;
                var commandQueuePostfix = AppSettingConfig.CommandQueueNamePostfix;
                var eventQueuePostfix   = AppSettingConfig.EventQueueNamePostfix;

                var consumerMethod = typeof(AutofacExtensions).GetMethod("Consumer", new Type[] { typeof(IReceiveEndpointConfigurator), typeof(IComponentContext), typeof(string) });

                foreach (var receiveEndPoint in receiveEndPoints)
                {
                    if (receiveEndPoint == ReceiveEndPoint.Commnad)
                    {
                        cfg.ReceiveEndpoint(baseQueueName + "_" + commandQueuePostfix, ep =>
                        {
                            var commandConsumers = System.Reflection.Assembly.GetAssembly(typeof(MassTransitModule))
                                                   .GetTypes()
                                                   .Where(type => type.IsClass && type.Name.EndsWith("CommandConsumer"));

                            foreach (var commandConsumer in commandConsumers)
                            {
                                consumerMethod.MakeGenericMethod(commandConsumer).Invoke(commandConsumer, new object[] { ep, context, "message" });
                            }
                        });
                    }
                    else if (receiveEndPoint == ReceiveEndPoint.Request)
                    {
                        cfg.ReceiveEndpoint(baseQueueName + "_" + rpcQueuePostfix, ep =>
                        {
                            var requestConsumers = System.Reflection.Assembly.GetAssembly(typeof(MassTransitModule))
                                                   .GetTypes()
                                                   .Where(type => type.IsClass && type.Name.EndsWith("RequestConsumer"));

                            foreach (var requestConsumer in requestConsumers)
                            {
                                consumerMethod.MakeGenericMethod(requestConsumer).Invoke(requestConsumer, new object[] { ep, context, "message" });
                            }
                        });
                    }
                    else if (receiveEndPoint == ReceiveEndPoint.Event)
                    {
                        cfg.ReceiveEndpoint(baseQueueName + "_" + eventQueuePostfix, ep =>
                        {
                            var eventConsumers = System.Reflection.Assembly.GetAssembly(typeof(MassTransitModule))
                                                 .GetTypes()
                                                 .Where(type => type.IsClass && type.Name.EndsWith("EventConsumer"));

                            foreach (var eventConsumer in eventConsumers)
                            {
                                consumerMethod.MakeGenericMethod(eventConsumer).Invoke(eventConsumer, new object[] { ep, context, "message" });
                            }
                        });
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Configure a service instance, which supports one or more receive endpoints, all of which are managed by conductor.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="options"></param>
        /// <param name="configure"></param>
        public static void ServiceInstance <TEndpointConfigurator>(this IBusFactoryConfigurator <TEndpointConfigurator> configurator,
                                                                   ServiceInstanceOptions options, Action <IServiceInstanceConfigurator <TEndpointConfigurator> > configure)
            where TEndpointConfigurator : IReceiveEndpointConfigurator
        {
            IServiceInstanceTransportConfigurator <TEndpointConfigurator> transportConfigurator = Cached <TEndpointConfigurator> .Instance;

            var instance = new ServiceInstance();

            if (options.InstanceEndpointEnabled)
            {
                var definition = new InstanceEndpointDefinition(instance);
                configurator.ReceiveEndpoint(definition, options.EndpointNameFormatter, instanceEndpointConfigurator =>
                {
                    var instanceConfigurator = new ServiceInstanceConfigurator <TEndpointConfigurator>(configurator, transportConfigurator, instance, options,
                                                                                                       instanceEndpointConfigurator);

                    configure?.Invoke(instanceConfigurator);
                });
            }
            else
            {
                var instanceConfigurator = new ServiceInstanceConfigurator <TEndpointConfigurator>(configurator, transportConfigurator, instance, options);

                configure?.Invoke(instanceConfigurator);
            }
        }
Esempio n. 3
0
        public static void UseInMemoryScheduler(this IBusFactoryConfigurator configurator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            var scheduler = schedulerFactory.GetScheduler();

            configurator.ReceiveEndpoint("quartz", e =>
            {
                var partitioner = configurator.CreatePartitioner(16);

                e.Consumer(() => new ScheduleMessageConsumer(scheduler), x =>
                           x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId)));
                e.Consumer(() => new CancelScheduledMessageConsumer(scheduler), x =>
                           x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId)));

                configurator.UseMessageScheduler(e.InputAddress);

                var specification = new SchedulerBusFactorySpecification(scheduler, e.InputAddress);
                configurator.AddBusFactorySpecification(specification);
            });
        }
Esempio n. 4
0
        public static Uri UseInMemoryScheduler(this IBusFactoryConfigurator configurator, string queueName = "quartz")
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            var scheduler = TaskUtil.Await(() => schedulerFactory.GetScheduler());

            Uri inputAddress = null;

            configurator.ReceiveEndpoint(queueName, e =>
            {
                var partitioner = configurator.CreatePartitioner(16);

                e.Consumer(() => new ScheduleMessageConsumer(scheduler), x =>
                           x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId)));

                e.Consumer(() => new CancelScheduledMessageConsumer(scheduler), x =>
                           x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId)));

                configurator.UseMessageScheduler(e.InputAddress);

                var observer = new SchedulerBusObserver(scheduler, e.InputAddress);
                configurator.ConnectBusObserver(observer);

                inputAddress = e.InputAddress;
            });

            return(inputAddress);
        }
 protected override void ConfigureNamedReceiveEndpoint(IBusFactoryConfigurator configurator, string queueName)
 {
     configurator.ReceiveEndpoint(queueName, x =>
     {
         x.StateMachineSaga(_stateMachine, TestRepository);
     });
 }
Esempio n. 6
0
        public static void AddScheduling(this IBusFactoryConfigurator configurator, Action <InMemorySchedulerOptions> configure)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var options = new InMemorySchedulerOptions();

            configure?.Invoke(options);

            if (options.SchedulerFactory == null)
            {
                throw new ArgumentNullException(nameof(options.SchedulerFactory));
            }

            Uri inputAddress = null;

            var observer = new SchedulerBusObserver(options);

            configurator.ReceiveEndpoint(options.QueueName, e =>
            {
                var partitioner = configurator.CreatePartitioner(Environment.ProcessorCount);

                e.Consumer(() => new ScheduleMessageConsumer(observer.Scheduler), x =>
                           x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId)));

                e.Consumer(() => new CancelScheduledMessageConsumer(observer.Scheduler), x =>
                           x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId)));

                configurator.UseMessageScheduler(e.InputAddress);

                configurator.ConnectBusObserver(observer);
            });
        }
Esempio n. 7
0
 /// <summary>
 /// Applies the receive endpoints to the bus.
 /// </summary>
 /// <param name="configurator"></param>
 public void Apply(string busName, IBusFactoryConfigurator configurator)
 {
     foreach (var name in names.GetEndpointNames(busName))
     {
         configurator.ReceiveEndpoint(name, endpoint => Apply(busName, name, endpoint, configurations.GetConfigurations(busName, name)));
     }
 }
Esempio n. 8
0
        public static void AddSignalRHubEndpoints <THub, TEndpointConfigurator>(this IBusFactoryConfigurator configurator,
                                                                                IServiceProvider serviceProvider,
                                                                                IHost host, Action <TEndpointConfigurator> configureEndpoint = null)
            where TEndpointConfigurator : class, IReceiveEndpointConfigurator
            where THub : Hub
        {
            var consumers = HubConsumersCache.GetOrAdd <THub>();

            var queueNameBase = host.Topology.CreateTemporaryQueueName($"signalRBackplane-{typeof(THub).Name}-");

            // Loop through our 5 hub consumers and create a temporary endpoint for each
            foreach (var consumerType in consumers)
            {
                // remove `1 from generic type
                var name  = consumerType.Name;
                int index = name.IndexOf('`');
                if (index > 0)
                {
                    name = name.Remove(index);
                }

                configurator.ReceiveEndpoint(new HubEndpointDefinition <THub>(), null, e =>
                {
                    configureEndpoint?.Invoke((TEndpointConfigurator)e);

                    e.ConfigureConsumer(serviceProvider, consumerType);
                });
            }
        }
 /// <summary>
 /// Method used to configure the available endpoints for a test case
 /// </summary>
 /// <param name="busFactoryConfigurator">
 /// </param>
 public override void ConfigureEndpoints(IBusFactoryConfigurator busFactoryConfigurator)
 {
     busFactoryConfigurator.ReceiveEndpoint(
         QueueName,
         endpointConfigurator => endpointConfigurator.Consumer <Consumers.ConsumeConsumer>()
         );
 }
Esempio n. 10
0
 protected virtual void ConfigureNamedReceiveEndpoint(IBusFactoryConfigurator configurator, string queueName)
 {
     configurator.ReceiveEndpoint(queueName, x =>
     {
         x.Saga(TestRepository);
     });
 }
Esempio n. 11
0
        public static void UseHangfireScheduler(this IBusFactoryConfigurator configurator, IHangfireComponentResolver hangfireComponentResolver,
                                                string queueName = "hangfire",
                                                Action <BackgroundJobServerOptions> configureServer = null)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (hangfireComponentResolver == null)
            {
                throw new ArgumentNullException(nameof(hangfireComponentResolver));
            }

            configurator.ReceiveEndpoint(queueName, e =>
            {
                var partitioner = configurator.CreatePartitioner(Environment.ProcessorCount);

                e.Consumer(() => new ScheduleMessageConsumer(hangfireComponentResolver), x =>
                {
                    x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId));
                    x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId));
                });
                e.Consumer(() => new ScheduleRecurringMessageConsumer(hangfireComponentResolver));

                var observer = new SchedulerBusObserver(hangfireComponentResolver, e.InputAddress, configureServer);
                configurator.ConnectBusObserver(observer);

                configurator.UseMessageScheduler(e.InputAddress);
            });
        }
Esempio n. 12
0
        void ConfigureBus(IBusFactoryConfigurator configurator)
        {
            configurator.ReceiveEndpoint(CompensateQueueName, x =>
            {
                x.CompensateActivityHost(_activityFactory, _configureCompensate);

                CompensateAddress = x.InputAddress;
            });

            configurator.ReceiveEndpoint(ExecuteQueueName, x =>
            {
                x.ExecuteActivityHost(CompensateAddress, _activityFactory, _configureExecute);

                ExecuteAddress = x.InputAddress;
            });
        }
        /// <summary>
        /// Prefer using this method when configuring a receive endpoint, so that the consumers for a command/event will listen on the correct queue.
        /// </summary>
        /// <typeparam name="TMessage">Must end with either Command, Event or Query (convention)</typeparam>
        public static void ReceiveEndpoint <TMessage>(this IBusFactoryConfigurator cfg, Action <IReceiveEndpointConfigurator> conf)
        {
            var className = typeof(TMessage).Name;

            ValidationHelpers.EnsureNamingConventionForMessage(className);
            cfg.ReceiveEndpoint(className, conf);
        }
Esempio n. 14
0
        public static Task RegisterStateMachine(this IBusFactoryConfigurator configurator, Type stateMachineType, IServiceProvider provider)
        {
            configurator.ReceiveEndpoint(stateMachineType.FullName, e =>
            {
                var instanceType = stateMachineType
                                   .GetTypeInfo()
                                   .BaseType
                                   .GetGenericArguments()[0];

                var automatonymousIntegrationAssembly = Assembly.Load(new AssemblyName("MassTransit.AutomatonymousExtensions.DependencyInjectionIntegration"));

                var stateMachineSagaMethod = automatonymousIntegrationAssembly
                                             .GetTypes()
                                             .Where(t => t.GetTypeInfo().IsSealed&& !t.GetTypeInfo().IsGenericType&& !t.IsNested)
                                             .SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public))
                                             .Where(m => m.IsDefined(typeof(ExtensionAttribute), false) && m.GetParameters()[0].ParameterType == typeof(IReceiveEndpointConfigurator) && m.GetParameters()[2].ParameterType == typeof(IServiceProvider))
                                             .Single(m => m.Name == "StateMachineSaga")
                                             .MakeGenericMethod(instanceType);

                var stateMachine = provider.GetService(stateMachineType);

                stateMachineSagaMethod.Invoke(e, new object[] { e, stateMachine, provider, null });
            });

            return(Task.CompletedTask);
        }
 public static void CreateConventionalCommandHandlerEndpoint <TConsumer, TMessage>(this IBusFactoryConfigurator cfg, IServiceProvider provider) where TMessage : class where TConsumer : class, IConsumer <TMessage>
 {
     cfg.ReceiveEndpoint(BuildConventionalPathForType(typeof(TMessage)),
                         configurator =>
     {
         configurator.Consumer <TConsumer>(provider);
     });
 }
Esempio n. 16
0
 private void ConfigureConsumersListeningOnErrorQueue(IBusFactoryConfigurator busFactoryConfigurator)
 {
     busFactoryConfigurator.ReceiveEndpoint(ErrorQueueName,
                                            receiveEndpointConfigurator =>
     {
         receiveEndpointConfigurator.Consumer(typeof(MyCommandFaultConsumer), _consumerFactory.Create);
         receiveEndpointConfigurator.Consumer(typeof(MyEventFaultConsumer), _consumerFactory.Create);
     });
 }
Esempio n. 17
0
        public static void RegisterScopedConsumer <TConsumer>(this IBusFactoryConfigurator configurator, IServiceProvider provider, Action <IReceiveEndpointConfigurator> endpointConfigurator = null, Action <IConsumerConfigurator <TConsumer> > consumerConfigurator = null) where TConsumer : class, IConsumer
        {
            configurator.ReceiveEndpoint(typeof(TConsumer).FullName, e =>
            {
                e.ScopedConsumer(provider, consumerConfigurator);

                endpointConfigurator?.Invoke(e);
            });
        }
Esempio n. 18
0
        protected virtual void ConfigureNamedReceiveEndpoint(IBusFactoryConfigurator configurator, string queueName)
        {
            configurator.ReceiveEndpoint(queueName, x =>
            {
                var decorator = new TestConsumerFactoryDecorator <TConsumer>(_consumerFactory, _consumed);

                x.Consumer(decorator);
            });
        }
Esempio n. 19
0
        public static void RegisterConsumer <TConsumer>(this IBusFactoryConfigurator bus, IServiceProvider provider, Action <IReceiveEndpointConfigurator> endpointConfigurator = null, Action <IConsumerConfigurator <TConsumer> > consumerConfigurator = null) where TConsumer : class, IConsumer
        {
            bus.ReceiveEndpoint(typeof(TConsumer).FullName, e =>
            {
                e.Consumer(() => provider.GetRequiredService <TConsumer>(), consumerConfigurator);

                endpointConfigurator?.Invoke(e);
            });
        }
Esempio n. 20
0
        public static Task RegisterConsumer(this IBusFactoryConfigurator configurator, Type consumerType, IServiceProvider provider)
        {
            configurator.ReceiveEndpoint(consumerType.FullName, e =>
            {
                e.Consumer(consumerType, t => provider.GetRequiredService(t));
                e.UseInMemoryOutbox();
            });

            return(Task.CompletedTask);
        }
Esempio n. 21
0
        public static void RegisterStateMachine <TStateMachine, TState>(this IBusFactoryConfigurator configurator, IServiceProvider provider, Action <IReceiveEndpointConfigurator> endpointConfigurator = null)
            where TStateMachine : MassTransitStateMachine <TState>
            where TState : class, SagaStateMachineInstance
        {
            configurator.ReceiveEndpoint(typeof(TStateMachine).FullName, e =>
            {
                e.StateMachineSaga(provider.GetRequiredService <TStateMachine>(), provider.GetRequiredService <ISagaRepository <TState> >());

                endpointConfigurator?.Invoke(e);
            });
        }
        void ConfigureBus(IBusFactoryConfigurator configurator)
        {
            configurator.ReceiveEndpoint(ExecuteQueueName, x =>
            {
                OnConfigureExecuteReceiveEndpoint?.Invoke(x);

                x.ExecuteActivityHost(_activityFactory, _configureExecute);

                ExecuteAddress = x.InputAddress;
            });
        }
        /// <summary>
        /// Creates a management endpoint which can be used by controllable filters on a bus instance
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void ManagementEndpoint(this IBusFactoryConfigurator configurator, Action <IReceiveEndpointConfigurator> configure = null)
        {
            IReceiveEndpointConfigurator specification = null;

            configurator.ReceiveEndpoint(new ManagementEndpointDefinition(), DefaultEndpointNameFormatter.Instance, x =>
            {
                specification = x;

                configure?.Invoke(specification);
            });
        }
 /// <summary>
 /// Method used to configure the available endpoints for a test case
 /// </summary>
 /// <param name="busFactoryConfigurator">
 /// </param>
 public override void ConfigureEndpoints(IBusFactoryConfigurator busFactoryConfigurator)
 {
     busFactoryConfigurator.ReceiveEndpoint(
         QueueName,
         endpointConfigurator =>
     {
         endpointConfigurator.Consumer <Buyer>();
         endpointConfigurator.Consumer <Bank>();
         endpointConfigurator.Consumer <Shop>();
     }
         );
 }
        public static void FutureEndpoint <TFuture, TRequest>(this IBusFactoryConfigurator configurator, IBusRegistrationContext context)
            where TFuture : class, SagaStateMachine <FutureState>, new()
            where TRequest : class
        {
            var endpointNameFormatter = context.GetRequiredService <IEndpointNameFormatter>();

            configurator.ReceiveEndpoint(endpointNameFormatter.Message <TFuture>(), endpoint =>
            {
                endpoint.ApplyFutureEndpointConfiguration <TRequest>();

                endpoint.StateMachineSaga(new TFuture(), context);
            });
        }
        public static void AddSignalRHubEndpoints <THub>(this IBusFactoryConfigurator configurator,
                                                         IRegistrationContext <IServiceProvider> context,
                                                         Action <IReceiveEndpointConfigurator> configureEndpoint = null)
            where THub : Hub
        {
            var endpointNameFormatter = context.Container.GetService <IEndpointNameFormatter>();
            var definition            = new HubEndpointDefinition <THub>();

            configurator.ReceiveEndpoint(definition, endpointNameFormatter, e =>
            {
                configureEndpoint?.Invoke(e);

                e.ConfigureConsumer <AllConsumer <THub> >(context);
            });

            configurator.ReceiveEndpoint(definition, endpointNameFormatter, e =>
            {
                configureEndpoint?.Invoke(e);

                e.ConfigureConsumer <ConnectionConsumer <THub> >(context);
            });

            configurator.ReceiveEndpoint(definition, endpointNameFormatter, e =>
            {
                configureEndpoint?.Invoke(e);

                e.ConfigureConsumer <GroupConsumer <THub> >(context);
            });

            configurator.ReceiveEndpoint(definition, endpointNameFormatter, e =>
            {
                configureEndpoint?.Invoke(e);

                e.ConfigureConsumer <UserConsumer <THub> >(context);
            });
        }
        /// <summary>
        /// Configure a service instance for use with the job service
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="options"></param>
        /// <param name="configure"></param>
        public static void ServiceInstance <TEndpointConfigurator>(this IBusFactoryConfigurator <TEndpointConfigurator> configurator,
                                                                   ServiceInstanceOptions options, Action <IServiceInstanceConfigurator <TEndpointConfigurator> > configure)
            where TEndpointConfigurator : IReceiveEndpointConfigurator
        {
            var instance = new ServiceInstance();

            var definition = new InstanceEndpointDefinition(instance);

            configurator.ReceiveEndpoint(definition, options.EndpointNameFormatter, endpointConfigurator =>
            {
                var instanceConfigurator = new ServiceInstanceConfigurator <TEndpointConfigurator>(configurator, options, endpointConfigurator);

                configure?.Invoke(instanceConfigurator);
            });
        }
        public static void CreateBackplaneEndpoints <T>(this IBusFactoryConfigurator configurator, IServiceProvider serviceProvider, IHost host, IReadOnlyDictionary <Type, IReadOnlyList <Type> > hubConsumers, Action <T> configureEndpoint = null)
            where T : class, IReceiveEndpointConfigurator
        {
            var factoryType = typeof(ScopeConsumerFactory <>);
            var consumerConfiguratorType = typeof(ConsumerConfigurator <>);

            foreach (var hub in hubConsumers)
            {
                var queueNameBase = host.Topology.CreateTemporaryQueueName($"signalRBackplane-{hub.Key.Name}-");

                // Loop through our 5 hub consumers and create a temporary endpoint for each
                foreach (var consumer in hub.Value)
                {
                    // remove `1 from generic type
                    var name  = consumer.Name;
                    int index = name.IndexOf('`');
                    if (index > 0)
                    {
                        name = name.Remove(index);
                    }

                    configurator.ReceiveEndpoint($"{queueNameBase}{name}-", e =>
                    {
                        configureEndpoint?.Invoke((T)e);

                        IConsumerScopeProvider scopeProvider = new DependencyInjectionConsumerScopeProvider(serviceProvider);

                        var concreteFactoryType = factoryType.MakeGenericType(consumer);

                        var consumerFactory = Activator.CreateInstance(concreteFactoryType, scopeProvider);

                        var concreteConsumerConfiguratorType = consumerConfiguratorType.MakeGenericType(consumer);

                        var consumerConfigurator = Activator.CreateInstance(concreteConsumerConfiguratorType, consumerFactory, e);

                        e.AddEndpointSpecification((IReceiveEndpointSpecification)consumerConfigurator);
                    });
                }
            }
        }
        private void InMemoryBuild(IBusFactoryConfigurator configurator)
        {
            var groupHandlers = _handlerInfos.GroupBy(_ => _.QueueName);

            foreach (var groupHandler in groupHandlers)
            {
                configurator.ReceiveEndpoint(groupHandler.Key, cfg =>
                {
                    foreach (var handlerInfo in groupHandler)
                    {
                        var handlerMethod = GetHandlerMethod(handlerInfo.MessageType);
                        var methodInfo    = DatabusExecutionContext.Current.GetType().GetMethod("Handler").MakeGenericMethod(handlerInfo.MessageType);
                        var delgate       = Delegate.CreateDelegate(typeof(MessageHandler <>).MakeGenericType(handlerInfo.MessageType), DatabusExecutionContext.Current, methodInfo);

                        handlerMethod.Invoke(null, new object[] { cfg, delgate, null });
                        Console.WriteLine($"{handlerInfo.MessageHandlerType.Name} for message {handlerInfo.MessageType.Name} in queue {handlerInfo.QueueName} registered");
                    }

                    EndpointConfigure(cfg, groupHandler.Key);
                });
            }
        }
Esempio n. 30
0
        public static void UseInMemoryScheduler(this IBusFactoryConfigurator configurator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            var scheduler = schedulerFactory.GetScheduler();

            var specification = new InMemorySchedulerBusFactorySpecification(scheduler);

            configurator.AddBusFactorySpecification(specification);

            configurator.ReceiveEndpoint("quartz", e =>
            {
                configurator.UseMessageScheduler(e.InputAddress);

                e.Consumer(() => new ScheduleMessageConsumer(scheduler));
                e.Consumer(() => new CancelScheduledMessageConsumer(scheduler));
            });
        }