예제 #1
0
        public async static Task Main(string[] args)
        {
            var host = new HostBuilder()
                       .ConfigureServices((hostContext, services) =>

            {
                services.AddLogging();

                services.AddScoped <InstanceCount>();
                services.AddTransient(typeof(MonitoringAsyncHandler <>));
                services.AddTransient(typeof(MonitoringAttribute));

                var subscriptions = new Subscription[]
                {
                    new AzureServiceBusSubscription <GreetingAsyncEvent>(
                        new SubscriptionName(GreetingEventAsyncMessageMapper.Topic),
                        new ChannelName("paramore.example.greeting"),
                        new RoutingKey(GreetingEventAsyncMessageMapper.Topic),
                        timeoutInMilliseconds: 400,
                        makeChannels: OnMissingChannel.Create,
                        requeueCount: 3,
                        isAsync: true),

                    new AzureServiceBusSubscription <GreetingEvent>(
                        new SubscriptionName(GreetingEventMessageMapper.Topic),
                        new ChannelName("paramore.example.greeting"),
                        new RoutingKey(GreetingEventMessageMapper.Topic),
                        timeoutInMilliseconds: 400,
                        makeChannels: OnMissingChannel.Create,
                        requeueCount: 3,
                        isAsync: false)
                };

                //TODO: add your ASB qualified name here
                var clientProvider = new ServiceBusVisualStudioCredentialClientProvider(".servicebus.windows.net");

                var asbConsumerFactory = new AzureServiceBusConsumerFactory(clientProvider, false);
                services.AddServiceActivator(options =>
                {
                    options.Subscriptions  = subscriptions;
                    options.ChannelFactory = new AzureServiceBusChannelFactory(asbConsumerFactory);
                    options.UseScoped      = false;
                })
                .UseInMemoryOutbox()
                .AutoFromAssemblies();

                services.AddHostedService <ServiceActivatorHostedService>();
            })
                       .ConfigureLogging((hostingContext, logging) => {
                logging.SetMinimumLevel(LogLevel.Information);
                logging.AddConsole();
            })
                       .UseConsoleLifetime()
                       .Build();

            await host.RunAsync();
        }
예제 #2
0
        public async static Task Main(string[] args)
        {
            var host = new HostBuilder()
                       .ConfigureServices((hostContext, services) =>

            {
                services.AddLogging();

                var subscriptions = new Subscription[]
                {
                    new AzureServiceBusSubscription <GreetingAsyncEvent>(
                        typeof(GreetingAsyncEvent),
                        new SubscriptionName(GreetingEventAsyncMessageMapper.Topic),
                        new ChannelName("paramore.example.greeting"),
                        new RoutingKey(GreetingEventAsyncMessageMapper.Topic),
                        timeoutInMilliseconds: 400,
                        makeChannels: OnMissingChannel.Validate,
                        requeueCount: 3,
                        isAsync: true),
                    new AzureServiceBusSubscription <GreetingEvent>(
                        typeof(GreetingEvent),
                        new SubscriptionName(GreetingEventMessageMapper.Topic),
                        new ChannelName("paramore.example.greeting"),
                        new RoutingKey(GreetingEventMessageMapper.Topic),
                        timeoutInMilliseconds: 400,
                        makeChannels: OnMissingChannel.Validate,
                        requeueCount: 3,
                        isAsync: false)
                };

                //create the gateway
                var asbConfig = new AzureServiceBusConfiguration("Endpoint=sb://fim-development-bus.servicebus.windows.net/;Authentication=Managed Identity", true);

                var asbConsumerFactory = new AzureServiceBusConsumerFactory(asbConfig);
                services.AddServiceActivator(options =>
                {
                    options.Subscriptions  = subscriptions;
                    options.ChannelFactory = new AzureServiceBusChannelFactory(asbConsumerFactory);
                }).UseInMemoryOutbox()
                .UseExternalBus(AzureServiceBusMessageProducerFactory.Get(asbConfig))
                .AutoFromAssemblies();


                services.AddHostedService <ServiceActivatorHostedService>();
            })
                       .ConfigureLogging((hostingContext, logging) => {
                logging.SetMinimumLevel(LogLevel.Information);
                logging.AddConsole();
            })
                       .UseConsoleLifetime()
                       .Build();

            await host.RunAsync();
        }