Show / Hide Table of Contents

    Broker Callbacks

    The callbacks are used to notify some events happening during the lifecycle of a message broker client.

    An interface has to be implemented by the callback handler that is then registered via the Add*BrokerCallbacksHandler methods.

    The only generic callback, invoked for any of the actual broker implementation is:

    • IEndpointsConfiguredCallback

    Some broker specific callbacks may be added by the specific broker implementation (see Kafka Events and MQTT Events).

    Example

    In the following example an handler for the IEndpointsConfiguredCallback is being registered.

    • Startup
    • EndpointsConfiguredCallbackHandler
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddSilverback()
                .WithConnectionToMessageBroker(options => options
                    .AddKafka())
                .AddSingletonBrokerCallbacksHandler<EndpointsConfiguredCallbackHandler>();
        }
    }
    
    public class EndpointsConfiguredCallbackHandler
        : IKafkaPartitionsAssignedCallback
    {
        public Task OnEndpointsConfiguredAsync()
        {
            // Perform some initialization logic, 
            // e.g. create the missing topics
        } 
    }
    
    • Improve this doc
    GitHub E-Mail
    ↑ Back to top © 2020 Sergio Aquilini