【发布时间】:2020-07-02 20:32:48
【问题描述】:
在我的例子中,我有一些原始 JSON 字符串数据发送到主题并且无法对 POJO 类进行硬编码,我想使用 pulsar 模式特性来验证结构。我有一个主题“我的主题”并与下面的 JSON 模式相关联,然后我尝试传输一些消息。
var producer = client.newProducer(Schema.AUTO_PRODUCE_BYTES();
producer.send("{\"y\": 1}".getBytes()); // here! the value is 1(number) not string.
var reader = client.newReader(Schema.AUTO_CONSUME())
var message = reader.readNext();
I got {"y": 1}
我的问题是脉冲星模式是如何工作的?邮件应该被拒绝。
{
"version": 1,
"schemaInfo": {
"name": "my-topic",
"schema": {
"type": "record",
"name": "Data",
"namespace": "com.iot.test",
"fields": [
{
"name": "y",
"type": [
"null",
"string"
]
}
]
},
"type": "JSON",
"properties": {
"__alwaysAllowNull": "true"
}
}
}
【问题讨论】:
标签: apache-pulsar pulsar