コード例 #1
0
 /// <summary>
 /// Constructs a new instance of default API consumer.
 /// </summary>
 /// <param name="api">
 /// The ingress API which messages this consumer process.
 /// </param>
 /// <param name="consumer">
 /// The Kafka API consumer.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// One of arguments is not specified.
 /// </exception>
 public DefaultApiConsumer(
     [NotNull] IIngressApi api,
     [NotNull] IConsumer <TKey, TValue> consumer,
     [NotNull] ILogger <DefaultApiConsumer <TKey, TValue> > logger)
 {
     _api      = api ?? throw new ArgumentNullException(nameof(api));
     _consumer = consumer ?? throw new ArgumentNullException(nameof(consumer));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #2
0
        /// <inheritdoc />
        public IApiConsumer <TKey, TValue> Get <TKey, TValue>([NotNull] IIngressApi api)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            if (!_consumers.TryGetValue(api, out var consumer))
            {
                throw new ArgumentException($"There is no registered consumer for API with ID '{api.Id}'.", nameof(api));
            }

            return((IApiConsumer <TKey, TValue>)consumer);
        }
コード例 #3
0
        /// <inheritdoc />
        public void Add <TKey, TValue>([NotNull] IIngressApi api, [NotNull] IApiConsumer <TKey, TValue> consumer)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (consumer == null)
            {
                throw new ArgumentNullException(nameof(consumer));
            }

            if (!_consumers.TryAdd(api, consumer))
            {
                throw new PoezdConfigurationException($"An ingress API with ID '{api.Id}' and its consumer already registered.");
            }
        }
コード例 #4
0
 private void StartConsumeFromApiTopics <TKey, TValue>(IIngressApi api, CancellationToken cancellationToken) =>
 _consumerRegistry.Get <TKey, TValue>(api).Start(OnMessageReceived, cancellationToken);
コード例 #5
0
 private void CreateAndRegisterConsumer <TKey, TValue>(IIngressApi api) =>
 _consumerRegistry.Add(api, _apiConsumerFactory.Create <TKey, TValue>(_driverConfiguration.ConsumerConfig, api));
コード例 #6
0
 public IApiConsumer <TKey, TValue> Create <TKey, TValue>(ConsumerConfig config, IIngressApi api) => null;
コード例 #7
0
 private static Pipeline <MessageHandlingContext> BuildIngressPipeline(IMessageBroker messageBroker, IIngressApi api)
 {
     try
     {
         var pipeline = new Pipeline <MessageHandlingContext>();
         messageBroker.Ingress.EnterPipeFitter.AppendStepsInto(pipeline);
         api.PipeFitter.AppendStepsInto(pipeline);
         messageBroker.Ingress.ExitPipeFitter.AppendStepsInto(pipeline);
         return(pipeline);
     }
     catch (Exception exception)
     {
         throw new PoezdOperationException(
                   "An error occurred during building an ingress pipeline. Inspect the inner exceptions for more details.",
                   exception);
     }
 }
コード例 #8
0
        /// <inheritdoc />
        public IApiConsumer <TKey, TValue> Create <TKey, TValue>(ConsumerConfig config, IIngressApi api)
        {
            var consumer = _consumerFactory.Create <TKey, TValue>(
                config ?? throw new ArgumentNullException(nameof(config)),
                _consumerConfigurator,
                _deserializerFactory);

            return(new DefaultApiConsumer <TKey, TValue>(
                       api ?? throw new ArgumentNullException(nameof(api)),
                       consumer,
                       _loggerFactory.CreateLogger <DefaultApiConsumer <TKey, TValue> >()));
        }