本文整理汇总了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();
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
示例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));
}
}
示例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());
}
示例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();
}
示例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));
}
示例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));
}
示例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();
}
示例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();
}
示例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;
}
示例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));
}
示例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);
}