Esempio n. 1
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();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();

            var asbConnection = new AzureServiceBusConfiguration("Endpoint=sb://.servicebus.windows.net/;Authentication=Managed Identity", true);

            var producer = AzureServiceBusMessageProducerFactory.Get(asbConnection);

            serviceCollection.AddBrighter(options =>
            {
                var outBox = new InMemoryOutbox();
                options.BrighterMessaging = new BrighterMessaging(outBox, producer: producer);
            }).AutoFromAssemblies();

            var serviceProvider = serviceCollection.BuildServiceProvider();

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

            bool run = true;

            while (run)
            {
                Console.WriteLine("Sending....");

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

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

                var keyPress = Console.ReadKey();
                if (keyPress.KeyChar == 'q')
                {
                    run = false;
                }
            }
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //string dbConnString = "server=(localdb)\\mssqllocaldb;database=BrighterTests;trusted_connection=yes;MultipleActiveResultSets=True";
            string dbConnString = "server=(localdb)\\mssqllocaldb;database=BrighterTests;trusted_connection=yes";

            //EF
            services.AddDbContext <GreetingsDataContext>(o =>
            {
                o.UseSqlServer(dbConnString);
            });

            //Brighter
            string asbConnectionString = "Endpoint=sb://.servicebus.windows.net/;Authentication=Managed Identity";

            var asbConnection = new AzureServiceBusConfiguration(asbConnectionString, true);
            var producer      = AzureServiceBusMessageProducerFactory.Get(asbConnection);

            var outboxConfig = new MsSqlConfiguration(dbConnString, "BrighterOutbox");

            services
            .AddBrighter(opt =>
            {
                opt.PolicyRegistry           = new DefaultPolicy();
                opt.CommandProcessorLifetime = ServiceLifetime.Scoped;
            })
            .UseExternalBus(producer)
            //.UseMsSqlOutbox(outboxConfig, typeof(MsSqlOutboxSqlAuthConnectionFactory))
            .UseMsSqlOutbox(outboxConfig, typeof(MsSqlEntityFrameworkCoreConnectionProvider <GreetingsDataContext>), ServiceLifetime.Scoped)
            .MapperRegistry(r =>
            {
                r.Add(typeof(GreetingEvent), typeof(GreetingEventMessageMapper));
                r.Add(typeof(GreetingAsyncEvent), typeof(GreetingEventAsyncMessageMapper));
            });


            services.AddControllersWithViews();
        }