Ejemplo n.º 1
0
 public SetKeyPipe(KafkaKeyResolver <TKey, TValue> keyResolver, IPipe <KafkaSendContext <TKey, TValue> > pipe = null)
 {
     _keyResolver = keyResolver;
     _pipe        = pipe;
 }
        /// <summary>
        /// Add a provider to the container for the specified message type, using a key type of Null
        /// The producer must be configured in the UsingKafka configuration method.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="topicName">The topic name</param>
        /// <param name="producerConfig"></param>
        /// <param name="keyResolver">Key resolver</param>
        /// <typeparam name="T">The message type</typeparam>
        /// <typeparam name="TKey">The key type</typeparam>
        public static IKafkaProducerRegistrationConfigurator <TKey, T> AddProducer <TKey, T>(this IRiderRegistrationConfigurator configurator, string topicName,
                                                                                             ProducerConfig producerConfig, KafkaKeyResolver <TKey, T> keyResolver)
            where T : class
        {
            IKafkaProducerRegistrationConfigurator <TKey, T> registration = configurator.AddProducer <TKey, T>(topicName, producerConfig);

            configurator.Registrar.Register <ITopicProducer <T> >(provider =>
                                                                  new KeyedTopicProducer <TKey, T>(provider.GetRequiredService <ITopicProducer <TKey, T> >(), keyResolver));

            return(registration);
        }
Ejemplo n.º 3
0
 public KeyedTopicProducer(ITopicProducer <TKey, TValue> topicProducer, KafkaKeyResolver <TKey, TValue> keyResolver)
 {
     _topicProducer = topicProducer;
     _keyResolver   = keyResolver;
 }