Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka 卡夫卡休息的例子_Apache Kafka_Kafka Consumer Api_Kafka Producer Api_Confluent Platform - Fatal编程技术网

Apache kafka 卡夫卡休息的例子

Apache kafka 卡夫卡休息的例子,apache-kafka,kafka-consumer-api,kafka-producer-api,confluent-platform,Apache Kafka,Kafka Consumer Api,Kafka Producer Api,Confluent Platform,有没有关于生产者和消费者团体在Java中使用Kafka rest api的好例子。我不是在寻找simpleconsumer或kafka客户的生产者和消费者的例子。感谢您的帮助。最好实现生产者和消费者,然后为生产者和消费者集成RESTAPI producer(){ //your implementation for producer } consumer(){ //your implementation for consumer } REST API: @POST restProducer()

有没有关于生产者和消费者团体在Java中使用Kafka rest api的好例子。我不是在寻找simpleconsumer或kafka客户的生产者和消费者的例子。感谢您的帮助。

最好实现生产者和消费者,然后为生产者和消费者集成RESTAPI

producer(){
//your implementation for producer
}

consumer(){
//your implementation for consumer
}
REST API:

@POST
restProducer(){
producer();
}

@GET
restConsumer(){
consumer();
}
--否则

尝试利用融合实现的RESTAPI

这是来自Confluent的Rest API(Rest代理)代码示例。 不幸的是,不是用Java,而是用Python:(
我必须键入它,所以它可能包含一些拼写错误。我希望这对您有所帮助

(生产者使用用Python编写的RESTAPI)

import requests
import base64
import json

url = "http://restproxy:8082/topics/my_topic"
headers = {
    "Content-Type" : "application/vnd.kafka.binary.v1 + json",
}
# Create one or more messages
payload = {"records":
       [{
           "key":base64.b64encode('firstkey'),
           "value":base64.b64encode('firstvalue'),
       }],
}
# Send the message
r = requests.post(url, data=json.dumps(payload), headers=headers)
if r.status_code != 200:
   print("Status Code: " + str(r.status_code))
   print(r.text)
(消费者使用Python编写的RESTAPI)

import requests
import base64
import json

url = "http://restproxy:8082/topics/my_topic"
headers = {
    "Content-Type" : "application/vnd.kafka.binary.v1 + json",
}
# Create one or more messages
payload = {"records":
       [{
           "key":base64.b64encode('firstkey'),
           "value":base64.b64encode('firstvalue'),
       }],
}
# Send the message
r = requests.post(url, data=json.dumps(payload), headers=headers)
if r.status_code != 200:
   print("Status Code: " + str(r.status_code))
   print(r.text)