kafka.consumer.Whitelist类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中kafka.consumer.Whitelist类的一些代码示例,展示了Whitelist类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Whitelist类的具体详情如下:
包路径:kafka.consumer.Whitelist
类名称:Whitelist

Whitelist介绍

暂无

代码示例

代码示例来源:origin: Graylog2/graylog2-server

cc = Consumer.createJavaConsumerConnector(consumerConfig);
final TopicFilter filter = new Whitelist(configuration.getString(CK_TOPIC_FILTER));

代码示例来源:origin: pinterest/secor

@Override
public void init(SecorConfig config) throws UnknownHostException {
  this.mConfig = config;
  mConsumerConnector = Consumer.createJavaConsumerConnector(createConsumerConfig());
  if (!mConfig.getKafkaTopicBlacklist().isEmpty() && !mConfig.getKafkaTopicFilter().isEmpty()) {
    throw new RuntimeException("Topic filter and blacklist cannot be both specified.");
  }
  TopicFilter topicFilter = !mConfig.getKafkaTopicBlacklist().isEmpty() ? new Blacklist(mConfig.getKafkaTopicBlacklist()) :
      new Whitelist(mConfig.getKafkaTopicFilter());
  LOG.debug("Use TopicFilter {}({})", topicFilter.getClass(), topicFilter);
  List<KafkaStream<byte[], byte[]>> streams =
      mConsumerConnector.createMessageStreamsByFilter(topicFilter);
  KafkaStream<byte[], byte[]> stream = streams.get(0);
  mIterator = stream.iterator();
  mKafkaMessageTimestampFactory = new KafkaMessageTimestampFactory(mConfig.getKafkaMessageTimestampClass());
}

代码示例来源:origin: uber/chaperone

private void init() {
 // register kafka offset lag metrics, one Gauge is for per consumer level granularity
 MetricRegistry registry = Metrics.getRegistry();
 try {
  fetchedMsgCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-msgFetchRate");
  failedToIngestCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-failedToIngest");
  kafkaOffsetLagGauge =
    registry.register("kafkaIngesterConsumer." + this.getName() + "-kafkaOffsetLag", new JmxAttributeGauge(
      new ObjectName(maxLagMetricName), "Value"));
 } catch (MalformedObjectNameException | IllegalArgumentException e) {
  logger.error("Register failure for metrics of KafkaIngesterConsumer", e);
 }
 TopicFilter topicFilter = new Whitelist(AuditConfig.AUDIT_TOPIC_NAME);
 logger.info("{}: Topic filter is {}", getName(), AuditConfig.AUDIT_TOPIC_NAME);
 this.consumer = Consumer.createJavaConsumerConnector(createConsumerConfig());
 KafkaStream<byte[], byte[]> stream = consumer.createMessageStreamsByFilter(topicFilter, 1).get(0);
 iterator = stream.iterator();
 logger.info("KafkaIngesterConsumer thread {} is initialized successfully", getName());
 if (AuditConfig.INGESTER_ENABLE_DEDUP) {
  deduplicator =
    new Deduplicator(threadId, AuditConfig.INGESTER_REDIS_HOST, AuditConfig.INGESTER_REDIS_PORT,
      AuditConfig.INGESTER_REDIS_KEY_TTL_SEC, AuditConfig.INGESTER_DUP_HOST_PREFIX,
      AuditConfig.INGESTER_HOSTS_WITH_DUP);
  deduplicator.open();
 } else {
  deduplicator = null;
 }
}

代码示例来源:origin: stackoverflow.com

Whitelist whitelist = new Whitelist();
Whitelist.simpleText().addTags("table","td", "tr","tbody");

代码示例来源:origin: stackoverflow.com

package stackoverflow;

import org.apache.commons.lang3.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

public class EmbeddedHTML {

  public static void main(String[] args) {
    String src = "<description> &lt;div&gt;&lt;p&gt; An independent" +
        " inquiry into the September 11 attack on the US Consulate" +
        " in Benghazi that killed the US ambassador to Libya and" +
        " three other Americans has found that systematic failures" +
        " at the State Department led to “grossly†inadequate" +
        " security at the mission. &lt;/p&gt;</description>";
    String unescaped = StringEscapeUtils.unescapeHtml4(src);
    System.out.println(Jsoup.clean(unescaped, new Whitelist()));
  }

}

代码示例来源:origin: stackoverflow.com

String text = "<b>Remove <i>bold</i> and italics</b>";
   System.out.println(text);
   String doc =  Jsoup.clean(text, new Whitelist());
   System.out.println(doc);

代码示例来源:origin: stackoverflow.com

@SpringBootApplication
public class Application{
  public static void main(String[] args) {
    ConfigurableApplicationContext context =
      SpringApplication.run(Application.class, args);

    XMLConverter converter = context.getBean(XMLConverter.class)
    Whitelist whitelist = new Whitelist("example");
    converter.convertFromObjectToXML(whitelist, XML_FILE_NAME);
  }

  @Bean
  public XMLConverter xmlConverter(){
    XMLConverter converter = new XMLConverter();
    CastorMarshaller castorMarshaller = new CastorMarshaller()
    converter.setMarshaller(castorMarshaller);
    converter.setUnmarshaller(castorMarshaller);
    return converter;
  }
}

代码示例来源:origin: stackoverflow.com

protected String encodeHtml(String html) {
  return Jsoup.clean(html, getWhitelist());
}

private Whitelist getWhitelist() {
  return new Whitelist()
      .addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup", "dd", "div", "dl",
          "dt", "em", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img", "li", "ol", "p", "pre", "q",
          "small", "strike", "strong", "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead",
          "tr", "u", "ul", "iframe")

      .addAttributes("a", "href", "title").addAttributes("blockquote", "cite")
      .addAttributes("col", "span", "width").addAttributes("colgroup", "span", "width")
      .addAttributes("img", "align", "alt", "height", "src", "title", "width")
      .addAttributes("ol", "start", "type").addAttributes("q", "cite")
      .addAttributes("table", "summary", "width")
      .addAttributes("td", "abbr", "axis", "colspan", "rowspan", "width")
      .addAttributes("th", "abbr", "axis", "colspan", "rowspan", "scope", "width")
      .addAttributes("ul", "type")

      .addProtocols("a", "href", "ftp", "http", "https", "mailto")
      .addProtocols("blockquote", "cite", "http", "https").addProtocols("img", "src", "http", "https")
      .addProtocols("q", "cite", "http", "https");
}

代码示例来源:origin: stackoverflow.com

public class MainActivity extends Activity {
WithFileProgress api;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  TextView content = (TextView)findViewById(R.id.content);
  api = new WithFileProgress(this, content);

  Button button = (Button)findViewById(R.id.button);
  button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      EditText input = (EditText)findViewById(R.id.input);
      String url = input.getText().toString();

      if (Jsoup.isValid(url, new Whitelist())) {
        api.connect(url);
      } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setTitle("MainActivity").setMessage("Invalid address: "+url).create();
      }
    }
  });
}

代码示例来源:origin: stackoverflow.com

int NUMBER_OF_PARTITIONS = 6;
Properties consumerConfig = new Properties();
consumerConfig.put("zk.connect", "zookeeper.mydomain.com:2181" );
consumerConfig.put("backoff.increment.ms", "100");
consumerConfig.put("autooffset.reset", "largest");
consumerConfig.put("groupid", "java-consumer-example");
consumer = Consumer.createJavaConsumerConnector(new ConsumerConfig(consumerConfig));

TopicFilter sourceTopicFilter = new Whitelist("mytopic|myothertopic");
List<KafkaStream<Message>> streams = consumer.createMessageStreamsByFilter(sourceTopicFilter, NUMBER_OF_PARTITIONS);

ExecutorService executor = Executors.newFixedThreadPool(streams.size());
for(final KafkaStream<Message> stream: streams){
  executor.submit(new Runnable() {
    public void run() {
      for (MessageAndMetadata<Message> msgAndMetadata: stream) {
        ByteBuffer buffer = msgAndMetadata.message().payload();
        byte [] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        //Do something with the bytes you just got off Kafka.
      }
    }
  });
}

代码示例来源:origin: salesforce/Argus

private List<KafkaStream<byte[], byte[]>> _createStreams(ConsumerConnector consumer, String topicName) {
  int numStreams = Math.max(Integer.parseInt(
    _configuration.getValue(Property.KAFKA_CONSUMER_STREAMS_PER_TOPIC.getName(),
      Property.KAFKA_CONSUMER_STREAMS_PER_TOPIC.getDefaultValue())), 2);
  return consumer.createMessageStreamsByFilter(new Whitelist(topicName), numStreams);
}

代码示例来源:origin: com.salesforce.argus/argus-core

private List<KafkaStream<byte[], byte[]>> _createStreams(ConsumerConnector consumer, String topicName) {
  int numStreams = Math.max(Integer.parseInt(
    _configuration.getValue(Property.KAFKA_CONSUMER_STREAMS_PER_TOPIC.getName(),
      Property.KAFKA_CONSUMER_STREAMS_PER_TOPIC.getDefaultValue())), 2);
  return consumer.createMessageStreamsByFilter(new Whitelist(topicName), numStreams);
}

代码示例来源:origin: stackoverflow.com

public String escapeHtml(String source) {
  Document doc = Jsoup.parseBodyFragment(source);
  Elements elements = doc.select("b");
  for (Element element : elements) {
    element.replaceWith(new TextNode(element.toString(),""));
  }
  return Jsoup.clean(doc.body().toString(), new Whitelist().addTags("a").addAttributes("a", "href", "name", "rel", "target"));
}

代码示例来源:origin: stackoverflow.com

Whitelist whitelist = new Whitelist();
Set<String> allowedTags = new HashSet<String>();
Map<String, Set<String>> allowedAttributes = new HashMap<String, Set<String>>();

代码示例来源:origin: apache/streams

@Override
public void startStream() {
 Properties props = new Properties();
 props.setProperty("serializer.encoding", "UTF8");
 ConsumerConfig consumerConfig = new ConsumerConfig(props);
 consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);
 Whitelist topics = new Whitelist(config.getTopic());
 VerifiableProperties vprops = new VerifiableProperties(props);
 inStreams = consumerConnector.createMessageStreamsByFilter(topics, 1, new StringDecoder(vprops), new StringDecoder(vprops));
 for (final KafkaStream stream : inStreams) {
  executor.submit(new KafkaPersistReaderTask(this, stream));
 }
}

代码示例来源:origin: org.graylog2/graylog2-inputs

cc = Consumer.createJavaConsumerConnector(consumerConfig);
final TopicFilter filter = new Whitelist(configuration.getString(CK_TOPIC_FILTER));

代码示例来源:origin: org.graylog2/graylog2-server

cc = Consumer.createJavaConsumerConnector(consumerConfig);
final TopicFilter filter = new Whitelist(configuration.getString(CK_TOPIC_FILTER));

代码示例来源:origin: io.druid.extensions/druid-kafka-extraction-namespace

new Whitelist(Pattern.quote(topic)), 1, DEFAULT_STRING_DECODER, DEFAULT_STRING_DECODER
);

代码示例来源:origin: coderczp/dlog

@Override
  public void run() {
    ConsumerConfig cfg = new ConsumerConfig(props);
    consumer = Consumer.createJavaConsumerConnector(cfg);
    TopicFilter arg0 = new Whitelist(topic);
    List<KafkaStream<byte[], byte[]>> partitions = consumer.createMessageStreamsByFilter(arg0);
    while (!Thread.interrupted()) {
      for (KafkaStream<byte[], byte[]> partition : partitions) {
        ConsumerIterator<byte[], byte[]> it = partition
            .iterator();
        while (it.hasNext()) {
          MessageAndMetadata<byte[], byte[]> msg = it.next();
          onMessage(msg.topic(), new String(msg.message()));
        }
      }
    }
  }
}, "consumer-" + topic);

相关文章

Whitelist类方法