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


C# InMemoryBus.Subscribe方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            var outputBus = new InMemoryBus("OutputBus");
            var controller = new NodeController(outputBus);
            var mainQueue = new QueuedHandler(controller, "Main Queue");
            controller.SetMainQueue(mainQueue);

            // Hello world service
            var hello = new HelloWorldService(mainQueue);
            outputBus.Subscribe<SystemMessage.SystemInit>(hello);
            outputBus.Subscribe<SystemMessage.StartShutdown>(hello);
            outputBus.Subscribe<HelloWorldMessage.Hi>(hello);

            // TIMER
            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));
            outputBus.Subscribe<TimerMessage.Schedule>(timer);

            Console.WriteLine("Starting everything. Press enter to initiate shutdown");

            mainQueue.Start();

            mainQueue.Publish(new SystemMessage.SystemInit());
            Console.ReadLine();
            mainQueue.Publish(new SystemMessage.StartShutdown());
            Console.ReadLine();
        }
开发者ID:abdullin,项目名称:seda-homework,代码行数:26,代码来源:Program.cs

示例2: Setup

 public void Setup()
 {
     _consumer = new TestHandler<Message>();
     _bus = new InMemoryBus("temp");
     _bus.Subscribe(_consumer);
     ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
     var ioDispatcher = new IODispatcher(_bus, new PublishEnvelope(_bus));
     _readerService = new EventReaderCoreService(_bus, ioDispatcher, 10, writerCheckpoint, runHeadingReader: true);
     _subscriptionDispatcher =
         new ReaderSubscriptionDispatcher(_bus);
     _spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(_bus);
     _timeoutScheduler = new TimeoutScheduler();
     _workerId = Guid.NewGuid();
     _service = new ProjectionCoreService(
         _workerId, _bus, _bus, _subscriptionDispatcher, new RealTimeProvider(), ioDispatcher,
         _spoolProcessingResponseDispatcher, _timeoutScheduler);
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CheckpointSuggested>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CommittedEventReceived>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.EofReached>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionEofReached>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionMeasured>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionDeleted>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ProgressChanged>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.SubscriptionStarted>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.NotAuthorized>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ReaderAssignedReader>());
     _bus.Subscribe(_spoolProcessingResponseDispatcher.CreateSubscriber<PartitionProcessingResult>());
     _readerService.Handle(new Messages.ReaderCoreServiceMessage.StartReader());
     _service.Handle(new ProjectionCoreServiceMessage.StartCore());
 }
开发者ID:czcz1024,项目名称:EventStore,代码行数:30,代码来源:TestFixtureWithProjectionCoreService.cs

示例3: StartWithOptions

        public static NodeEntryPoint StartWithOptions(NodeOptions options, Action<int> termination)
        {
            var slim = new ManualResetEventSlim(false);
            var list = String.Join(Environment.NewLine,
                options.GetPairs().Select(p => String.Format("{0} : {1}", p.Key, p.Value)));

            Log.Info(list);

            var bus = new InMemoryBus("OutputBus");
            var controller = new NodeController(bus);
            var mainQueue = new QueuedHandler(controller, "Main Queue");
            controller.SetMainQueue(mainQueue);
            Application.Start(i =>
                {
                    slim.Set();
                    termination(i);
                });

            var http = new PlatformServerApiService(mainQueue, String.Format("http://{0}:{1}/", options.LocalHttpIp, options.HttpPort));

            bus.Subscribe<SystemMessage.Init>(http);
            bus.Subscribe<SystemMessage.StartShutdown>(http);

            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));
            bus.Subscribe<TimerMessage.Schedule>(timer);

            // switch, based on configuration
            AzureStoreConfiguration azureConfig;
            if (AzureStoreConfiguration.TryParse(options.StoreLocation, out azureConfig))
            {
                var storageService = new AzureStorageService(azureConfig, mainQueue);
                bus.Subscribe<ClientMessage.AppendEvents>(storageService);
                bus.Subscribe<SystemMessage.Init>(storageService);
                bus.Subscribe<ClientMessage.ImportEvents>(storageService);
                bus.Subscribe<ClientMessage.RequestStoreReset>(storageService);
            }
            else
            {
                var storageService = new FileStorageService(options.StoreLocation, mainQueue);
                bus.Subscribe<ClientMessage.AppendEvents>(storageService);
                bus.Subscribe<SystemMessage.Init>(storageService);
                bus.Subscribe<ClientMessage.ImportEvents>(storageService);
                bus.Subscribe<ClientMessage.RequestStoreReset>(storageService);
            }

            mainQueue.Start();

            mainQueue.Enqueue(new SystemMessage.Init());
            return new NodeEntryPoint(mainQueue,slim);
        }
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:50,代码来源:NodeEntryPoint.cs

示例4: setup

 public void setup()
 {
     _bus = new InMemoryBus("bus");
     _listEventsHandler = new TestHandler<ClientMessage.ReadStreamEventsBackward>();
     _bus.Subscribe(_listEventsHandler);
     _readDispatcher = new RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _writeDispatcher = new RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _subscriptionDispatcher =
         new PublishSubscribeDispatcher
             <ReaderSubscriptionManagement.Subscribe,
                 ReaderSubscriptionManagement.ReaderSubscriptionManagementMessage, EventReaderSubscriptionMessage>
             (_bus, v => v.SubscriptionId, v => v.SubscriptionId);
     _bus.Subscribe(
         _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CommittedEventReceived>());
     _bus.Subscribe(
         _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CheckpointSuggested>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.EofReached>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ProgressChanged>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.NotAuthorized>());
     _bus.Subscribe(_readDispatcher);
     _bus.Subscribe(_writeDispatcher);
     IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();
     _projectionConfig = new ProjectionConfig(null, 5, 10, 1000, 250, true, true, false, false);
     _coreProjection = CoreProjection.CreateAndPrepare(
         "projection", new ProjectionVersion(1, 0, 0), Guid.NewGuid(), _bus, projectionStateHandler, _projectionConfig, _readDispatcher,
         _writeDispatcher, _subscriptionDispatcher, null, new RealTimeProvider());
     _coreProjection.Start();
 }
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:31,代码来源:when_starting_a_projection.cs

示例5: setup0

 public void setup0()
 {
     _bus = new InMemoryBus("bus");
     _readDispatcher =
         new RequestResponseDispatcher
             <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted>(
             _bus, e => e.CorrelationId, e => e.CorrelationId, new PublishEnvelope(_bus));
     _writeDispatcher =
         new RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted>(
             _bus, e => e.CorrelationId, e => e.CorrelationId, new PublishEnvelope(_bus));
     _bus.Subscribe(_readDispatcher);
     _bus.Subscribe(_writeDispatcher);
     _consumer = new TestHandler<Message>();
     _bus.Subscribe(_consumer);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:15,代码来源:TestFixtureWithReadWriteDisaptchers.cs

示例6: Init

        public virtual void Init()
        {
            var sendOverHttpHandler = GetSendOverHttpProcessor();

            for (int i = 0; i < InstancesCnt; ++i)
            {
                var inputBus = new InMemoryBus(string.Format("ELECTIONS-INPUT-BUS-{0}", i));
                var outputBus = new InMemoryBus(string.Format("ELECTIONS-OUTPUT-BUS-{0}", i));
                var endPoint = new IPEndPoint(BaseEndPoint.Address, BaseEndPoint.Port + i);
                var nodeInfo = new VNodeInfo(Guid.NewGuid(), endPoint, endPoint, endPoint, endPoint, endPoint, endPoint);
                _instances.Add(new ElectionsInstance(nodeInfo.InstanceId, endPoint, inputBus, outputBus));

                sendOverHttpHandler.RegisterEndPoint(endPoint, inputBus);

                var electionsService = new Core.Services.ElectionsService(outputBus,
                                                                             nodeInfo,
                                                                             InstancesCnt,
                                                                             new InMemoryCheckpoint(),
                                                                             new InMemoryCheckpoint(),
                                                                             new FakeEpochManager(),
                                                                             () => -1, 0);
                electionsService.SubscribeMessages(inputBus);

                outputBus.Subscribe(sendOverHttpHandler);
                outputBus.Subscribe(new TimerMessageProcessor(Rnd,
                                                              Runner,
                                                              endPoint,
                                                              inputBus,
                                                              _timerMinDelay,
                                                              _timerMaxDelay));
                outputBus.Subscribe(new InnerBusMessagesProcessor(Runner, endPoint, inputBus));
            }
        }
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:33,代码来源:RandomizedElectionsTestCase.cs

示例7: Setup

 public void Setup()
 {
     _consumer = new WatchingConsumer();
     _bus = new InMemoryBus("temp");
     _bus.Subscribe(_consumer);
     _service = new ProjectionCoreService(_bus, _bus, 10, new InMemoryCheckpoint(1000));
     _service.Handle(new ProjectionMessage.CoreService.Start());
 }
开发者ID:soto,项目名称:EventStore,代码行数:8,代码来源:TestFixtureWithProjectionCoreService.cs

示例8: setup

 public void setup()
 {
     _bus = new InMemoryBus("bus");
     _listEventsHandler = new TestMessageHandler<ClientMessage.ReadStreamEventsBackward>();
     _bus.Subscribe(_listEventsHandler);
     _readDispatcher = new RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _writeDispatcher = new RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _bus.Subscribe(_readDispatcher);
     _bus.Subscribe(_writeDispatcher);
     _coreProjection = new CoreProjection(
         "projection", Guid.NewGuid(), _bus, new FakeProjectionStateHandler(),
         new ProjectionConfig(ProjectionMode.AdHoc, 5, 10, 1000, 250, true, true, true), _readDispatcher, _writeDispatcher);
     _coreProjection.Start();
 }
开发者ID:soto,项目名称:EventStore,代码行数:17,代码来源:when_starting_a_projection.cs

示例9: should_unsubscrible

 public void should_unsubscrible() {
   var bus = new InMemoryBus();
   bool subscriber_called = false;
   var handler =
     Handlers.Runnable<MyMessage>(msg => { subscriber_called = true; });
   bus.Subscribe(handler);
   bus.Unsubscribe(handler);
   bus.Publish(new MyMessage {Message = "MyMessage"});
   Assert.That(subscriber_called, Is.EqualTo(false));
 }
开发者ID:joethinh,项目名称:nohros-must,代码行数:10,代码来源:InMemoryBusTests.cs

示例10: should_publish_message_to_subscribers

 public void should_publish_message_to_subscribers() {
   var bus = new InMemoryBus();
   bool subscriber_called = false;
   bus.Subscribe(Handlers.Runnable<MyMessage>(msg => {
     Assert.That(msg.Message, Is.EqualTo("MyMessage"));
     subscriber_called = true;
   }));
   bus.Publish(new MyMessage {Message = "MyMessage"});
   Assert.That(subscriber_called, Is.EqualTo(true));
 }
开发者ID:joethinh,项目名称:nohros-must,代码行数:10,代码来源:InMemoryBusTests.cs

示例11: setup

 public void setup()
 {
     _bus = new InMemoryBus("bus");
     _listEventsHandler = new TestHandler<ClientMessage.ReadStreamEventsBackward>();
     _bus.Subscribe(_listEventsHandler);
     _readDispatcher = new RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _writeDispatcher = new RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted>(
         _bus, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_bus));
     _bus.Subscribe(_readDispatcher);
     _bus.Subscribe(_writeDispatcher);
     IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();
     _projectionConfig = new ProjectionConfig(5, 10, 1000, 250, true, true, false, false);
     _coreProjection = CoreProjection.CreateAndPrepapre(
         "projection", Guid.NewGuid(), _bus, projectionStateHandler, _projectionConfig, _readDispatcher,
         _writeDispatcher, null);
     _coreProjection.Start();
 }
开发者ID:base31,项目名称:geteventstore_EventStore,代码行数:19,代码来源:when_starting_a_projection.cs

示例12: setup

 public void setup()
 {
     _bus = new InMemoryBus("bus");
     _listEventsHandler = new TestMessageHandler<ClientMessage.ReadEventsBackwards>();
     _bus.Subscribe(_listEventsHandler);
     _coreProjection = new CoreProjection(
         "projection", Guid.NewGuid(), _bus, new FakeProjectionStateHandler(),
         new ProjectionConfig(ProjectionMode.AdHoc, 5, 10, 1000, 250, true, true, true));
     _coreProjection.Start();
 }
开发者ID:vishal-h,项目名称:EventStore-1,代码行数:10,代码来源:when_starting_a_projection.cs

示例13: Build

        public ReconnectionHandler Build()
        {
            var outputBus = new InMemoryBus("OutputBus");
            var mainQueue = new QueuedHandler(outputBus, "Main Queue");

            // TIMER
            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));
            outputBus.Subscribe(timer);

            //ALERTER
            var alerter = new Alerter();
            outputBus.Subscribe<AlertReconnectingForTooLong>(alerter);
            outputBus.Subscribe<AlertFalseAlarm>(alerter);

            var connectionHandler = new ReconnectionHandler(mainQueue);
            outputBus.Subscribe(connectionHandler);
            mainQueue.Start();
            return connectionHandler;
        }
开发者ID:jfloodnet,项目名称:ReconnectionAlerter,代码行数:19,代码来源:ConnectionExtensions.cs

示例14: setup

        public void setup()
        {
            _bus = new InMemoryBus("bus");
            _consumer = new WatchingConsumer();
            _bus.Subscribe(_consumer);

            _manager = new ProjectionManager(_bus, checkpointForStatistics: null);
            _bus.Subscribe<ProjectionMessage.Projections.Stopped>(_manager);
            _projectionName = "test-projection";
            _manager.Handle(
                new ProjectionManagementMessage.Post(
                    new PublishEnvelope(_bus), ProjectionMode.AdHoc, _projectionName, "JS",
                    @"fromAll(); on_any(function(){});log(1);", enabled: true));
            // when
            _newProjectionSource = @"fromAll(); on_any(function(){});log(2);";
            _manager.Handle(
                new ProjectionManagementMessage.UpdateQuery(
                    new PublishEnvelope(_bus), _projectionName, "JS", _newProjectionSource));
        }
开发者ID:vishal-h,项目名称:EventStore-1,代码行数:19,代码来源:when_updating_an_adhoc_projection_query_text.cs

示例15: Test2

        public void Test2()
        {
            var bus = new InMemoryBus("a", true);
            bus.Subscribe(new AdHocHandler<StorageMessage.WriteCommit>(x => { }));
            bus.Subscribe(new AdHocHandler<Message>(x => { }));

            var msg = new StorageMessage.WriteCommit(Guid.NewGuid(), new NoopEnvelope(), 0);
            const int iterations = 1000000;

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < iterations; ++i)
            {
                bus.Handle(msg);
            }

            sw.Stop();

            Console.WriteLine("Elapsed: {0} ({1} per item).", sw.Elapsed, sw.ElapsedMilliseconds / (float)iterations);
        }
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:20,代码来源:FSMSpeedTest.cs


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