当前位置: 首页>>代码示例>>C#>>正文


C# ICommandBus.Start方法代码示例

本文整理汇总了C#中ICommandBus.Start方法的典型用法代码示例。如果您正苦于以下问题:C# ICommandBus.Start方法的具体用法?C# ICommandBus.Start怎么用?C# ICommandBus.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICommandBus的用法示例。


在下文中一共展示了ICommandBus.Start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WebApiApplication

        static WebApiApplication()
        {
            try
            {
                Configuration.Instance.UseLog4Net();
                _Logger = IoCFactory.Resolve<ILoggerFactory>().Create(typeof(WebApiApplication));

                Configuration.Instance
                             .CommandHandlerProviderBuild(null, "CommandHandlers")
                             .RegisterDisposeModule()
                             .RegisterMvc();

                #region EventPublisher init
                _MessagePublisher = IoCFactory.Resolve<IMessagePublisher>();
                _MessagePublisher.Start();
                #endregion

                #region event subscriber init
                _DomainEventConsumer = IoCFactory.Resolve<IMessageConsumer>("DomainEventSubscriber");
                _DomainEventConsumer.Start();
                #endregion

                #region application event subscriber init
                _ApplicationEventConsumer = IoCFactory.Resolve<IMessageConsumer>("ApplicationEventConsumer");
                _ApplicationEventConsumer.Start();
                #endregion

                #region CommandBus init
                _CommandBus = IoCFactory.Resolve<ICommandBus>();
                _CommandBus.Start();
                #endregion

                #region Command Consuemrs init
                var commandHandlerProvider = IoCFactory.Resolve<ICommandHandlerProvider>();
                _CommandConsumer1 = new CommandConsumer(commandHandlerProvider, _MessagePublisher, "commandqueue1");
                _CommandConsumer2 = new CommandConsumer(commandHandlerProvider, _MessagePublisher, "commandqueue2");
                _CommandConsumer3 = new CommandConsumer(commandHandlerProvider, _MessagePublisher, "commandqueue3");

                _CommandConsumer1.Start();
                _CommandConsumer2.Start();
                _CommandConsumer3.Start();
                #endregion

            }
            catch (Exception ex)
            {
                _Logger.Error(ex.GetBaseException().Message, ex);
            }
        }
开发者ID:vebin,项目名称:IFramework,代码行数:49,代码来源:Global.asax.cs

示例2: Main

        static void Main(string[] args)
        {
            try
            {

                Configuration.Instance.UseLog4Net()
                                      .RegisterMessageContextType(typeof(IFramework.MessageQueue.EQueue.MessageFormat.MessageContext))
                                      .InitliaizeEQueue(5000, 5001, 5000)
                                      .CommandHandlerProviderBuild(null, "CommandHandlers");

                var consumerSetting = new ConsumerSetting();
                consumerSetting.MessageHandleMode = MessageHandleMode.Sequential;
                consumerSetting.BrokerPort = 5001;

                var producerSetting = new ProducerSetting();
                var producerPort = producerSetting.BrokerPort = 5000;

                var eventHandlerProvider = IoCFactory.Resolve<IHandlerProvider>("AsyncDomainEventSubscriber");
                IMessageConsumer domainEventSubscriber = new DomainEventSubscriber("domainEventSubscriber1",
                                                                                   consumerSetting,
                                                                                   "DomainEventSubscriber",
                                                                                   "domainevent",
                                                                                   eventHandlerProvider);
                domainEventSubscriber.Start();
                IoCFactory.Instance.CurrentContainer.RegisterInstance("DomainEventConsumer", domainEventSubscriber);

                IEventPublisher eventPublisher = new EventPublisher("EventPublisher", "domainevent",
                                                                  producerSetting);
                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(IEventPublisher),
                                                                      eventPublisher,
                                                                      new ContainerControlledLifetimeManager());

                var commandHandlerProvider = IoCFactory.Resolve<ICommandHandlerProvider>();
                var commandConsumer1 = new CommandConsumer("consumer1", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer2 = new CommandConsumer("consumer2", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer3 = new CommandConsumer("consumer3", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer4 = new CommandConsumer("consumer4", consumerSetting,
                                                          "CommandConsumerGroup",
                                                          "Command",
                                                          consumerSetting.BrokerAddress,
                                                          producerPort,
                                                          commandHandlerProvider);

                commandConsumer1.Start();
                commandConsumer2.Start();
                commandConsumer3.Start();
                commandConsumer4.Start();

                commandBus = new CommandBus("CommandBus",
                                                        commandHandlerProvider,
                                                        IoCFactory.Resolve<ILinearCommandManager>(),
                                                        consumerSetting.BrokerAddress,
                                                        producerPort,
                                                        consumerSetting,
                                                        "CommandBus",
                                                        "Reply",
                                                        "Command",
                                                        true);

                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(ICommandBus),
                                                                      commandBus,
                                                                      new ContainerControlledLifetimeManager());
                commandBus.Start();

                //Below to wait for consumer balance.
                var scheduleService = ObjectContainer.Resolve<IScheduleService>();
                var waitHandle = new ManualResetEvent(false);
                var taskId = scheduleService.ScheduleTask("consumer logs", () =>
                {
                    var bAllocatedQueueIds = (commandBus as CommandBus).Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c1AllocatedQueueIds = commandConsumer1.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c2AllocatedQueueIds = commandConsumer2.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c3AllocatedQueueIds = commandConsumer3.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c4AllocatedQueueIds = commandConsumer4.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var eAllocatedQueueIds = (domainEventSubscriber as DomainEventSubscriber).Consumer.GetCurrentQueues().Select(x => x.QueueId);

                    Console.WriteLine(string.Format("Consumer message queue allocation result:bus:{0}, eventSubscriber:{1} c1:{2}, c2:{3}, c3:{4}, c4:{5}",
                          string.Join(",", bAllocatedQueueIds),
                          string.Join(",", eAllocatedQueueIds),
                          string.Join(",", c1AllocatedQueueIds),
                          string.Join(",", c2AllocatedQueueIds),
                          string.Join(",", c3AllocatedQueueIds),
//.........这里部分代码省略.........
开发者ID:vebin,项目名称:IFramework,代码行数:101,代码来源:Program.cs


注:本文中的ICommandBus.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。