版本介绍:
Springboot:1.5.3
kafka:kafka_2.10-0.10.2.1
配置文件:
server.port=6097
spring.application.name=DsInfoservice
#============== kafka ===================
kafka.consumer.zookeeper.connect=192.168.xxx.xxx:2181
kafka.consumer.servers=192.168.xxx.xxx:9092
kafka.consumer.enable.auto.commit=true
kafka.consumer.session.timeout=6000
kafka.consumer.auto.commit.interval=100
kafka.consumer.auto.offset.reset=latest
kafka.consumer.topic=test
kafka.consumer.group.id=test1
kafka.consumer.concurrency=10
kafka.producer.servers=192.168.xxx.xxx:9092
kafka.producer.retries=0
kafka.producer.batch.size=4096
kafka.producer.linger=1
kafka.producer.buffer.memory=40960
Dsapplicationstart:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Dsapplicationstart {
public static void main(String[] args) {
SpringApplication.run(Dsapplicationstart.class,args);
}
}
KafkaProducerConfig
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import java.util.HashMap;
import java.util