Пример #1
0
 public SyncProducerConfig(ProducerConfig config, string host, int port) 
 {
     this.Host = host;
     this.Port = port;
     this.SendBufferBytes = config.SendBufferBytes;
     this.ClientId = config.ClientId;
     this.RequestRequiredAcks = config.RequestRequiredAcks;
     this.RequestTimeoutMs = config.RequestTimeoutMs;
 }
Пример #2
0
 public ProducerPool(ProducerConfig config)
 {
     this.config = config;
     this.syncProducers = new Dictionary<int, SyncProducer>();
 }
Пример #3
0
 public static SyncProducer CreateSyncProducer(ProducerConfig config, Broker broker)
 {
     return new SyncProducer(new SyncProducerConfig(config, broker.Host, broker.Port));
 }
        public List<string> SendMessages(
            TempKafkaConfig config, int messagesPerNode, string header, CompressionCodecs compressionCodec, int numParts)
        {
            var messages = new List<string>();
            var props = new ProducerConfig
            {
                Brokers = TestUtils.GetBrokerListFromConfigs(Configs),
                PartitionerClass = typeof(FixedValuePartitioner).AssemblyQualifiedName,
                KeySerializer = typeof(IntEncoder).AssemblyQualifiedName,
                Serializer = typeof(StringEncoder).AssemblyQualifiedName,
                RetryBackoffMs = 1000,
            };
            var producer = new Producer<int, string>(props);
            for (var partition = 0; partition < numParts; partition++)
            {
                var ms =
                    Enumerable.Range(0, messagesPerNode)
                              .Select(x => header + config.BrokerId + "-" + partition + "-" + x)
                              .ToList();
                producer.Send(ms.Select(m => new KeyedMessage<int, string>(Topic, partition, m)).ToArray());
                messages.AddRange(ms);
                Logger.DebugFormat("Sent {0} messages to broker {1} for partition [{2},{3}]", ms.Count, config.BrokerId, Topic, partition);
            }

            producer.Dispose();
            return messages;
        }
 public List<string> SendMessagesToBrokerPartition(
     TempKafkaConfig config,
     string topic,
     int partition,
     int numMessages,
     CompressionCodecs compression = CompressionCodecs.NoCompressionCodec)
 {
     var header = string.Format("test-{0}-{1}", config.BrokerId, partition);
     var props = new ProducerConfig
                     {
                         Brokers = TestUtils.GetBrokerListFromConfigs(Configs),
                         PartitionerClass = typeof(FixedValuePartitioner).AssemblyQualifiedName,
                         CompressionCodec = compression,
                         KeySerializer = typeof(IntEncoder).AssemblyQualifiedName,
                         Serializer = typeof(StringEncoder).AssemblyQualifiedName,
                         RetryBackoffMs = 1000, // custom: we need time to rebalance leader
                     }; 
     var producer = new Producer<int, string>(props);
     var ms =
         Enumerable.Range(0, numMessages)
                   .Select(x => header + config.BrokerId + "-" + partition + "-" + x)
                   .ToList();
     producer.Send(ms.Select(x => new KeyedMessage<int, string>(topic, partition, x)).ToArray());
     Logger.DebugFormat("Sent {0} messages to broker {1} for partition [{2},{3}]", ms.Count, config.BrokerId, Topic, partition);
     producer.Dispose();
     return ms;
 }
Пример #6
0
 public DefaultPartitioner(ProducerConfig config)
 {
 }