static async Task Main(string[] args) { string connectionString = "Server=NAG6CHANDRVAR01;Database=OrderDb;Trusted_Connection=True;"; var builder = new HostBuilder() .ConfigureServices((hostContext, services) => { services.AddMassTransit(cfg => { cfg.AddSagaStateMachine <OrderStateMachine, OrderStateData>() .EntityFrameworkRepository(r => { r.ConcurrencyMode = ConcurrencyMode.Pessimistic; // or use Optimistic, which requires RowVersion r.AddDbContext <DbContext, OrderStateDbContext>((provider, builder) => { builder.UseSqlServer(connectionString, m => { m.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name); m.MigrationsHistoryTable($"__{nameof(OrderStateDbContext)}"); }); }); }); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider)); }); services.AddMassTransitHostedService(); }); await builder.RunConsoleAsync(); }
private void ConfigureHandlers() { var redis = ConnectionMultiplexer.Connect("localhost"); var productView = new ProductView(new RedisReadModelRepository<ProductDto>(redis.GetDatabase())); ServiceLocator.ProductView = productView; var eventMappings = new EventHandlerDiscovery() .Scan(productView) .Handlers; var subscriptionName = "admin_readmodel"; var topicFilter1 = "Admin.Common.Events"; var b = RabbitHutch.CreateBus("host=localhost"); b.Subscribe<PublishedMessage>(subscriptionName, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter1)); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; }
private void ConfigureHandlers() { var redis = ConnectionMultiplexer.Connect("localhost"); var brandView = new OrderView(new RedisReadModelRepository<OrderDto>(redis.GetDatabase())); ServiceLocator.BrandView = brandView; var eventMappings = new EventHandlerDiscovery() .Scan(brandView) .Handlers; var messageBusEndPoint = "cashier_readmodel"; var topicFilter = "Cashier.Common.Events"; var b = RabbitHutch.CreateBus("host=localhost"); b.Subscribe<PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; }
public Consumer() { _messageHandlerInvokerCache = new MessageHandlerInvokerCache(); _rabbitMqBus = IntegrationTestsHelper.GetRabbitMqBus(); _rabbitMqBus.SubscribeToExchange(new RabbitMqEventSubscription <TestEventOne>("testevent-exchange", "topic", onMessage: (ev) => { var candidateHandler = _messageHandlerInvokerCache.GetMethodInfo(GetType(), typeof(TestEventOne)); if (null != candidateHandler) { ((Task)candidateHandler.Invoke(this, new object[] { ev.Content })).Wait(); } return(Task.CompletedTask); }, isExchangeDurable: false, isExchangeAutoDelete: true, isQueueDurable: false, isQueueAutoAck: false, isQueueAutoDelete: true, isQueueExclusive: true, routingStrategy: (ev) => ev.FilterOne == "filterOne")); }
public static void AddServiceBus(this IServiceCollection service, string endPointId, string endPointName) { var rabbitMqBusInstance = new RabbitMqBus(endPointId, endPointName); service.AddSingleton(typeof(IRabbitMqBus), rabbitMqBusInstance); service.AddSingleton(typeof(RabbitMqBus), rabbitMqBusInstance); }
private void ConfigureHandlers() { var redis = ConnectionMultiplexer.Connect("localhost"); var productView = new ProductView(new RedisReadModelRepository <ProductDto>(redis.GetDatabase())); ServiceLocator.ProductView = productView; var eventMappings = new EventHandlerDiscovery() .Scan(productView) .Handlers; var subscriptionName = "Microservices_Products_ReadModels_API"; var topicFilter1 = "Microservices.Products.Infrastructure.Events"; var b = RabbitHutch.CreateBus("host=localhost"); b.Subscribe <PublishedMessage>(subscriptionName, m => { EventHandlerData eventHandlerData; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType.Name, out eventHandlerData); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, eventHandlerData.TypeParameter); eventHandlerData.AggregateHandler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter1)); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMassTransit(cfg => { cfg.AddConsumer <OrderCardNumberValidateConsumer>(); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) => { cfg.UseHealthCheck(provider); //cfg.ReceiveEndpoint(BusConstants.OrderQueue, ep => //{ // ep.ConfigureConsumer<OrderCardNumberValidateConsumer>(provider); //}); })); }); services.AddMassTransitHostedService(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Card_ms", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(typeof(MappingProfile)); services.AddDbContext <BookContext>(options => options.UseSqlite("Data Source=Book.db")); services.AddControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddScoped <RatingConsumer>(); services.AddScoped <AddAmountConsumer>(); services.AddMassTransit(cfg => { cfg.AddConsumer <RatingConsumer>(); cfg.AddConsumer <AddAmountConsumer>(); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) => { cfg.ReceiveEndpoint(BusConstant.RateQueue, ep => { ep.ConfigureConsumer <RatingConsumer>(provider); }); cfg.ReceiveEndpoint(BusConstant.AddAmountQueue, ep => { ep.ConfigureConsumer <AddAmountConsumer>(provider); }); })); }); services.AddMassTransitHostedService(); services.AddAuthentication("Bearer") .AddJwtBearer("Bearer", options => { options.Authority = "https://localhost:3117"; options.RequireHttpsMetadata = false; options.Audience = "book"; }); services.AddCors(options => { options.AddPolicy("_myAllowSpecificOrigins", builder => { builder.WithOrigins( "http://localhost:3000", "http://localhost:3001" ) .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddScoped <BookService>(); services.AddScoped <CategoryService>(); services.AddScoped <ITokenConfiguration, TokenConfiguration>(); }
public void SetUp() { _rabbitMqBus = IntegrationTestsHelper.GetRabbitMqBus(); _counterTestEventOneNoFilter = 0; _counterTestEventTwoNoFilter = 0; _counterTestEventOneFilterOnFilterOne = 0; _counterTestEventTwoFilterOnFilterTwo = 0; }
private async static void AddPushRequestToQueue(string message) { Guid applicationId = Guid.NewGuid(); //one for an application Guid busId = Guid.NewGuid(); //Each instance of publishing bus var rmBus = new RabbitMqBus(); await Task.Run(() => rmBus.SendCommand(new CreateGdmsNotificationCommand(applicationId, Guid.NewGuid(), busId) { Message = message })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMassTransit(cfg => { cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider)); }); services.AddMassTransitHostedService(); }
private void ConfigureHandlers() { var bus = new RabbitMqBus(RabbitHutch.CreateBus("host=localhost")); ServiceLocator.Bus = bus; //Should get this from a config setting instead of hardcoding it. var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 12900)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.ProductCommands = new ProductCommandHandlers(repository); }
public async Task MainAsync() { var configClient = InternalConfigurationApiClientFactory.Create(GetConfiguration().GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var systemConfig = await configClient.GetConfigurationAsync(); // TODO : ideally queue name should be read from InternalConfigurationApi IMessageChannel messageChannel = new RabbitMqChannel(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer(), RabbitMqConsts.WorkerQueueName); IMessageBus messageBus = new RabbitMqBus(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer()); var worker = new WorkerService(messageChannel, messageBus, new ChannelPersistence(new MongoDbOptions(systemConfig.ChannelsDb.DbHost, systemConfig.ChannelsDb.DbName, systemConfig.ChannelsDb.CollectionName, systemConfig.ChannelsDb.User, systemConfig.ChannelsDb.Password))); worker.Start(); await Task.Delay(-1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMassTransit(cfg => { cfg.AddConsumer <BookingValidateConsumer>(); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) => { })); }); services.AddMassTransitHostedService(); services.AddControllers(); }
private void ConfigureHandlers() { var bus = new RabbitMqBus(RabbitHutch.CreateBus("host=localhost")); ServiceLocator.Bus = bus; var eventStorePort = 12800; var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, eventStorePort)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.OrderCommands = new OrderCommandHandlers(repository); }
public async Task RabbitMqBus_PublishSubscribe_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var rabbitMqListener = new RabbitMqListener(options, logger); var message = new TestMessage { Id = "1", String = "Test string", }; var count = 0; TestMessage result = null; rabbitMqListener.Subscribe("test", (TestMessage m) => { result = m; return(Task.FromResult(count++)); }, InteractionType.PublishSubscribe); var count2 = 0; TestMessage result2 = null; rabbitMqListener.Subscribe("test", (TestMessage m) => { result2 = m; return(Task.FromResult(count2++)); }, InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count >= 2 && count2 >= 2); count.ShouldBe(2); result.ShouldNotBeNull(); result.Id.ShouldBe(message.Id); result.String.ShouldBe(message.String); count2.ShouldBe(2); result2.ShouldNotBeNull(); result2.Id.ShouldBe(message.Id); result2.String.ShouldBe(message.String); }
/// <summary> /// Init the module with provided <see cref="LogicalPriorityMapper"/> /// </summary> /// <param name="mapper"></param> /// <param name="routeFinder">custom route finder</param> /// <returns></returns> public RabbitMqModule Load(LogicalPriorityMapper mapper, IRouteFinder routeFinder = null) { var internalBus = InternalBus.Current; var logger = DependencyResolver.Current.GetService<ILogger>() ?? new NullLogger(); _rabbitBus = new RabbitMqBus(logger, internalBus, mapper, MessageQueueConnectionString, Environment, SetupQueues); if (routeFinder != null) { _rabbitBus.SetRouteFinder(routeFinder); } InternalBus.Current = new RabbitMqBusAdapter(_rabbitBus); Global.PendingJobCount = _rabbitBus.GetMessageCount; Burrow.Global.DefaultConsumerBatchSize = ushort.Parse(ConfigurationManager.AppSettings["TaskConcurrencyLevel"] ?? "4"); Burrow.Global.PreFetchSize = uint.Parse(ConfigurationManager.AppSettings["PreFetchSize"] ?? ((Burrow.Global.DefaultConsumerBatchSize) * 2).ToString(CultureInfo.InvariantCulture)); return this; }
public async Task MainAsync() { var configClient = InternalConfigurationApiClientFactory.Create(GetConfiguration().GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var systemConfig = await configClient.GetConfigurationAsync(); // TODO : ideally queue name should be read from InternalConfigurationApi IMessageChannel messageChannel = new RabbitMqChannel(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer(), RabbitMqConsts.DiscordBotQueueName); IMessageBus messageBus = new RabbitMqBus(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer()); var svc = new DiscordService(systemConfig.DiscordBot.ApiKey, messageChannel, messageBus); messageChannel.Start(); await svc.ConnectAsync(); await Task.Delay(-1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMassTransit(cfg => { cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider)); }); services.AddMassTransitHostedService(); services.AddDbContext <OrderDbContext> (o => o.UseSqlServer(Configuration. GetConnectionString("OrderingDatabase"))); services.AddSingleton <IOrderDataAccess, OrderDataAccess>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ServiceLocator>(sp => { ServiceLocator locator = new ServiceLocator(); var b = RabbitHutch.CreateBus("host=192.168.1.105;username=test;password=test"); var bus = new RabbitMqBus(b); locator.Bus = bus; var messageBusEndPoint = "Sales_service"; var topicFilter = "Products.Common.Events"; IPAddress ip = IPAddress.Parse("192.168.1.105"); var eventStorePort = 1113; var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(ip, eventStorePort)); // var connectionString = "ConnectTo=tcp://admin:[email protected]:12900; Gossip Timeout = 500"; // var eventStoreConnection = EventStoreConnection.Create(connectionString); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); locator.OrderCommands = new OrderCommandHandlers(repository); locator.ProductView = new ProductView(); var eventMappings = new EventHandlerDiscovery() .Scan(new ProductEventsHandler(locator)) .Handlers; b.Subscribe <PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); return(locator); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //ConfigureHandlers(); services.AddSingleton <ProductCommandHandlers>(sp => { var bus = new RabbitMqBus(RabbitHutch.CreateBus("host=192.168.1.105;username=test;password=test")); //Should get this from a config setting instead of hardcoding it. var connectionString = "ConnectTo=tcp://admin:[email protected]:1113; Gossip Timeout = 500"; var eventStoreConnection = EventStoreConnection.Create(connectionString); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); return(new ProductCommandHandlers(repository)); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public async Task ListenerFactory_SubscribeExtension_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var listenerFactory = new RabbitMqListenerFactory(options, CommonUtils.CreateLogger <RabbitMqListenerFactory>()); var count = 0; await listenerFactory.Create() .Subscribe("test", (string m) => Task.FromResult(Interlocked.Increment(ref count)), InteractionType.PublishSubscribe) .Subscribe("test", (string m) => Task.FromResult(Interlocked.Increment(ref count)), InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", "1", InteractionType.PublishSubscribe); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count >= 2); count.ShouldBe(2); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.TryAddSingleton(KebabCaseEndpointNameFormatter.Instance); services.AddMassTransit(cfg => { cfg.AddRequestClient <IStartBooking>(); cfg.AddConsumer <StartBookingConsumer>(); cfg.AddConsumer <BookingCancelledConsumer>(); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider)); }); services.AddMassTransitHostedService(); services.AddDbContext <BookingDbContext>(a => a.UseSqlServer(Configuration.GetConnectionString("BookingDatabase"))); services.AddSingleton <IBookingDataAccess, BookingDataAccess>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMassTransit(cfg => { cfg.AddConsumer <OrderCardNumberValidateConsumer>(); cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) => { cfg.ReceiveEndpoint(BusConstants.OrderQueue, ep => { ep.ConfigureConsumer <OrderCardNumberValidateConsumer>(provider); }); })); }); services.AddMassTransitHostedService(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ServiceLocator>(sp => { ServiceLocator locator = new ServiceLocator(); var redis = ConnectionMultiplexer.Connect("192.168.1.105:6379,name=venom"); var brandView = new OrderView(new RedisReadModelRepository <OrderDto>(redis.GetDatabase())); locator.BrandView = brandView; var eventMappings = new EventHandlerDiscovery() .Scan(brandView) .Handlers; var messageBusEndPoint = "Sales_readmodel"; var topicFilter = "Sales.Common.Events"; var b = RabbitHutch.CreateBus("host=192.168.1.105;username=test;password=test"); b.Subscribe <PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); var bus = new RabbitMqBus(b); locator.Bus = bus; return(locator); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
private void ConfigureHandlers() { var b = RabbitHutch.CreateBus("host=localhost"); var messageBusEndPoint = "barista"; var topicFilter = "Cashier.Common.Events"; var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; //Should get this from a config setting instead of hardcoding it. var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 12900)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.OrderCommands = new BaristaOrderCommandHandlers(repository); var cashierEventHandler = new CashierOrderEventHandler(repository); ServiceLocator.CahierEventHandler = cashierEventHandler; var eventMappings = new EventHandlerDiscovery() .Scan(cashierEventHandler) .Handlers; b.Subscribe <PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); }
public async Task ListenerFactory_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var listenerFactory = new RabbitMqListenerFactory(options, CommonUtils.CreateLogger <RabbitMqListenerFactory>()); var rabbitMqListener = await listenerFactory.Create(); rabbitMqListener.ShouldNotBeNull(); var count = 0; rabbitMqListener.Subscribe("test", (string m) => Task.FromResult(count++), InteractionType.CompetingConsumers); await rabbitMqBus.Publish("test", "1", InteractionType.CompetingConsumers); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count > 0); count.ShouldBe(1); }
public static RabbitMqBus GetRabbitMqBus() { var rabbitMqConnectionOptions = new RabbitMqConnectionOptions() { HostName = "localhost", Password = "******", Username = "******", }; var anabasisAppContext = new AnabasisAppContext("appName", "appGroup", new Version(1, 0)); var loggerFactory = new LoggerFactory(); var defaultSerializer = new DefaultSerializer(); var rabbitMqBus = new RabbitMqBus( rabbitMqConnectionOptions, anabasisAppContext, defaultSerializer, loggerFactory ); return(rabbitMqBus); }
static void Main(string[] args) { Guid applicationId = Guid.NewGuid(); //one for an application Guid busId = Guid.NewGuid(); //Each instance of publishing bus var msg = Console.ReadLine(); while (msg != "Q") { var commandMessage = msg; var rmBus = new RabbitMqBus(); rmBus.SendCommand(new SendEmailCommand() { Message = commandMessage }); Console.WriteLine("published"); msg = Console.ReadLine(); } Console.ReadKey(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "GreenField.EmailService v1")); } RabbitMqBus bus = app.ApplicationServices.GetRequiredService <RabbitMqBus>(); bus.Subscribe <UserRegisteredMessage>("emailService"); //app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
private void ConfigureHandlers() { var b = RabbitHutch.CreateBus("host=localhost"); var messageBusEndPoint = "barista"; var topicFilter = "Cashier.Common.Events"; var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; //Should get this from a config setting instead of hardcoding it. var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 12900)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.OrderCommands = new BaristaOrderCommandHandlers(repository); var cashierEventHandler = new CashierOrderEventHandler(repository); ServiceLocator.CahierEventHandler = cashierEventHandler; var eventMappings = new EventHandlerDiscovery() .Scan(cashierEventHandler) .Handlers; b.Subscribe<PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); }
private void ConfigureHandlers() { var b = RabbitHutch.CreateBus("host=localhost"); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; var messageBusEndPoint = "cashier_service"; var topicFilter = "Admin.Common.Events"; var eventStorePort = 12900; var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, eventStorePort)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.OrderCommands = new OrderCommandHandlers(repository); ServiceLocator.ProductView = new ProductView(); var eventMappings = new EventHandlerDiscovery() .Scan(new AdminEventsHandler()) .Handlers; b.Subscribe <PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); }
private void ConfigureHandlers() { //Should get this from a config setting instead of hardcoding it. var redis = ConnectionMultiplexer.Connect("localhost"); var productView = new ProductView(new RedisReadModelRepository <ProductDto>(redis.GetDatabase())); ServiceLocator.ProductView = productView; IBaristaClient masterDataClient = new BaristaClient(); var eventMappings = new EventHandlerDiscovery() .Scan(productView) .Handlers; var subscriptionName = "journeydesigner_readmodel"; var topicFilter1 = "MasterData.Common.Events"; var topicFilter2 = "Barista.Common.Events"; var b = RabbitHutch.CreateBus("host=localhost"); b.Subscribe <PublishedMessage>(subscriptionName, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter1).WithTopic(topicFilter2)); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; }
private void ConfigureHandlers() { var b = RabbitHutch.CreateBus("host=localhost"); var bus = new RabbitMqBus(b); ServiceLocator.Bus = bus; var messageBusEndPoint = "cashier_service"; var topicFilter = "Admin.Common.Events"; var eventStorePort = 12900; var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, eventStorePort)); eventStoreConnection.ConnectAsync().Wait(); var repository = new EventStoreRepository(eventStoreConnection, bus); ServiceLocator.OrderCommands = new OrderCommandHandlers(repository); ServiceLocator.ProductView = new ProductView(); var eventMappings = new EventHandlerDiscovery() .Scan(new AdminEventsHandler()) .Handlers; b.Subscribe<PublishedMessage>(messageBusEndPoint, m => { Aggregate handler; var messageType = Type.GetType(m.MessageTypeName); var handlerFound = eventMappings.TryGetValue(messageType, out handler); if (handlerFound) { var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType); handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version); } }, q => q.WithTopic(topicFilter)); }