Exemplo n.º 1
0
        public InboundConsumer(IBroker broker,
                               IEndpoint endpoint,
                               InboundConnectorSettings settings,
                               Action <IEnumerable <IInboundMessage>, IServiceProvider> messagesHandler,
                               Action <IServiceProvider> commitHandler,
                               Action <IServiceProvider> rollbackHandler,
                               IErrorPolicy errorPolicy,
                               IServiceProvider serviceProvider)
        {
            _endpoint    = endpoint;
            _settings    = settings;
            _errorPolicy = errorPolicy;

            _messagesHandler = messagesHandler;
            _commitHandler   = commitHandler;
            _rollbackHandler = rollbackHandler;

            _serviceProvider         = serviceProvider;
            _logger                  = serviceProvider.GetRequiredService <ILogger <InboundConsumer> >();
            _messageLogger           = serviceProvider.GetRequiredService <MessageLogger>();
            _inboundMessageProcessor = serviceProvider.GetRequiredService <InboundMessageProcessor>();

            _consumer = broker.GetConsumer(_endpoint);

            Bind();
        }
Exemplo n.º 2
0
        public InboundConsumer(IBroker broker,
                               IEndpoint endpoint,
                               InboundConnectorSettings settings,
                               Func <IEnumerable <IInboundMessage>, IServiceProvider, Task> messagesHandler,
                               Func <IServiceProvider, Task> commitHandler,
                               Func <IServiceProvider, Task> rollbackHandler,
                               IErrorPolicy errorPolicy,
                               IServiceProvider serviceProvider)
        {
            if (broker == null)
            {
                throw new ArgumentNullException(nameof(broker));
            }

            _endpoint    = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
            _settings    = settings ?? throw new ArgumentNullException(nameof(settings));
            _errorPolicy = errorPolicy;

            _messagesHandler = messagesHandler ?? throw new ArgumentNullException(nameof(messagesHandler));
            _commitHandler   = commitHandler ?? throw new ArgumentNullException(nameof(commitHandler));
            _rollbackHandler = rollbackHandler ?? throw new ArgumentNullException(nameof(rollbackHandler));

            _serviceProvider   = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _logger            = serviceProvider.GetRequiredService <ILogger <InboundConsumer> >();
            _errorPolicyHelper = serviceProvider.GetRequiredService <ErrorPolicyHelper>();

            _consumer = broker.GetConsumer(_endpoint);

            Bind();
        }
Exemplo n.º 3
0
        private static void Connect()
        {
            var messageKeyProvider = new MessageKeyProvider(new[] { new DefaultPropertiesMessageKeyProvider() });

            _broker = new KafkaBroker(messageKeyProvider, GetLoggerFactory(), new MessageLogger(messageKeyProvider));

            _consumer = _broker.GetConsumer(new KafkaConsumerEndpoint("Topic1")
            {
                Configuration = new KafkaConsumerConfig
                {
                    BootstrapServers = "PLAINTEXT://kafka:9092",
                    GroupId          = "silverback-consumer",
                    AutoOffsetReset  = Confluent.Kafka.AutoOffsetReset.Earliest
                }
            });

            _consumer.Received += OnMessageReceived;

            _broker.Connect();
        }
Exemplo n.º 4
0
        private static void Connect()
        {
            _consumer = _broker.GetConsumer(new KafkaConsumerEndpoint("Topic1")
            {
                Configuration = new KafkaConsumerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092",
                    GroupId          = "silverback-consumer",
                    AutoOffsetReset  = Confluent.Kafka.AutoOffsetReset.Earliest
                },
                Serializer = new JsonMessageSerializer <TestMessage>()
            });

            _consumer.Received += OnMessageReceived;

            _broker.Connect();

            Console.CancelKeyPress += (_, e) =>
            {
                _broker.Disconnect();
                _activity.Stop();
            };
        }