本文整理汇总了C#中Bus.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.Subscribe方法的具体用法?C# Bus.Subscribe怎么用?C# Bus.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bus
的用法示例。
在下文中一共展示了Bus.Subscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EventTest
public void EventTest()
{
var bus = new Bus(null, new HandlerRegistry());
int called = 0;
bus.Subscribe<WidgetCreatedEvent>((x) => called++);
bus.Subscribe<WidgetCreatedEvent>((x) => called++);
bus.Publish(new WidgetCreatedEvent());
Assert.AreEqual(2, called);
}
示例2: When_testing_something
public void When_testing_something()
{
var bus1 = new Bus();
bus1.Subscribe("first", x => _output.WriteLine("Bus1 => ({0}) => {1}", "first", x.Json));
bus1.Subscribe("second", x => _output.WriteLine("Bus1 => ({0}) => {1}", "second", x.Json));
var bus2 = new Bus();
bus2.Subscribe("first", x => _output.WriteLine("Bus2 => ({0}) => {1}", "first", x.Json));
bus2.Subscribe("second", x => _output.WriteLine("Bus2 => ({0}) => {1}", "second", x.Json));
var exchange = new Exchange();
exchange.AddBus(bus1);
exchange.AddBus(bus2);
bus1.Publish("first", new Message { Json = "a message"});
}
示例3: WithBus
public static ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator WithBus(
this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator configure)
{
var bus = new Bus();
var messages = new Collection<Message>();
typeof (Message).Assembly.GetTypes().Union(typeof(Extensions).Assembly.GetTypes())
.Where(typeof (Message).IsAssignableFrom)
.Where(type => false == type.IsAbstract && type.IsClass)
.ForEach(messageType => bus.Subscribe(messageType, new AdHocHandler<Message>(
m =>
{
messages.Add(m);
})));
configure.ApplicationStartup(
(_, pipelines) => pipelines.AfterRequest.AddItemToStartOfPipeline(
context => { context.Items[SystemUnderTest.MessagesKey] = messages; }));
return configure.Dependency(bus);
}
示例4: Main
static void Main(string[] args)
{
var bus = new Bus(new Dispatcher.Dispatcher());
var printers = new[] { new Printer(bus, 1), new Printer(bus, 2), new Printer(bus, 3), new Printer(bus, 4) };
var printerPool = printers
.Select(printer => new WideningHandler<PrintJob, Message>(printer))
.Select(printer => new QueuedHandler(printer, bus) { MaxQueueLength = 1 })
.ToArray();
var refillPool = printers
.Select(printer => new WideningHandler<RefillPaper, Message>(printer))
.Select(printer => new QueuedHandler(printer, bus) { MaxQueueLength = 1 })
.ToArray();
foreach (var printer in refillPool)
{
bus.Subscribe<RefillPaper>(new NarrowingHandler<RefillPaper, Message>(printer));
// subscribe the printer directly to RefillPaper as we don't want to distribute that with the print jobs
}
var office = Enumerable.Range(0, 50)
.Select(i => new Employee(bus, i))
.ToArray();
var loadBalancer = new RoundRobinLoadBalancer(printerPool);
var printerRetryHandler = new RetryHandler(loadBalancer, bus);
var retryManager = new RetryManager(bus);
var timerService = new TimerService(bus);
bus.Subscribe<FutureMessage>(timerService);
bus.Subscribe<RetryMessage>(retryManager);
bus.Subscribe<SuccessMessage>(retryManager);
bus.Subscribe(new NarrowingHandler<PrintJob, Message>(printerRetryHandler));
var console = new QueuedHandler(new WideningHandler<LogMessage, Message>(new ConsoleHandler()), bus);
bus.Subscribe<LogMessage>(new NarrowingHandler<LogMessage, Message>(console));
var porter = new Porter(bus);
bus.Subscribe(porter);
var converter = new LogConverter(bus);
bus.Subscribe<PrintJob>(converter);
bus.Subscribe<OutOfPaper>(converter);
bus.Subscribe<PagePrinted>(converter);
bus.Subscribe<RetryMessage>(converter);
}