Beispiel #1
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddJsonFile("appsettings.Development.json", true)
                                .Build();

            //IServiceCollection services = new ServiceCollection();
            //services.AddDbContext<MyDbContext>(options =>
            //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            //services.AddScoped<IMyService, MyService>();
            //IServiceProvider provider = services.BuildServiceProvider();

            //IMyService myService = provider.GetService<IMyService>();

            var httpClient = new HttpClient();

            var notificationsApiUrl        = configuration["NotificationsApiUrl"];
            var serviceBusConnectionString = configuration["ServiceBusConnectionString"];

            var ordersNotificationListener = new NotificationListener(httpClient, serviceBusConnectionString, "orders", "products-api", notificationsApiUrl);

            ordersNotificationListener.StartListening();

            Console.WriteLine("listening for notifications ... press any key to quit");

            Console.ReadKey();

            await ordersNotificationListener.StopListening();
        }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddJsonFile("appsettings.Development.json", true)
                                .Build();

            var httpClient = new HttpClient();

            var notificationsApiUrl        = configuration["NotificationsApiUrl"];
            var serviceBusConnectionString = configuration["ServiceBusConnectionString"];

            var productsNotificationListener  = new NotificationListener(httpClient, serviceBusConnectionString, "products", "web-api", notificationsApiUrl);
            var customersNotificationListener = new NotificationListener(httpClient, serviceBusConnectionString, "customers", "web-api", notificationsApiUrl);
            var ordersNotificationListener    = new NotificationListener(httpClient, serviceBusConnectionString, "orders", "web-api", notificationsApiUrl);

            productsNotificationListener.StartListening();
            customersNotificationListener.StartListening();
            ordersNotificationListener.StartListening();

            Console.WriteLine("listening for notifications ... press any key to quit");

            Console.ReadKey();

            await productsNotificationListener.StopListening();

            await customersNotificationListener.StopListening();

            await ordersNotificationListener.StopListening();
        }