我有一个json有效负载,我想在生产者Api
中作为标题发送Content-Type: application/xml
以上有效负载应作为标头发送
{
"type": "record_created",
"version": 1,
"orgId": "",
"userId": "",
"userName": "",
"correlationId": "",
"jobId": ""
}
我们怎么做?
答案 0 :(得分:1)
有两种方式
1) getHeaders并添加标题
ProducerRecord<Integer, String> record = new ProducerRecord<Integer, String>("topic", 1, "message");
record.headers().add(new RecordHeader("type", "record_created".getBytes()));
record.headers().add(new RecordHeader("type", "record_created".getBytes()));
producer.send(record);
2) 使用ProducerRecord(String topic,Integer partition,K key,V value,Iterable headers)
但这样你必须决定分区 - 否