Exemplo n.º 1
0
 static async void Client()
 {
     var client = new ProducerClient {
         Log = XTrace.Log
     };
     await client.RegisterProducer();
 }
Exemplo n.º 2
0
        public void ConfigureDIService(IServiceCollection services)
        {
            //Permission handler
            services.AddScoped <IAuthorizationHandler, PermissionAuthorizationHandler>();

            services.AddTransient <IUserService, UserService>();
            services.AddTransient <ILandLordUserService, LandLordUserService>();
            services.AddTransient <IEstateManagerUserService, EstateManagerUserService>();

            services.AddSingleton <IProducerClient <BusMessage> >(service =>
            {
                var topics         = Configuration.GetSection("Kafka").GetValue <string>("Topics").ToString().Split(",");
                var env            = service.GetRequiredService <IHostingEnvironment>();
                var producerClient = new ProducerClient <BusMessage>(env, Configuration);
                return(producerClient);
            });

            services.AddSingleton <IConsumerClient <BusMessage> >(service =>
            {
                var topics         = Configuration.GetSection("Kafka").GetValue <string>("Topics").ToString().Split(",");
                var env            = service.GetRequiredService <IHostingEnvironment>();
                var consumerClient = new ConsumerClient <BusMessage>(env, Configuration);
                //consumerClient.Subscribe(topics.ToList());
                return(consumerClient);
            });

            services.AddTransient <Func <List <BusHandler> > >(cont =>
                                                               () =>
            {
                List <BusHandler> handlers = new List <BusHandler>();
                var scope   = cont.GetRequiredService <IServiceProvider>().CreateScope();
                var handler = scope.ServiceProvider.GetRequiredService <AuthHandler>();

                handlers.Add((message) => {
                    if (message.BusMessageType == (int)BusMessageTypes.NEW_USER)
                    {
                        handler.HandleCreateMarketerUser(message);
                        handler.HandleCreateTruckOwnerUser(message);
                    }
                });

                return(handlers);
            });

            services.AddMediatR(typeof(Startup));
            //services.AddTransient(p => BuildMediator());
            services.AddScoped <ImanageExceptionAttribute>();
            services.AddSingleton <BoundedMessageChannel <BusMessage> >();
            services.AddHostedService <EvenHubProcessorService>();
            services.AddHostedService <EventHubReaderService>();
            services.AddScoped <ImanageExceptionAttribute>();
            services.AddScoped <IDbContext, ImanageAuthDbContext>();
            services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
            services.AddScoped(typeof(IRepository <>), typeof(EntityRepository <>));
            services.AddTransient <AuthHandler>();
        }
Exemplo n.º 3
0
        public static void Run()
        {
            var server = new ProducerClient();
            var client = new ConsumerClient();

            // Kick off server.
            var serverTask = Task.Run(async() =>
            {
                await server.RunAsync();
            });

            // Kick off client.
            var clientTask = Task.Run(async() =>
            {
                // Similarly, client to server communication could happen on a
                // separate command channel passed into the server.
                await client.RunAsync(server.EventsChannel);
            });

            Task.WaitAll(serverTask, clientTask);
            Console.WriteLine("Shutting down runner");
        }