public void OneTimeSetUp() { _container = new Container(configuration => configuration.AddRegistry <BusRegistry>()); _bus = BusFactory.Create("TestE2E", "tcp://localhost:8080", "tcp://localhost:8080", _container); _directoryRepository = _container.GetInstance <IPeerRepository>(); }
/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(string[] args) { LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(); // super bad resolver DependencyResolverFunc dependencyResolver = (name, type) => new SomeHandler(); var configurator = new AppConfigConfigurator(dependencyResolver); var busFactory = new BusFactory(); IBus consumer = busFactory.Create(cfg => configurator.Configure("Consumer", cfg)); IBus producer = busFactory.Create(cfg => configurator.Configure("Producer", cfg)); using (new Timer(_ => producer.Emit(":msg", new { }), null, 0, 1000)) { Console.ReadKey(false); } producer.Dispose(); consumer.Dispose(); }
public void OneTimeSetUp() { var container = new Container(configuration => configuration.AddRegistry <BusRegistry>()); _directory = container.GetInstance <IPeerDirectory>(); container.Configure((conf) => { conf.For <ITransport>().Use <TestBusTransport>(); }); _bus = BusFactory.Create("TestE2E", "tcp://localhost:8080", "tcp://localhost:8080", container); }
static void Main(string[] args) { _bus = BusFactory.Create("directory", Constants.EndpointDirectory, Constants.EndpointDirectory); _bus.Start(); Console.Read(); while (true) { _bus.Send(new DoSomething()); Task.Delay(1500); } }
static async Task Main(string[] args) { Console.WriteLine("Starting Producer...."); var bus = BusFactory.Create(); await bus.StartAsync(); await bus.Publish(new Information("some message data")); await Task.Delay(5000); await bus.Publish(new Alert()); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await bus.StopAsync(); }
static void Main(string[] args) { _bus = BusFactory.Create("peer2", Constants.EndpointPeer2, Constants.EndpointDirectory); _bus.Start(); var subscription1 = Subscription.Matching <DatabaseStatus>(ev => ev.DatacenterName == Constants.Paris); var subscription2 = Subscription.Any <DoSomething>(); _bus.Subscribe(new SubscriptionRequest(subscription1)).Wait(); _bus.Subscribe(new SubscriptionRequest(subscription2)).Wait(); Task.Delay(100).Wait(); while (true) { _bus.Publish(DatabaseStatus.Create(Constants.London)); Task.Delay(1000); } }
static async Task Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting Consumer2...."); var bus = BusFactory.Create((config, host) => { config.ReceiveEndpoint(host, "consumer_2_queue", q => { q.Consumer(() => new Handler()); }); }); await bus.StartAsync(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await bus.StopAsync(); }
static void Main() { try { var bus = BusFactory.Create(); var bar = new Bar(bus); bar.DoIt(); Console.ReadKey(); bus.Dispose(); } catch (Exception exception) { DisplayException(exception); } finally { DisplayExitPrompt(); } }
static async Task Main(string[] args) { LoggerFactory.SetupMassTransitLogger(); var bus = BusFactory.Create(); try { TaskUtil.Await(() => bus.StartAsync()); while (true) { try { Console.Write("Enter something (quit exits): "); var line = Console.ReadLine(); if (line == "quit") { break; } await bus.Publish <OrderPizzaMessage>(new { Amount = 10.0m, CardNumber = "1234", Type = line, }); } catch (Exception ex) { Console.WriteLine($"Error occurred: {ex}"); } } } finally { TaskUtil.Await(() => bus.StopAsync()); } }
static void Main() { Dealer dealer = new Dealer("Фаворит моторс"); MashinFactoryBase suzukiMotors = new CarsFactory("Suzuki Motors", "Suzuki"); MashinFactoryBase vwGroupe = new SUVFactory("VW Motors SUV", "VW"); MashinFactoryBase man = new BusFactory("Man Neoplan", "Man"); CarBase[] cars = new CarBase[] { suzukiMotors.Create(BodyNames.Sedan, 4, 4, 5, TypesOfDrive.Mono2, "SX-4", "1", Colors.Black, 1250d, 800, 1_200_000), suzukiMotors.Create(BodyNames.Hatchback, 5, 4, 5, TypesOfDrive.Full4, "SX-4", "1", Colors.Yellow, 1280d, 850d, 1_200_000), vwGroupe.Create(BodyNames.Wagon, 5, 4, 5, TypesOfDrive.Full4, "Tuareg FX", "2", Colors.White, 2300d, 120d, 4_500_000), man.Create(BodyNames.Bus, 1, 6, 40, TypesOfDrive.Full4, "Neoplan CityLiner", "1", Colors.Black, 5_000d, 8_000d, 15_000_000) };
public async Task TestStartPeer() { var configuration = new BusConfiguration() { PeerName = "London", Endpoint = "tcp://localhost:8585", DirectoryEndpoint = "tcp://localhost:8585", IsPeerDirectory = true }; var bus = BusFactory.Create <TestPushPullRegistry>(configuration); var dispatcher = bus.Container.GetInstance <IMessageDispatcher>(); var handler1 = bus.Container.GetInstance <IEventHandler <MajorEventOccured> >(); var handler2 = bus.Container.GetInstance <IEventHandler <MinorEventOccured> >(); bus.Register(handler1); bus.Register(handler2); await Task.Delay(500); Assert.AreEqual(2, dispatcher.HandledEvents.Count); Assert.IsTrue(dispatcher.HandledEvents.Any(ev => ev.GetType() == typeof(PeerRegisterCommand))); Assert.IsTrue(dispatcher.HandledEvents.Any(ev => ev.GetType() == typeof(PeerRegisterCommandResult))); bus.Subscribe <MajorEventOccured>(); bus.Subscribe <MinorEventOccured>(ev => ev.Perimeter >= Perimeter.Infra); await Task.Delay(500); //2*2 PeerUpdatedEvent (PeerDirectory + Directory) Assert.AreEqual(6, dispatcher.HandledEvents.Count); Assert.AreEqual(4, dispatcher.HandledEvents.Count(ev => ev.GetType() == typeof(PeerUpdatedEvent))); var directory = bus.Container.GetInstance <IDirectory>(); var peerDirectory = bus.Container.GetInstance <IPeerDirectory>(); Assert.AreEqual(1, directory.GetMatchedPeers(new MajorEventOccured()).Count()); Assert.AreEqual(1, peerDirectory.StateOfTheWorld.Count()); Assert.AreEqual(1, peerDirectory.StateOfTheWorld.First().Subscriptions.Count(sub => sub.EventType == typeof(MajorEventOccured))); Assert.AreEqual(1, peerDirectory.StateOfTheWorld.First().Subscriptions.Count(sub => sub.EventType == typeof(MinorEventOccured))); bus.Emit(new MajorEventOccured() { Severity = Severity.Fatal, Message = "Oh no!" }); await Task.Delay(300); Assert.AreEqual(7, dispatcher.HandledEvents.Count); Assert.IsTrue(dispatcher.HandledEvents.Any(ev => ev.GetType() == typeof(MajorEventOccured))); bus.Emit(new MinorEventOccured() { Perimeter = Perimeter.Global, Message = "Oh no!" }); await Task.Delay(100); Assert.AreEqual(8, dispatcher.HandledEvents.Count); Assert.IsTrue(dispatcher.HandledEvents.Any(ev => ev.GetType() == typeof(MinorEventOccured))); bus.Emit(new MinorEventOccured() { Perimeter = Perimeter.Business, Message = "Oh no!" }); await Task.Delay(100); Assert.AreEqual(8, dispatcher.HandledEvents.Count); bus.Stop(); }
public async Task TestE2E() { var cancel = new CancellationTokenSource(); IMessageDispatcher _dispatcher1 = null; IMessageDispatcher _dispatcher2 = null; IBus _peer2 = null; IBus _peer1 = null; var peer1EventCount = 0; var peer2EventCount = 0; new Task(async() => { var configuration = new BusConfiguration() { PeerName = "London", Endpoint = "tcp://localhost:8181", DirectoryEndpoint = "tcp://localhost:8181", IsPeerDirectory = true }; _peer1 = BusFactory.Create <TestPushPullRegistry>(configuration); _dispatcher1 = _peer1.Container.GetInstance <IMessageDispatcher>(); var handler1 = _peer1.Container.GetInstance <IEventHandler <MajorEventOccured> >(); var handler2 = _peer1.Container.GetInstance <IEventHandler <MinorEventOccured> >(); _peer1.Register(handler1); _peer1.Register(handler2); _peer1.Subscribe <MajorEventOccured>(); _peer1.Subscribe <MinorEventOccured>(ev => ev.Perimeter >= Perimeter.Infra); while (!cancel.IsCancellationRequested) { _peer1.Emit(new MinorEventOccured() { Perimeter = Perimeter.Infra, Message = "Oh no!" }); peer1EventCount++; await Task.Delay(500); } }, cancel.Token).Start(); await Task.Delay(1000); new Task(async() => { var configuration = new BusConfiguration() { PeerName = "Paris", Endpoint = "tcp://localhost:8282", DirectoryEndpoint = "tcp://localhost:8181" }; _peer2 = BusFactory.Create <TestPushPullRegistry>(configuration); _dispatcher2 = _peer2.Container.GetInstance <IMessageDispatcher>(); var handler1 = _peer2.Container.GetInstance <IEventHandler <MajorEventOccured> >(); var handler2 = _peer2.Container.GetInstance <IEventHandler <MinorEventOccured> >(); _peer2.Register(handler1); _peer2.Register(handler2); _peer2.Subscribe <MajorEventOccured>(); _peer2.Subscribe <MinorEventOccured>(ev => ev.Perimeter >= Perimeter.Infra); while (!cancel.IsCancellationRequested) { _peer2.Emit(new MajorEventOccured() { Severity = Severity.Error, Message = "Oh no!" }); peer2EventCount++; await Task.Delay(500); } }, cancel.Token).Start(); await Task.Delay(2000); cancel.Cancel(); _peer1.Stop(); _peer2.Stop(); Assert.IsNotNull(_dispatcher1); Assert.IsNotNull(_dispatcher2); //at least 1/3 events should be processed... Assert.IsTrue(_dispatcher1.HandledEvents.Where(ev => ev.GetType() == typeof(MajorEventOccured)).Count() > peer1EventCount / 3); Assert.IsTrue(_dispatcher1.HandledEvents.Where(ev => ev.GetType() == typeof(MinorEventOccured)).Count() > peer1EventCount / 3); Assert.IsTrue(_dispatcher2.HandledEvents.Where(ev => ev.GetType() == typeof(MajorEventOccured)).Count() > peer2EventCount / 3); Assert.IsTrue(_dispatcher2.HandledEvents.Where(ev => ev.GetType() == typeof(MinorEventOccured)).Count() > peer2EventCount / 3); }
public void OneTimeSetUp() { _bus = BusFactory.Create("TestE2E", "tcp://localhost:8585", "tcp://localhost:8585"); _bus.Start(); }