本文整理汇总了C#中InMemoryBus类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryBus类的具体用法?C# InMemoryBus怎么用?C# InMemoryBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryBus类属于命名空间,在下文中一共展示了InMemoryBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setup
public void setup()
{
_checkpointUnhandledBytesThreshold = 1000;
_checkpointProcessedEventsThreshold = 2000;
Given();
_bus = new InMemoryBus("bus");
_projectionCorrelationId = Guid.NewGuid();
_eventHandler = new TestHandler<EventReaderSubscriptionMessage.CommittedEventReceived>();
_checkpointHandler = new TestHandler<EventReaderSubscriptionMessage.CheckpointSuggested>();
_progressHandler = new TestHandler<EventReaderSubscriptionMessage.ProgressChanged>();
_subscriptionStartedHandler = new TestHandler<EventReaderSubscriptionMessage.SubscriptionStarted>();
_notAuthorizedHandler = new TestHandler<EventReaderSubscriptionMessage.NotAuthorized>();
_eofHandler = new TestHandler<EventReaderSubscriptionMessage.EofReached>();
_partitionEofHandler = new TestHandler<EventReaderSubscriptionMessage.PartitionEofReached>();
_partitionMeasuredHandler = new TestHandler<EventReaderSubscriptionMessage.PartitionMeasured>();
_bus.Subscribe(_eventHandler);
_bus.Subscribe(_checkpointHandler);
_bus.Subscribe(_progressHandler);
_bus.Subscribe(_eofHandler);
_bus.Subscribe(_partitionEofHandler);
_bus.Subscribe(_partitionMeasuredHandler);
_readerStrategy = CreateCheckpointStrategy();
_subscription = CreateProjectionSubscription();
When();
}
示例2: Projections
public Projections(
TFChunkDb db, QueuedHandler mainQueue, InMemoryBus mainBus, TimerService timerService,
HttpService httpService, int projectionWorkerThreadCount)
{
_projectionWorkerThreadCount = projectionWorkerThreadCount;
SetupMessaging(db, mainQueue, mainBus, timerService, httpService);
}
示例3: 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));
}
}
示例4: 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();
}
示例5: 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();
}
示例6: setup
public void setup()
{
_bus = new InMemoryBus("bus");
_listEventsHandler = new TestHandler<ClientMessage.ReadStreamEventsBackward>();
_bus.Subscribe(_listEventsHandler);
_ioDispatcher = new IODispatcher(_bus, new PublishEnvelope(_bus));
_subscriptionDispatcher =
new ReaderSubscriptionDispatcher
(_bus);
_bus.Subscribe(
_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CommittedEventReceived>());
_bus.Subscribe(
_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CheckpointSuggested>());
_bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.EofReached>());
_bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionEofReached>());
_bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionMeasured>());
_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(_ioDispatcher.BackwardReader);
_bus.Subscribe(_ioDispatcher.ForwardReader);
_bus.Subscribe(_ioDispatcher.Writer);
_bus.Subscribe(_ioDispatcher);
IProjectionStateHandler projectionStateHandler = new FakeProjectionStateHandler();
_projectionConfig = new ProjectionConfig(null, 5, 10, 1000, 250, true, true, false, false, false);
var version = new ProjectionVersion(1, 0, 0);
var projectionProcessingStrategy = new ContinuousProjectionProcessingStrategy(
"projection", version, projectionStateHandler, _projectionConfig,
projectionStateHandler.GetSourceDefinition(), null, _subscriptionDispatcher);
_coreProjection = projectionProcessingStrategy.Create(
Guid.NewGuid(), _bus, SystemAccount.Principal, _bus, _ioDispatcher, _subscriptionDispatcher,
new RealTimeProvider());
_coreProjection.Start();
}
示例7: ProjectionManagerNode
private ProjectionManagerNode(IPublisher inputQueue, IPublisher[] queues, RunProjections runProjections)
{
_runProjections = runProjections;
_output = new InMemoryBus("ProjectionManagerOutput");
_projectionManager = new ProjectionManager(
inputQueue, _output, queues, new RealTimeProvider(), runProjections);
}
示例8: 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());
}
示例9: BuildAuthenticationProvider
public IAuthenticationProvider BuildAuthenticationProvider(IPublisher mainQueue, IBus mainBus, IPublisher workersQueue, InMemoryBus[] workerBusses)
{
var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm();
var dispatcher = new IODispatcher(mainQueue, new PublishEnvelope(workersQueue, crossThread: true));
foreach (var bus in workerBusses) {
bus.Subscribe(dispatcher.ForwardReader);
bus.Subscribe(dispatcher.BackwardReader);
bus.Subscribe(dispatcher.Writer);
bus.Subscribe(dispatcher.StreamDeleter);
bus.Subscribe(dispatcher);
}
// USER MANAGEMENT
var ioDispatcher = new IODispatcher(mainQueue, new PublishEnvelope(mainQueue));
mainBus.Subscribe(ioDispatcher.BackwardReader);
mainBus.Subscribe(ioDispatcher.ForwardReader);
mainBus.Subscribe(ioDispatcher.Writer);
mainBus.Subscribe(ioDispatcher.StreamDeleter);
mainBus.Subscribe(ioDispatcher);
var userManagement = new UserManagementService(mainQueue, ioDispatcher, passwordHashAlgorithm, skipInitializeStandardUsersCheck: false);
mainBus.Subscribe<UserManagementMessage.Create>(userManagement);
mainBus.Subscribe<UserManagementMessage.Update>(userManagement);
mainBus.Subscribe<UserManagementMessage.Enable>(userManagement);
mainBus.Subscribe<UserManagementMessage.Disable>(userManagement);
mainBus.Subscribe<UserManagementMessage.Delete>(userManagement);
mainBus.Subscribe<UserManagementMessage.ResetPassword>(userManagement);
mainBus.Subscribe<UserManagementMessage.ChangePassword>(userManagement);
mainBus.Subscribe<UserManagementMessage.Get>(userManagement);
mainBus.Subscribe<UserManagementMessage.GetAll>(userManagement);
mainBus.Subscribe<SystemMessage.BecomeMaster>(userManagement);
return new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, ESConsts.CachedPrincipalCount);
}
示例10: TestFixtureSetUp
public override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
WriterCheckpoint = new InMemoryCheckpoint(0);
ChaserCheckpoint = new InMemoryCheckpoint(0);
Bus = new InMemoryBus("bus");
IODispatcher = new IODispatcher(Bus, new PublishEnvelope(Bus));
Db = new TFChunkDb(new TFChunkDbConfig(PathName,
new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
10000,
0,
WriterCheckpoint,
ChaserCheckpoint,
new InMemoryCheckpoint(-1),
new InMemoryCheckpoint(-1)));
Db.Open();
// create db
Writer = new TFChunkWriter(Db);
Writer.Open();
WriteTestScenario();
Writer.Close();
Writer = null;
WriterCheckpoint.Flush();
ChaserCheckpoint.Write(WriterCheckpoint.Read());
ChaserCheckpoint.Flush();
var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint));
var lowHasher = new XXHashUnsafe();
var highHasher = new Murmur3AUnsafe();
TableIndex = new TableIndex(GetFilePathFor("index"), lowHasher, highHasher,
() => new HashListMemTable(PTableVersions.Index64Bit, MaxEntriesInMemTable * 2),
() => new TFReaderLease(readers),
PTableVersions.Index64Bit,
MaxEntriesInMemTable);
ReadIndex = new ReadIndex(new NoopPublisher(),
readers,
TableIndex,
0,
additionalCommitChecks: true,
metastreamMaxCount: MetastreamMaxCount,
hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault);
ReadIndex.Init(ChaserCheckpoint.Read());
// scavenge must run after readIndex is built
if (_scavenge)
{
if (_completeLastChunkOnScavenge)
Db.Manager.GetChunk(Db.Manager.ChunksCount - 1).Complete();
_scavenger = new TFChunkScavenger(Db, IODispatcher, TableIndex, ReadIndex, Guid.NewGuid(), "fakeNodeIp");
_scavenger.Scavenge(alwaysKeepScavenged: true, mergeChunks: _mergeChunks);
}
}
示例11: 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());
}
示例12: ProjectionWorkerNode
public ProjectionWorkerNode(TFChunkDb db, QueuedHandler inputQueue)
{
Ensure.NotNull(db, "db");
_coreOutput = new InMemoryBus("Core Output");
_projectionCoreService = new ProjectionCoreService(CoreOutput, inputQueue, 10, db.Config.WriterCheckpoint);
}
示例13: SetUp
public void SetUp()
{
_bus = new InMemoryBus(string.Format("bus_{0}", _serverEndPoint.Port));
_service = new HttpService(ServiceAccessibility.Private, _bus, 1, _serverEndPoint.ToHttpUrl());
_client = new HttpAsyncClient();
HttpBootstrap.Subscribe(_bus, _service);
}
示例14: 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));
}
示例15: 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));
}