static void Main(string[] args) { Console.WriteLine("Trying to connect to RabbitMQ instance @locahost with guest:guest"); var loggerFactory = new LoggerFactory(); var network = RabbitNetworkInfos.GetConfigurationFor("client", RabbitMQExchangeStrategy.SingleExchange); //This network will produce a client_queue queue, bound to cqelight_global_exchange new Bootstrapper() .UseRabbitMQ( ConnectionInfosHelper.GetConnectionInfos("client"), network ) .UseAutofacAsIoC(c => c.Register(_ => loggerFactory).AsImplementedInterfaces().ExternallyOwned()) .Bootstrapp(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Successfuly connected to RabbitMQ"); Console.ResetColor(); Console.WriteLine("Enter your message and press enter to send to server, or enter 'quit' to exit process"); var data = Console.ReadLine(); while (data != "quit") { CoreDispatcher.PublishEventAsync(new NewMessage { Payload = data }); data = Console.ReadLine(); } }
public async Task PublishEventRangeAsync() { await CoreDispatcher.PublishEventAsync(new Evt()); await CoreDispatcher.PublishEventAsync(new Evt2()); await CoreDispatcher.PublishEventAsync(new Evt3()); }
static async Task Main(string[] args) { new Bootstrapper(new BootstrapperOptions { AutoLoad = true }).Bootstrapp(); await CoreDispatcher.PublishEventAsync(new GreetingsEvent()).ConfigureAwait(false); Console.Read(); }
static async Task Main(string[] args) { new Bootstrapper(). UseInMemoryEventBus() .Bootstrapp(); await CoreDispatcher.PublishEventAsync(new GreetingsEvent()).ConfigureAwait(false); Console.Read(); }
/// <summary> /// Helper method to publish an event through Saga custom dispatcher or, if not defined, CoreDispatcher. /// </summary> /// <param name="event">Command to dispatch.</param> protected Task DispatchEventAsync(IDomainEvent @event) { if (_dispatcher != null) { return(_dispatcher.PublishEventAsync(@event, this)); } else { return(CoreDispatcher.PublishEventAsync(@event, this)); } }
/// <summary> /// This is the main asynchronous method that get called when handler is created and should be invoked. /// </summary> public async Task <Result> HandleAsync(SendMessageCommand command, ICommandContext context = null) { // Act with your business logic. // Command handler should handle infrastructural issues to keep domain pure. System.Console.ForegroundColor = ConsoleColor.DarkGreen; System.Console.WriteLine($"New message received : {command.Message}"); System.Console.ForegroundColor = ConsoleColor.White; await CoreDispatcher.PublishEventAsync(new MessageTreatedEvent(Guid.NewGuid(), command.Message)).ConfigureAwait(false); return(Result.Ok()); }
public async Task <Result> HandleAsync(CreerFamilleCommand command, ICommandContext context = null) { Famille._nomFamilles = (await _familleRepository.GetAllFamillesAsync().ConfigureAwait(false)).Select(f => new NomFamille(f.Nom)).ToList(); var result = Famille.CreerFamille(command.Nom); if (result && result is Result <NomFamille> resultFamille) { await CoreDispatcher.PublishEventAsync(new FamilleCreee(resultFamille.Value)); return(Result.Ok()); } return(result); }
public async Task AutoLoad_Should_Enable_Bus_WithDefaultConfig() { AutoLoadDomainEventHandler.Called = false; try { new Bootstrapper(new BootstrapperOptions { AutoLoad = true }).Bootstrapp(); await CoreDispatcher.PublishEventAsync(new AutoLoadDomainEvent()); AutoLoadDomainEventHandler.Called.Should().BeTrue(); } finally { AutoLoadDomainEventHandler.Called = false; } }
public async Task OnEventDispatched_Should_Be_Called_On_Publish() { bool called = false; Func <IDomainEvent, Task> lambda = async(e) => called = true; try { var evt1 = new EventDispatchedOne(); CoreDispatcher.OnEventDispatched += lambda; await CoreDispatcher.PublishEventAsync(evt1); called.Should().BeTrue(); } finally { CoreDispatcher.OnEventDispatched -= lambda; } }
public Task PublishAsync() { return(CoreDispatcher.PublishEventAsync(new Evt())); }
public async Task <Result> HandleAsync(SayHello command, ICommandContext context = null) { await CoreDispatcher.PublishEventAsync(new HelloSaid()); return(Result.Ok()); }