Exemple #1
0
        private static void initializeEventDispatcher()
        {
            string sqlConnectionString = "server=db;userid=jomaya;password=jomaya;database=jomaya-frontend;";

            var optionsBuilder = new DbContextOptionsBuilder <FrontEndContext>();

            optionsBuilder.UseMySQL(sqlConnectionString);
            _context = new FrontEndContext(optionsBuilder.Options);

            _klantRepo      = new KlantRepository(_context);
            _autoRepo       = new AutoRepository(_context);
            _onderhoudsRepo = new OnderhoudRepository(_context);

            var config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.frontend.auto.dispatcher"
            };

            var publisher = new EventPublisher(config);

            _autoDispatcher = new AutoDispatcher(config, _autoRepo, _onderhoudsRepo);

            config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.frontend.klant.dispatcher"
            };
            _klantDispatcher = new KlantDispatcher(config, _klantRepo);
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddSwaggerGen();
            services.AddSingleton <IEventPublisher, EventPublisher>(config =>
            {
                var _config = new EventBusConfig()
                {
                    Host      = Configuration.GetConnectionString("RabbitMQ"),
                    Port      = 5672,
                    QueueName = "jomaya.integratieservice",
                };


                return(new EventPublisher(_config));
            });
            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "A Monument service",
                    Description    = "Restauration of monuments",
                    TermsOfService = "None"
                });
            });
            services.AddMvc();
        }
Exemple #3
0
        public static EventBusConfig GetEventBusConfigs(this IConfiguration configuration)
        {
            var eventBusClientName = new EventBusConfig();

            configuration?.GetSection("EventBusConfigs")?.Bind(eventBusClientName);
            return(eventBusClientName);
        }
        public static IServiceCollection RegisterEasyNetQ(this IServiceCollection services,
                                                          EventBusConfig config)
        {
            config.PrefetchCount = Math.Min(10, Math.Max(1, config.PrefetchCount));
            var connString =
                $"host={config.HostName.Trim('"')};virtualHost={config.VirtualHost.Trim('"')};username={config.UserName.Trim('"')};password={config.Password.Trim('"')};prefetchcount={config.PrefetchCount};timeout=20";

            services.AddSingleton(
                RabbitHutch.CreateBus(connString));

            services.AddSingleton <IEventBus, EventBusEasyNetQ>(p =>
                                                                new EventBusEasyNetQ(p.GetService <IBus>(), p, config.Prefix, p.GetService <ILoggerFactory>()));

            services.AddTransient <ServiceActionInvokeTrackAttribute>();

            //if (config.AopInject)
            //    services.AddDynamicProxy(configure =>
            //    {
            //        configure.Interceptors.AddServiced<ServiceActionInvokeTrackAttribute>(method =>
            //            method.DeclaringType?.Namespace != null &&
            //            (method.DeclaringType.Name.EndsWith("Service") ||
            //             method.DeclaringType.Name.EndsWith("ServiceBase"))
            //            && method.DeclaringType.GetInterface(typeof(IService).FullName) != null
            //            && method.DeclaringType.GetCustomAttribute<AopIgnoreAttribute>() == null
            //            && !method.Name.Contains("Context"));

            //        //configure.Interceptors.AddTyped<ServiceActionInvokeTrackAttribute>(method =>
            //        //    method.DeclaringType.Name.EndsWith("Service")
            //        //    && method.DeclaringType.GetInterface(typeof(IService).FullName) != null
            //        //    && !method.DeclaringType.IsSubclassOf(typeof(HttpProxyServiceBase))
            //        //    && !method.Name.Contains("Context")
            //        //    );
            //    });
            return(services);
        }
Exemple #5
0
        private static void ConfigureServices(IServiceCollection services)
        {
            var eventBusConfig = new EventBusConfig();

            Configuration.GetSection("EventBusConfig").Bind(eventBusConfig);
            var credentials = new BasicAWSCredentials(eventBusConfig.AccessKey, eventBusConfig.SecretKey);

            services.Configure <Config>(options => Configuration.GetSection("Config").Bind(options));
            services.Configure <EventBusConfig>(options => Configuration.GetSection("EventBusConfig").Bind(options));
            services.AddHttpClient <IExternalSimCardsProviderService, ExternalSimCardsProviderService>();

            services.AddSingleton <AWSCredentials>(credentials);
            services.AddSingleton <ISimCardOrdersDataStore, SimCardOrdersDataStore>();
            services.AddSingleton <ISqsService, SqsService>();
            services.AddSingleton <ISnsService, SnsService>();
            services.AddSingleton <IQueueNamingStrategy, DefaultQueueNamingStrategy>();
            services.AddSingleton <IMessageBus, MessageBus>();
            services.AddSingleton <IMessageBusListenerBuilder, MessageBusListenerBuilder>();
            services.AddSingleton <IMessagePublisher, MessagePublisher>();
            services.AddSingleton <ICompletedOrderChecker, CompletedOrderChecker>();
            services.AddSingleton <IMonitoring, Monitoring>();

            services.AddHostedService <MetricsServerHost>();
            services.AddHostedService <EventListenerHostedService>();
            services.AddHostedService <CompletedOrderPollingHostedService>();
        }
        public static IServiceProvider RegisterEasyNetQProvider(this IServiceCollection services,
                                                                EventBusConfig configuration)
        {
            //注入权限监控(需要调用EventBus查询权限)
            //services.AddScoped<IUserPermissionService, EventService>();

            services.RegisterEasyNetQ(configuration);

            return(services.BuildAspectInjectorProvider());
        }
Exemple #7
0
        public void Init()
        {
            _options = CreateNewContextOptions();

            _config = new EventBusConfig()
            {
                Host      = "localhost",
                Port      = 5673,
                QueueName = "DispatcherTest"
            };
        }
Exemple #8
0
        private static void InitializeDispatcher()
        {
            var config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.rdwservice.queue"
            };
            EventPublisher publisher = new EventPublisher(config);
            RDWService     service   = new RDWService(publisher);

            _dispatcher = new RDWDispatcher(config, service);
        }
Exemple #9
0
        public void DispatcherGetsEventAndConnectToRDWAndGetAResponse()
        {
            var _configTo = new EventBusConfig()
            {
                ExchangeName = "jomaya.eventbus",
                Host         = Configuration.GetConnectionString("RabbitMQ") ?? "localhost",
                Port         = 5673,
                QueueName    = "DispatcherGetsEventAndConnectToRDWAndGetAResponseTo"
            };

            var _configFrom = new EventBusConfig()
            {
                ExchangeName = "jomaya.eventbus",
                Host         = Configuration.GetConnectionString("RabbitMQ") ?? "localhost",
                Port         = 5673,
                QueueName    = "DispatcherGetsEventAndConnectToRDWAndGetAResponseFrom"
            };
            var filePath = "integratie_test.txt";

            using (var eventSender = new EventPublisher(_configFrom))
                using (var testStarter = new EventPublisher(_configTo))
                    using (var rdwDispatcher = new RDWDispatcher(_configTo, new RDWService(eventSender)))
                        using (var testReceiver = new TestDispatcher(_configFrom))
                        {
                            rdwDispatcher.LogFilePath = filePath;
                            AutoKlaargemeldEvent aae = new AutoKlaargemeldEvent()
                            {
                                AutoId          = 1,
                                Kenteken        = "AB-BA-33",
                                GUID            = Guid.NewGuid().ToString(),
                                RoutingKey      = "",
                                TimeStamp       = DateTime.UtcNow,
                                KilometerStand  = 1234,
                                VoertuigType    = (int)Common.VoertuigTypes.Personenauto,
                                IsApk           = true,
                                KlantId         = 1,
                                Werkzaamheden   = "test",
                                OnderhoudId     = 1,
                                OnderhoudsDatum = DateTime.UtcNow
                            };
                            rdwDispatcher.Uri = new Uri("http://localhost:4003/");

                            testStarter.Publish(aae);

                            Thread.Sleep(2000);

                            Assert.AreEqual(2, testReceiver.ReceivedEventCount);
                            Assert.AreEqual("Jomaya.Common.Events.APKKeuringsregistratieEvent", testReceiver.ReceivedEvent.BasicProperties.Type);
                        }
        }
Exemple #10
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddSwaggerGen();

            var sqlConnectionString = Configuration.GetConnectionString("DataAccessMySqlProvider")
                                      ?? "server=localhost;port=5001;userid=jomaya;password=jomaya;database=jomaya-autoservice";

            services.AddDbContext <AutosBackendContext>(options =>
                                                        options.UseMySQL(sqlConnectionString));

            //, b => b.MigrationsAssembly("AspNet5MultipleProject")

            //services.AddDbContext<AutosBackendContext>(options => options.UseSqlServer(@"Server=db;Database=Jomaya;UserID=sa,Password=admin"));

            services.AddScoped <IRepository <Auto, long>, AutoRepository>();
            services.AddScoped <IRepository <Onderhoudsopdracht, long>, OnderhoudRepository>();

            services.AddSingleton <IEventPublisher, EventPublisher>(config =>
            {
                var _config = new EventBusConfig()
                {
                    Host      = Configuration.GetConnectionString("RabbitMQ") ?? "localhost",
                    Port      = 5672,
                    QueueName = "jomaya.autoservice",
                };


                return(new EventPublisher(_config));
            });

            services.AddScoped <Services.AutoService, Services.AutoService>();
            services.AddScoped <AutoDispatcher, AutoDispatcher>();

            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "Jomaya AutoService",
                    Description    = "De service die de auto's beheert.",
                    TermsOfService = "None"
                });
            });
            services.AddMvc();
        }
Exemple #11
0
        public void DispatcherLogsRDWRequests()
        {
            var _config = new EventBusConfig()
            {
                Host      = "localhost",
                Port      = 5673,
                QueueName = "DispatcherLogsRDWRequests"
            };

            var filePath = "test.txt";

            using (var eventSender = new EventPublisher(_config))
                using (var rdwDispatcher = new RDWDispatcher(_config, new RDWService(eventSender)))
                {
                    rdwDispatcher.LogFilePath = filePath;
                    rdwDispatcher.Uri         = new Uri("http://localhost:4003/");
                    var myEvent = new AutoKlaargemeldEvent()
                    {
                        AutoId         = 1,
                        GUID           = "TESTGUID",
                        Kenteken       = "TE-ST-55",
                        IsApk          = true,
                        KilometerStand = 123456,
                        RoutingKey     = "Niks",
                        TimeStamp      = DateTime.Now,
                        VoertuigType   = (int)Common.VoertuigTypes.Personenauto,
                        KlantId        = 1,
                    };


                    eventSender.Publish(myEvent);

                    Thread.Sleep(5000);

                    var logPath = Path.GetTempFileName();
                    var result  = File.ReadAllText(filePath);

                    var expectedFirstpart = $"TimeStamp: {myEvent.TimeStamp} Guid: TESTGUID AutoID: 1 Eigenaar: ";
                    var expectedLastPart  = $" Kenteken: TE-ST-55 KilometerStand: 123456 VoertuigType: 0 ";

                    Assert.IsTrue(result.Contains(expectedFirstpart));
                    Assert.IsTrue(result.Contains(expectedLastPart));
                    File.Delete(filePath);
                }
        }
Exemple #12
0
        private static void initializeEventDispatcher()
        {
            string sqlConnectionString = "server=db;userid=jomaya;password=jomaya;database=jomaya-foutlogging;";

            var optionsBuilder = new DbContextOptionsBuilder <FoutLoggingContext>();

            optionsBuilder.UseMySQL(sqlConnectionString);
            _context = new FoutLoggingContext(optionsBuilder.Options);
            _repo    = new CustomExceptionRepository(_context);

            var config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.foutlogging.queue"
            };

            var publisher = new EventPublisher(config);

            _dispatcher = new FoutLoggingDispatcher(config, _repo);
        }
Exemple #13
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            string sqlConnectionString = "server=db;userid=jomaya;password=jomaya;database=jomaya-autoservice;";

            _publisher = new EventPublisher(

                new EventBusConfig()
            {
                Host = "rabbitmq",
                Port = 5672,
            }
                );

            var optionsBuilder = new DbContextOptionsBuilder <AutosBackendContext>();

            optionsBuilder.UseMySQL(sqlConnectionString);
            _context = new AutosBackendContext(optionsBuilder.Options);

            _autoRepo      = new AutoRepository(_context);
            _onderhoudRepo = new OnderhoudRepository(_context);
            var config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.autoservice.auto.dispatcher"
            };

            var publisher = new EventPublisher(config);

            _autoDispatcher = new AutoDispatcher(config, new Services.AutoService(_autoRepo, _onderhoudRepo, _publisher));

            host.Run();
        }
        public static void PublishException(Exception e, bool inDockerContainer = true)
        {
            string eventBusHost;
            int    eventBusPort;

            if (inDockerContainer)
            {
                eventBusHost = "rabbitmq";
                eventBusPort = 5672;
            }
            else
            {
                eventBusHost = "localhost";
                eventBusPort = 5673;
            }

            var config = new EventBusConfig()
            {
                Host         = eventBusHost,
                Port         = eventBusPort,
                QueueName    = "jomaya.exception.publisher",
                ExchangeName = "my-bus"
            };

            var myEvent = new ExceptionThrownEvent()
            {
                ExceptionType = e.GetType(),
                GUID          = Guid.NewGuid().ToString(),
                Message       = e.Message,
                RoutingKey    = "jomaya.exception.exceptionthrownevent",
                StackTrace    = e.StackTrace,
                TimeStamp     = DateTime.Now
            };

            using (var publisher = new EventPublisher(config))
            {
                publisher.Publish(myEvent);
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostEnvironment env, ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            app.UseHealthChecks("/health");
            app.UseMetricServer();
            app.UseHttpMetrics();
            app.UseSerilogRequestLogging();
            app.UseMvc();

            var eventBusConfig = new EventBusConfig();

            Configuration.GetSection("EventBusConfig").Bind(eventBusConfig);

            logger.LogDebug($"SnsServiceUrl: {eventBusConfig.SnsServiceUrl}");
            logger.LogDebug($"SqsServiceUrl: {eventBusConfig.SqsServiceUrl}");
        }
Exemple #16
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddSwaggerGen();

            var sqlConnectionString = Configuration.GetConnectionString("DataAccessMySqlProvider")
                                      ?? "server=localhost;port=4001;userid=jomaya;password=jomaya;database=jomaya-klantservice;";

            services.AddDbContext <KlantContext>(options => options.UseMySQL(sqlConnectionString));

            //b => b.MigrationsAssembly("AspNet5MultipleProject")

            services.AddScoped <IRepository <Klant, long>, KlantRepository>();
            services.AddScoped <IEventPublisher, EventPublisher>(config =>
            {
                var _config = new EventBusConfig()
                {
                    Host = Configuration.GetConnectionString("RabbitMQ") ?? "localhost",
                    Port = 5672,
                };

                return(new EventPublisher(_config));
            });
            services.AddScoped <KlantService>();


            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "A Monument service",
                    Description    = "Restauration of monuments",
                    TermsOfService = "None"
                });
            });
            services.AddMvc();
        }
Exemple #17
0
        private (DbType, string) GetDbConnString(EventBusConfig eventBusConfig)
        {
            try
            {
                var dbConfig = Singleton <AppSettings> .Instance["DbConfig"];

                if (dbConfig != null)
                {
                    foreach (var connectionConfig in dbConfig.DataConnectionConfigs)
                    {
                        if (connectionConfig.Name == eventBusConfig.DbConnectionString)
                        {
                            return((DbType)(int)connectionConfig.UseDataType,
                                   connectionConfig.MasterDataConnectionString);
                        }
                    }
                }
            }
            finally
            {
            }

            return(eventBusConfig.DbType, eventBusConfig.DbConnectionString);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options => options.EnableEndpointRouting = false);

            var eventBusConfig = new EventBusConfig();

            Configuration.GetSection("EventBusConfig").Bind(eventBusConfig);
            var credentials = new BasicAWSCredentials(eventBusConfig.AccessKey, eventBusConfig.SecretKey);

            services.Configure <Config>(options => Configuration.GetSection("Config").Bind(options));
            services.Configure <EventBusConfig>(options => Configuration.GetSection("EventBusConfig").Bind(options));

            // Shared
            var config = new Config();

            Configuration.GetSection("Config").Bind(config);

            services.AddDbContext <MobilesContext>(options =>
                                                   options.UseSqlServer(config.ConnectionString));
            services.AddScoped <IRepository <Mobile>, MobileRepository>();
            services.AddScoped <ICustomerRepository, CustomerRepository>();

            // Utilities
            services.AddSingleton <IDateTimeCreator, DateTimeCreator>();
            services.AddSingleton <IEnumConverter, EnumConverter>();
            services.AddSingleton <IMessageDeserializer, MessageDeserializer>();
            services.AddSingleton <AWSCredentials>(credentials);

            // API
            services.AddScoped <IGuidCreator, GuidCreator>();
            services.AddScoped <IMessagePublisher, MessagePublisher>();
            services.AddScoped <IGetNewProvisionsQuery, GetNewProvisionsQuery>();
            services.AddScoped <IGetProcessingProvisionMobilesQuery, GetProcessingProvisionMobilesQuery>();
            services.AddScoped <IGetNewActivatesQuery, GetNewActivatesQuery>();
            services.AddScoped <IGetNewCeasesQuery, GetNewCeasesQuery>();
            services.AddScoped <IGetMobileByOrderIdQuery, GetMobileByOrderIdQuery>();
            services.AddScoped <IGetMobilesByCustomerIdQuery, GetMobilesByCustomerIdQuery>();
            services.AddScoped <IGetNextMobileIdQuery, GetNextMobileIdQuery>();
            services.AddScoped <ICustomersService, CustomersService>();
            services.AddScoped <IMobilesService, MobilesService>();

            // EventBus
            services.AddSingleton <ISnsService, SnsService>();
            services.AddSingleton <ISqsService, SqsService>();
            services.AddSingleton <IMessageBus, MessageBus>();
            services.AddSingleton <IMessageBusListenerBuilder, MessageBusListenerBuilder>();
            services.AddSingleton <IQueueNamingStrategy, DefaultQueueNamingStrategy>();

            services.AddSingleton <IMonitoring>(new Monitoring());

            services.AddScoped <IMobileEventsChecker, MobileProvisionRequestedEventChecker>();
            services.AddScoped <IMobileEventsChecker, ProcessingProvisionEventChecker>();
            services.AddScoped <IMobileEventsChecker, ActivateRequestedEventChecker>();
            services.AddScoped <IMobileEventsChecker, CeaseRequestedEventChecker>();

            // HostedService
            services.AddHostedService <EventsService>();
            services.AddHostedService <EventPublisherService>();

            services.AddHealthChecks()
            .ForwardToPrometheus();
        }
Exemple #19
0
 public AutoDispatcher(EventBusConfig config, Services.AutoService autoService) : base(config)
 {
     _autoService = autoService;
 }
Exemple #20
0
 public PlayerDispatcher(EventBusConfig config)
     : base(config)
 {
 }
Exemple #21
0
 public AutoDispatcher(EventBusConfig config, IRepository <Auto, long> autoRepo, IRepository <Onderhoudsopdracht, long> onderhoudRepo)
     : base(config)
 {
     _autoRepo      = autoRepo;
     _onderhoudRepo = onderhoudRepo;
 }
Exemple #22
0
 public RDWDispatcher(EventBusConfig config, RDWService service) : base(config)
 {
     _service = service;
 }
Exemple #23
0
 public BlackJackDispatcher(EventBusConfig config) : base(config)
 {
 }
 public FoutLoggingDispatcher(EventBusConfig config, CustomExceptionRepository repo) : base(config)
 {
     _repo = repo;
 }
Exemple #25
0
 public KlantDispatcher(EventBusConfig config, IRepository <Entities.Klant, long> autoRepo)
     : base(config)
 {
     _autoRepo = autoRepo;
 }
Exemple #26
0
 public TestDispatcher(EventBusConfig config) : base(config)
 {
 }
 public RoomDispatcher(EventBusConfig config) : base(config)
 {
 }
Exemple #28
0
 public KlantDispatcher(EventBusConfig config) : base(config)
 {
 }