zoukankan      html  css  js  c++  java
  • kafka demo

     public static void main(String[] args) {
    
            Properties props = new Properties();
            props.put("bootstrap.servers", "mini1:9092");
            props.put("group.id", "test123456");
            props.put("enable.auto.commit", "true");
            props.put("auto.commit.interval.ms", "1000");
            props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
            consumer.subscribe(Arrays.asList("first"));
            while (true) {
                ConsumerRecords<String, String> records = consumer.poll(100);
                for (ConsumerRecord<String, String> record : records)
                    System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
            }
        }
     
        public static void main(String[] args) throws InterruptedException {
    
            Properties props = new Properties();
            props.put("bootstrap.servers", "mini1:9092");
            props.put("acks", "all");
            props.put("retries", 0);
            props.put("batch.size", 16384);
            props.put("linger.ms", 1);
            props.put("buffer.memory", 33554432);
            props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
            props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    
            Producer<String, String> producer = new KafkaProducer<>(props);
            for(int i = 0; i < 100; i++) {
    
                producer.send(new ProducerRecord<String, String>("first", Integer.toString(i), Integer.toString(i)));
            }
            producer.close();
    
    
    
        }
  • 相关阅读:
    php通过curl发送XML数据,并获取XML数据
    js预编译环节 变量声明提升 函数声明整体提升
    JavaScript 字符串转json格式
    PHP保留两位小数的几种方法
    tp5.1 错误 No input file specified.
    frame与iframe的区别及基本用法
    iframe的用法
    Jquery DataTable基本使用
    松软科技课堂:SQL--FULLJOIN关键字
    松软科技课堂:SQL-LEFT-JOIN 关键字
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/7453369.html
Copyright © 2011-2022 走看看