예제 #1
0
  private Properties getProducerProperties(String topic) {
    Properties configs = KafkaProperties.getDefaultKafkaProducerProperties();

    try {
      Properties envProperties = m_environment.getProducerConfig(topic);
      configs.putAll(envProperties);
    } catch (IOException e) {
      m_logger.warn("read producer config failed", e);
    }

    List<Partition> partitions = m_metaService.listPartitionsByTopic(topic);
    if (partitions == null || partitions.size() < 1) {
      return configs;
    }

    String producerDatasource = partitions.get(0).getWriteDatasource();
    Storage producerStorage = m_metaService.findStorageByTopic(topic);
    if (producerStorage == null) {
      return configs;
    }

    for (Datasource datasource : producerStorage.getDatasources()) {
      if (producerDatasource.equals(datasource.getId())) {
        Map<String, Property> properties = datasource.getProperties();
        for (Map.Entry<String, Property> prop : properties.entrySet()) {
          configs.put(prop.getValue().getName(), prop.getValue().getValue());
        }
        break;
      }
    }

    return KafkaProperties.overrideByCtripDefaultProducerSetting(configs);
  }