private ConsumerConfig getConsumerConfig(DestinationConfiguration destination) {
   destination.getUrl();
   String queue;
   String zkHost = properties.get("broker.zk.servers");
   String zkRoot = properties.get("broker.zk.root");
   ZkHosts zkHosts = new ZkHosts(zkHost, zkRoot);
   if (!destination.isGrouped()) {
     queue =
         destination.getSite()
             + "."
             + destination.getSensor()
             + "."
             + destination.getSensorId()
             + "."
             + destination.getProperty("topic");
   } else {
     queue =
         destination.getSite()
             + "."
             + destination.getSensor()
             + "."
             + destination.getProperty("topic");
   }
   ConsumerConfig consumerConfig = new ConsumerConfig(zkHosts, queue, "/iot/broker", queue);
   Iterable<String> iterable = Splitter.on(",").split(zkHost);
   Iterator<String> it = iterable.iterator();
   consumerConfig.zkServers = new ArrayList<String>();
   while (it.hasNext()) {
     consumerConfig.zkServers.add(it.next());
   }
   return consumerConfig;
 }
예제 #2
0
  private KafkaConsumer(
      ConsumerConfig config,
      ConsumerRebalanceCallback callback,
      Deserializer<K> keyDeserializer,
      Deserializer<V> valueDeserializer) {
    log.trace("Starting the Kafka consumer");
    subscribedTopics = new HashSet<String>();
    subscribedPartitions = new HashSet<TopicPartition>();
    this.metrics =
        new Metrics(
            new MetricConfig(),
            Collections.singletonList((MetricsReporter) new JmxReporter("kafka.consumer.")),
            new SystemTime());
    this.metadataFetchTimeoutMs = config.getLong(ConsumerConfig.METADATA_FETCH_TIMEOUT_CONFIG);
    this.totalMemorySize = config.getLong(ConsumerConfig.TOTAL_BUFFER_MEMORY_CONFIG);

    List<InetSocketAddress> addresses =
        ClientUtils.parseAndValidateAddresses(
            config.getList(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));

    if (keyDeserializer == null)
      this.keyDeserializer =
          config.getConfiguredInstance(
              ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, Deserializer.class);
    else {
      this.keyDeserializer = keyDeserializer;
    }

    if (valueDeserializer == null)
      this.valueDeserializer =
          config.getConfiguredInstance(
              ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, Deserializer.class);
    else {
      this.valueDeserializer = valueDeserializer;
    }

    config.logUnused();
    log.debug("Kafka consumer started");
  }