Apache kafka 卡夫卡休息的例子
有没有关于生产者和消费者团体在Java中使用Kafka rest api的好例子。我不是在寻找simpleconsumer或kafka客户的生产者和消费者的例子。感谢您的帮助。最好实现生产者和消费者,然后为生产者和消费者集成RESTAPIApache 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()
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)