Beispiel #1
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();

            //TODO: add your ASB qualified name here
            var asbClientProvider = new ServiceBusVisualStudioCredentialClientProvider("fim-development-bus.servicebus.windows.net");

            serviceCollection.AddBrighter()
            .UseInMemoryOutbox()
            .UseExternalBus(new AzureServiceBusProducerRegistryFactory(
                                asbClientProvider,
                                new AzureServiceBusPublication[]
            {
                new AzureServiceBusPublication()
                {
                    Topic = new RoutingKey("greeting.event")
                },
                new AzureServiceBusPublication()
                {
                    Topic = new RoutingKey("greeting.addGreetingCommand")
                },
                new AzureServiceBusPublication()
                {
                    Topic = new RoutingKey("greeting.Asyncevent")
                }
            }
                                ).Create())
            .AutoFromAssemblies();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var commandProcessor = serviceProvider.GetService <IAmACommandProcessor>();

            bool run = true;

            while (run)
            {
                Console.WriteLine("Sending....");
                var distroGreeting = new GreetingEvent("Paul - Distributed");
                commandProcessor.DepositPost(distroGreeting);

                commandProcessor.Post(new GreetingEvent("Paul"));
                commandProcessor.Post(new GreetingAsyncEvent("Paul - Async"));

                commandProcessor.ClearOutbox(distroGreeting.Id);

                Console.WriteLine("Press q to Quit or any other key to continue");

                var keyPress = Console.ReadKey();
                if (keyPress.KeyChar == 'q')
                {
                    run = false;
                }
            }
        }
Beispiel #2
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();
        }