88e030b7
王彪总
init project
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package com.java110.utils.kafka;
import com.java110.utils.factory.ApplicationContextFactory;
import org.springframework.kafka.core.KafkaTemplate;
/**
* kafka 工厂类
* Created by wuxw on 2018/4/15.
*/
public class KafkaFactory {
/**
* 获取kafka template
* @return
*/
private static KafkaTemplate getKafkaTemplate(){
return (KafkaTemplate) ApplicationContextFactory.getBean("kafkaTemplate");
}
/**
* 发送kafka消息
* @param topic
* @param key
* @param message
* @throws Exception
*/
public static void sendKafkaMessage(String topic,String key,Object message) throws Exception{
getKafkaTemplate().send(topic,key,message);
}
/**
* 发送kafka消息
* @param topic
* @param message
* @throws Exception
*/
public static void sendKafkaMessage(String topic,Object message) throws Exception{
getKafkaTemplate().send(topic,"",message);
}
}
|