我们有一个系统(示例系统A),它通过HTTP发送时间序列数据。
我现在想将Apache Kafka引入系统。
我的想法是运行Kafka服务器,系统A在收到时间序列消息后立即将此消息发布到Apache Kafka服务器。
在这里,我有一个疑问,如何发布通过HTTP协议发送的时间序列数据?
这是一个例子。
我有以下网址来收集数据:
http://ipaddress:portno/HttpPush/Track?event
接收以下分层数据
2017-08-17 00:00:21 INFO:?data = $ Sensor,x8,86832364748057,20170816235919,13,1,1,5 | 2,0,7,20170816235854,0,0,0,0,128 ,0,4095 | 3,0,10,20170816235854,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00 | 2,0,7,20170816235859,0,0,0,0,128,0 ,4095
注意:我正在接收20kps数据
有没有人可以帮我提供示例kafka生产者API这个例子。
答案 0 :(得分:1)
此处Kafka REST Proxy可能很有用。源系统可以通过HTTP直接将其数据流式传输到Kafka。
答案 1 :(得分:0)
您可以将URL中的数据转换为String,并将该数据放入将数据发布到kafka的方法中。 1,用生产者属性初始化生产者(例如,参见下面的代码片段)
producer = new KafkaProducer<String, String>(KafkaConfiguration.producerProperties);
logger.info("JetKafkaProducer{" + this.hashCode() + "} initalised Successfully ,for the topic {" + topic
+ "}");
logger.debug("JetKafkaProducer with hash code: {" + this.hashCode() + "}, for the topic{" + topic
+ "} has producer properties: " + KafkaConfiguration.producerProperties);
现在发布消息
public void publishMesssage(String data) throws Exception {
if (getTopic() != null && data != null) {
ProducerRecord<String, String> record = new ProducerRecord<String, String>(this.getTopic(), data);
producer.send(record); // This publishes message on given topic
logger.info("Published record to Kafka " + data.toString());
} else {
logger.error("Failed to publish record to " + getTopic() + " Data: " + data.toString());
}
return;
}