コード例 #1
0
 private static IReadOnlyDictionary <string, KafkaProducerEndpoint> BuildEndpointsDictionary(
     IReadOnlyDictionary <string, Action <IKafkaProducerEndpointBuilder> > endpointBuilderActions,
     KafkaClientConfig?clientConfig) =>
 Check.NotNull(endpointBuilderActions, nameof(endpointBuilderActions))
 .ToDictionary(
     pair => pair.Key,
     pair => BuildEndpoint(pair.Value, clientConfig));
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaProducerEndpointBuilder" /> class.
 /// </summary>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaProducerConfig" />.
 /// </param>
 /// <param name="endpointsConfigurationBuilder">
 ///     The optional reference to the <see cref="IEndpointsConfigurationBuilder" /> that instantiated the
 ///     builder.
 /// </param>
 public KafkaProducerEndpointBuilder(
     KafkaClientConfig?clientConfig = null,
     IEndpointsConfigurationBuilder?endpointsConfigurationBuilder = null)
     : base(endpointsConfigurationBuilder)
 {
     _clientConfig = clientConfig;
 }
コード例 #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaOutboundEndpointRouter{TMessage}" /> class.
 /// </summary>
 /// <param name="routerFunction">
 ///     The <see cref="DictionaryOutboundRouter{TMessage,TEndpoint}.RouterFunction" />.
 /// </param>
 /// <param name="endpointBuilderActions">
 ///     The <see cref="IReadOnlyDictionary{TKey,TValue}" /> containing the key of each endpoint and the
 ///     <see cref="Action{T}" /> to be invoked to build them.
 /// </param>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaProducerConfig" />.
 /// </param>
 public KafkaOutboundEndpointRouter(
     RouterFunction routerFunction,
     IReadOnlyDictionary <string, Action <IKafkaProducerEndpointBuilder> > endpointBuilderActions,
     KafkaClientConfig?clientConfig = null)
     : base(routerFunction, BuildEndpointsDictionary(endpointBuilderActions, clientConfig))
 {
 }
コード例 #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaProducerConfig" /> class.
 /// </summary>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaProducerConfig" />.
 /// </param>
 public KafkaProducerConfig(KafkaClientConfig?clientConfig = null)
     : base(clientConfig?.GetConfluentConfig())
 {
     // Optimization: by default limit delivery report to just key and status since no other field
     // is needed
     DeliveryReportFields = "key,status";
 }
コード例 #5
0
 public KafkaProducerEndpoint(
     string nameFormat,
     Func <IOutboundEnvelope, string[]> argumentsFunction,
     KafkaClientConfig?clientConfig = null)
     : this(nameFormat, argumentsFunction, null, clientConfig)
 {
 }
コード例 #6
0
        private static KafkaProducerEndpoint BuildEndpoint(
            Action <IKafkaProducerEndpointBuilder> builderAction,
            KafkaClientConfig?clientConfig)
        {
            var builder = new KafkaProducerEndpointBuilder(clientConfig);

            builderAction.Invoke(builder);

            return(builder.Build());
        }
コード例 #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KafkaConsumerEndpoint" /> class.
        /// </summary>
        /// <param name="topicNames">
        ///     The name of the topics.
        /// </param>
        /// <param name="clientConfig">
        ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
        ///     <see cref="KafkaConsumerConfig" />.
        /// </param>
        public KafkaConsumerEndpoint(string[] topicNames, KafkaClientConfig?clientConfig = null)
            : base(string.Empty)
        {
            if (topicNames == null || topicNames.Length == 0)
            {
                return;
            }

            Init(topicNames, clientConfig);
        }
コード例 #8
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KafkaProducerEndpoint" /> class.
        /// </summary>
        /// <param name="nameResolverType">
        ///     The type of the <see cref="IKafkaProducerEndpointNameResolver" /> to be used to resolve the actual
        ///     endpoint name.
        /// </param>
        /// <param name="clientConfig">
        ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
        ///     <see cref="KafkaProducerConfig" />.
        /// </param>
        public KafkaProducerEndpoint(Type nameResolverType, KafkaClientConfig?clientConfig = null)
            : base(nameResolverType)
        {
            Configuration = new KafkaProducerConfig(clientConfig);

            if (!typeof(IKafkaProducerEndpointNameResolver).IsAssignableFrom(nameResolverType))
            {
                throw new ArgumentException(
                          "The specified type must implement IKafkaProducerEndpointNameResolver.",
                          nameof(nameResolverType));
            }

            _partitionFunction = (envelope, serviceProvider) =>
                                 ((IKafkaProducerEndpointNameResolver)serviceProvider.GetRequiredService(nameResolverType))
                                 .GetPartition(envelope) ?? Partition.Any;
        }
コード例 #9
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KafkaProducerEndpoint" /> class.
        /// </summary>
        /// <param name="nameFunction">
        ///     The function returning the endpoint name for the message being produced.
        /// </param>
        /// <param name="partitionFunction">
        ///     The optional function returning the target partition index for the message being produced. If <c>null</c>
        ///     the partition is automatically derived from the message key (use <see cref="KafkaKeyMemberAttribute" />
        ///     to specify a message key, otherwise a random one will be generated).
        /// </param>
        /// <param name="clientConfig">
        ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
        ///     <see cref="KafkaProducerConfig" />.
        /// </param>
        public KafkaProducerEndpoint(
            Func <IOutboundEnvelope, string> nameFunction,
            Func <IOutboundEnvelope, int>?partitionFunction,
            KafkaClientConfig?clientConfig = null)
            : base(nameFunction)
        {
            Configuration = new KafkaProducerConfig(clientConfig);

            if (partitionFunction != null)
            {
                _partitionFunction = (envelope, _) => partitionFunction.Invoke(envelope);
            }
            else
            {
                _partitionFunction = AnyPartitionFunction;
            }
        }
コード例 #10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KafkaProducerEndpoint" /> class.
        /// </summary>
        /// <param name="name">
        ///     The name of the topic.
        /// </param>
        /// <param name="partition">
        ///     The optional partition index. If <c>null</c> the partition is automatically derived from the message
        ///     key (use <see cref="KafkaKeyMemberAttribute" /> to specify a message key, otherwise a random one will be
        ///     generated).
        /// </param>
        /// <param name="clientConfig">
        ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
        ///     <see cref="KafkaProducerConfig" />.
        /// </param>
        public KafkaProducerEndpoint(
            string name,
            int?partition,
            KafkaClientConfig?clientConfig = null)
            : base(name)
        {
            if (partition != null && partition < Partition.Any)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(partition),
                          "The partition index must be greater or equal to 0, or Partition.Any (-1).");
            }

            Configuration = new KafkaProducerConfig(clientConfig);

            if (partition != null)
            {
                _partitionFunction = (_, _) => partition.Value;
            }
            else
            {
                _partitionFunction = AnyPartitionFunction;
            }
        }
コード例 #11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaConsumerEndpoint" /> class.
 /// </summary>
 /// <param name="topicPartitions">
 ///     The topics and partitions to be consumed.
 /// </param>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaConsumerConfig" />.
 /// </param>
 public KafkaConsumerEndpoint(
     IEnumerable <TopicPartition> topicPartitions,
     KafkaClientConfig?clientConfig = null)
     : this(
         topicPartitions?.Select(
             topicPartition => new TopicPartitionOffset(topicPartition, Offset.Unset)) !,
コード例 #12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaConsumerEndpoint" /> class.
 /// </summary>
 /// <param name="topicName">
 ///     The name of the topic.
 /// </param>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaConsumerConfig" />.
 /// </param>
 public KafkaConsumerEndpoint(string topicName, KafkaClientConfig?clientConfig = null)
     : this(new[] { topicName }, clientConfig)
 {
 }
コード例 #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaConsumerConfig" /> class.
 /// </summary>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaConsumerConfig" />.
 /// </param>
 public KafkaConsumerConfig(KafkaClientConfig?clientConfig = null)
     : base(clientConfig?.GetConfluentConfig())
 {
 }
コード例 #14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaProducerEndpoint" /> class.
 /// </summary>
 /// <param name="nameFunction">
 ///     The function returning the endpoint name for the message being produced.
 /// </param>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaProducerConfig" />.
 /// </param>
 public KafkaProducerEndpoint(
     Func <IOutboundEnvelope, string> nameFunction,
     KafkaClientConfig?clientConfig = null)
     : this(nameFunction, null, clientConfig)
 {
 }
コード例 #15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KafkaProducerEndpoint" /> class.
 /// </summary>
 /// <param name="name">
 ///     The name of the topic.
 /// </param>
 /// <param name="clientConfig">
 ///     The <see cref="KafkaClientConfig" /> to be used to initialize the
 ///     <see cref="KafkaProducerConfig" />.
 /// </param>
 public KafkaProducerEndpoint(
     string name,
     KafkaClientConfig?clientConfig = null)
     : this(name, (int?)null, clientConfig)
 {
 }