項目如果需要引入kafka,可以從以下幾個流程走:
1.pom文件引對應的jar包
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.9.2</artifactId>
<version>0.8.2.1</version>
</dependency>
有的項目還需要將對應使用kafka的包、類作為groupId、artifactId引入
例:
<!-- kafka -->
<!-- <dependency>
<groupId>com.xxx.bis</groupId>
<artifactId>OCC_KAFKA_Client</artifactId>
<version>0.0.1</version>
</dependency>-->
如果項目已經做了相應配置,則只需要引入最上面的jar包即可。
2.配置kafka

spring配置文件引入Kafka
基礎配置完成之后,根據需求,分為生產者和消費者兩種,無論哪種,都需要由運維先創建kafka主題。
並在application等配置信息中聲明主題。
生產者
1)在需要的類中根據需求,引入Kafka,發送信息
@Autowired
private KafkaTemplate kafkaTemplate;
String topic = ConfigHelper.getString("運維創建的kafka主題");
//enrolment_web_space_modify_topic
System.out.println("kafka主題名:" + topic);
kafkaTemplate.send(topic, JsonHelper.toString(config));
消費者
1)進行消費者訂閱配置
2.spring配置Kafka

3.業務訂閱Kafka信息