Example #1
0
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider)
 {
     configurator.Connect(endpoints => endpoints
                          .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-events")
     {
         Configuration = new KafkaProducerConfig
         {
             BootstrapServers = "PLAINTEXT://localhost:9092",
             MessageTimeoutMs = 1000
         }
     })
                          .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-events-two")
     {
         Configuration = new KafkaProducerConfig
         {
             BootstrapServers = "PLAINTEXT://localhost:9092",
             MessageTimeoutMs = 1000
         }
     })
                          .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-failure")
     {
         Configuration = new KafkaProducerConfig
         {
             BootstrapServers = "PLAINTEXT://somwhere:1000",
             MessageTimeoutMs = 1000
         }
     }));
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, BusConfigurator busConfigurator)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //Ensure ITracer is initalized
            app.ApplicationServices.GetRequiredService <ITracer>();

            var broker = busConfigurator.Connect(endpoitns =>
                                                 endpoitns
                                                 .AddInbound(new KafkaConsumerEndpoint("teste"))
                                                 .AddOutbound <WeatherForecast>(new KafkaProducerEndpoint("teste")));

            appLifetime.ApplicationStopping.Register(() => broker.Disconnect());
        }
Example #3
0
        public static IApplicationBuilder SilverbackConfigure(this IApplicationBuilder app, BusConfigurator busConfigurator, IConfiguration configuration)
        {
            var uri = configuration.GetSection("KafkaConfiguration:Uri").Value;
            var maxFailedAttempts     = 3;
            var ConfigurationConsumer = new KafkaConsumerConfig
            {
                BootstrapServers = uri,
                GroupId          = "Geo"
            };
            var ConfigurationProducer = new KafkaProducerConfig
            {
                BootstrapServers = uri
            };

            busConfigurator.Connect(endpoints => endpoints
                                    .AddInbound(
                                        new KafkaConsumerEndpoint("create-geolocalization")
            {
                Configuration = ConfigurationConsumer
            }, policy => policy.Chain(
                                            policy.Move(new KafkaProducerEndpoint("retry_5M_topic")
            {
                Configuration = new KafkaProducerConfig {
                    BootstrapServers = configuration["Kafka:Uri"]
                }
            })
                                            .MaxFailedAttempts(maxFailedAttempts),
                                            policy.Move(new KafkaProducerEndpoint("retry_30M_topic")
            {
                Configuration = new KafkaProducerConfig {
                    BootstrapServers = configuration["Kafka:Uri"]
                }
            })
                                            .MaxFailedAttempts(maxFailedAttempts),
                                            policy.Move(new KafkaProducerEndpoint("retry_60M_topic")
            {
                Configuration = new KafkaProducerConfig {
                    BootstrapServers = configuration["Kafka:Uri"]
                }
            })
                                            .MaxFailedAttempts(maxFailedAttempts),
                                            policy.Move(new KafkaProducerEndpoint("failed_topic")
            {
                Configuration = new KafkaProducerConfig {
                    BootstrapServers = configuration["Kafka:Uri"]
                }
            })
                                            .MaxFailedAttempts(maxFailedAttempts)))
                                    .AddOutbound <GeocodificadoEvent>(
                                        new KafkaProducerEndpoint("geocodification")
            {
                Configuration = ConfigurationProducer
            }));


            return(app);
        }
Example #4
0
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-error-events")
 {
     Configuration = new KafkaProducerConfig
     {
         BootstrapServers = "PLAINTEXT://localhost:9092"
     }
 }));
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-events")
 {
     Configuration = new KafkaProducerConfig
     {
         BootstrapServers = "PLAINTEXT://kafka:9092",
         ClientId         = GetType().FullName
     }
 }));
        protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider)
        {
            configurator.Connect(endpoints => endpoints
                                 .AddOutbound <IIntegrationEvent>(new KafkaProducerEndpoint("silverback-examples-events")
            {
                Configuration = new KafkaProducerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092"
                }
            }));

            _cancellationTokenSource = new CancellationTokenSource();

            Console.WriteLine("Starting OutboundWorker background process (press ESC to stop)...");

            var service = serviceProvider.GetRequiredService <IHostedService>();

            service.StartAsync(CancellationToken.None);
            _cancellationTokenSource.Token.Register(() => service.StopAsync(CancellationToken.None));
        }
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .AddOutbound <IIntegrationEvent>(CreateEndpoint("silverback-examples-custom-serializer")));
Example #8
0
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .ReadConfig(Configuration, serviceProvider));
Example #9
0
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .AddOutbound <IIntegrationEvent>(CreateEndpoint()));
Example #10
0
        protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider)
        {
            Configuration.SetupSerilog();

            var broker = configurator
                         .Connect(endpoints => endpoints
                                  .AddInbound(CreateConsumerEndpoint("silverback-examples-events", "silverback-examples-events-chunked", "silverback-examples-events-sp"))
                                  .AddInbound(CreateConsumerEndpoint("silverback-examples-batch"),
                                              settings: new InboundConnectorSettings
            {
                Batch = new Messaging.Batch.BatchSettings
                {
                    Size        = 5,
                    MaxWaitTime = TimeSpan.FromSeconds(5)
                },
                Consumers = 2
            })
                                  .AddInbound(CreateConsumerEndpoint("silverback-examples-error-events"), policy => policy
                                              .Chain(
                                                  policy
                                                  .Retry(TimeSpan.FromMilliseconds(500))
                                                  .MaxFailedAttempts(2),
                                                  policy
                                                  .Move(new KafkaProducerEndpoint("silverback-examples-error-events")
            {
                Configuration = new KafkaProducerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092"
                }
            })
                                                  .MaxFailedAttempts(2),
                                                  policy
                                                  .Move(new KafkaProducerEndpoint("silverback-examples-events")
            {
                Configuration = new KafkaProducerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092"
                }
            })
                                                  .Transform(
                                                      (msg, ex) => new IntegrationEventA
            {
                Id      = Guid.NewGuid(),
                Content = $"Transformed BadEvent (exception: {ex.Message})"
            },
                                                      (headers, ex) =>
            {
                headers.Add("exception-message", ex.Message);
                return(headers);
            })
                                                  .Publish(messages => new MessageMovedEvent
            {
                Identifiers = messages.Select(x => ((IIntegrationMessage)x?.Content)?.Id ?? Guid.Empty).ToList(),
                Source      = messages.First().Endpoint.Name,
                Destination = "silverback-examples-events"
            })))
                                  .AddInbound(CreateConsumerEndpoint("silverback-examples-custom-serializer",
                                                                     GetCustomSerializer()))
                                  // Special inbound (not logged)
                                  .AddInbound <InboundConnector>(CreateConsumerEndpoint("silverback-examples-legacy-messages",
                                                                                        new JsonMessageSerializer <LegacyMessage>()
            {
                Encoding = MessageEncoding.ASCII
            })));

            Console.CancelKeyPress += (_, __) =>
            {
                broker.Disconnect();
            };
        }
 protected override void Configure(BusConfigurator configurator, IServiceProvider serviceProvider) =>
 configurator.Connect(endpoints => endpoints
                      .AddOutbound <SampleBatchProcessedEvent>(CreateEndpoint()));