Repository navigation
Support seting topic schema when creating producers/consumers - #81
lcartercondon wants to merge 3 commits into
Conversation
Added class to allow setting topic schema when creating producers/consumers
| static const std::string CFG_SCHEMA = "schema"; | ||
| static const std::string CFG_SCHEMA_TYPE = "schemaType"; | ||
| static const std::string CFG_SCHEMA_NAME = "name"; | ||
| static const std::string CFG_SCHEMA_SCHEMA = "schema"; | ||
| static const std::string CFG_SCHEMA_PROPS = "properties"; |
There was a problem hiding this comment.
| static const std::string CFG_SCHEMA = "schema"; | |
| static const std::string CFG_SCHEMA_TYPE = "schemaType"; | |
| static const std::string CFG_SCHEMA_NAME = "name"; | |
| static const std::string CFG_SCHEMA_SCHEMA = "schema"; | |
| static const std::string CFG_SCHEMA_PROPS = "properties"; | |
| static const std::string CFG_SCHEMA = "schema"; |
There was a problem hiding this comment.
Yup, thanks for the heads up on cleanup.
| // pulsar_schema_type GetSchemaType(); | ||
| // std::string GetName(); | ||
| // std::string GetSchema(); | ||
| // pulsar_string_map_t GetProperties(); |
There was a problem hiding this comment.
| // pulsar_schema_type GetSchemaType(); | |
| // std::string GetName(); | |
| // std::string GetSchema(); | |
| // pulsar_string_map_t GetProperties(); |
sijie
left a comment
There was a problem hiding this comment.
It seems that this pull request more focused on passing the schema info to the cpp client. but how does nodejs application use this feature? Can you show an example?
|
Even if we can set the schema information, the current Node.js client can handle message payloads only with Buffer type. pulsar-client-node/src/Message.cc Lines 136 to 143 in cc79c67 pulsar-client-node/src/Message.cc Lines 85 to 93 in cc79c67 |
|
This simply allows the NodeJS client to specify the schema when creating the producer or consumer - it doesn't go to the same extent that, say, the Python client does where passing an object (to the producer's send) causes that object to get encoded using the schema info or where the subscriber decodes the message payload to a value using the schema info. I'm planning on adding the automatic encode/decode parts in a similar fashion to how the Python client does it i.e. by wrapping the Producer/Consumer/Message bindings in language-native classes that add information regarding schema and support for automatic encode/decode, but I'm not quite sure yet of the exact implementation. |
|
@massakam I think this is fine - any user of a schema'd topic is (with this implementation) still responsible for serializing to Buffer when sending messages or deserializing from Buffer into whatever schema when consuming messages. |
Once users implement such an application, isn't it a breaking change for them to support automatic encoding/decoding? const buffer = /* object serialization> */;
producer.send({
data: buffer,
});↓ const obj = {
key1: "val1",
key2: "val2",
};
producer.send({
data: obj,
});If so, I think parts for automatic encoding/decoding should be added in this PR or as soon as possible. |
This is a great point - I hadn't thought about it yet. I could work around it in It's definitely a bit more tricky for the message handling function in the consumer. Would it be reasonable to do something along the lines of what the Python lib does? It assigns the decoded |
|
In the case of Python and Go libraries, it seems that binary data and deserialized data can be obtained from different fields of the message object. If the Node.js library follows this, it won't be a breaking change. |
|
Any news about this? It would be great to have schemas in nodejs! Can I help to complete the PR? |
I've not taken a look at this in quite some time unfortunately - I was working on this as part of related work at a prior employer. I'll take a look at this again this weekend, but cannot make any guarantees as to completing the requested changes. Contributions that complete the requests are absolutely welcome, I believe all that's left is:
There has been some chatter in this PR re adding automatic encode/decode support, similar to how Python and Go client libs do it. Contributions that add that would be above and beyond but are absolutely welcome as well. I'll update this weekend if I'm able to accomplish the requested changes and/or automatic encode/decode support feature request. |
|
@lcartercondon hi, thanks for the reply. Alternatively, you can close this PR with docs and I can submit an new PR with audo encode/decode! |
|
Any updates on this? Seems like a really useful feature. As I understand it, without schema support, Pulsar SQL is basically non-functional without this feature. Am I correct in that understanding? |
|
@sijie Any update on this request ? It is really important to the world because numbers of nodejs developer become more and more now |
|
@lcartercondon Could you please rebase to the master branch? |
|
I've resolved the conflict, but the current code fails to compile. |
| void SchemaInfo::SetProducerSchema(pulsar_producer_configuration_t *cProducerConfiguration) { | ||
| pulsar_producer_configuration_set_schema_info(cProducerConfiguration, this->cSchemaType, this->name.c_str(), |
There was a problem hiding this comment.
| void SchemaInfo::SetProducerSchema(pulsar_producer_configuration_t *cProducerConfiguration) { | |
| pulsar_producer_configuration_set_schema_info(cProducerConfiguration, this->cSchemaType, this->name.c_str(), | |
| void SchemaInfo::SetProducerSchema(std::shared_ptr<pulsar_producer_configuration_t> cProducerConfiguration) { | |
| pulsar_producer_configuration_set_schema_info(cProducerConfiguration.get(), this->cSchemaType, this->name.c_str(), |
| void SchemaInfo::SetConsumerSchema(pulsar_consumer_configuration_t *cConsumerConfiguration) { | ||
| pulsar_consumer_configuration_set_schema_info(cConsumerConfiguration, this->cSchemaType, this->name.c_str(), |
There was a problem hiding this comment.
| void SchemaInfo::SetConsumerSchema(pulsar_consumer_configuration_t *cConsumerConfiguration) { | |
| pulsar_consumer_configuration_set_schema_info(cConsumerConfiguration, this->cSchemaType, this->name.c_str(), | |
| void SchemaInfo::SetConsumerSchema(std::shared_ptr<pulsar_consumer_configuration_t> cConsumerConfiguration) { | |
| pulsar_consumer_configuration_set_schema_info(cConsumerConfiguration.get(), this->cSchemaType, this->name.c_str(), |
| public: | ||
| SchemaInfo(const Napi::Object &schemaInfo); | ||
| ~SchemaInfo(); | ||
| void SetProducerSchema(pulsar_producer_configuration_t *cProducerConfiguration); |
There was a problem hiding this comment.
| void SetProducerSchema(pulsar_producer_configuration_t *cProducerConfiguration); | |
| void SetProducerSchema(std::shared_ptr<pulsar_producer_configuration_t> cProducerConfiguration); |
| SchemaInfo(const Napi::Object &schemaInfo); | ||
| ~SchemaInfo(); | ||
| void SetProducerSchema(pulsar_producer_configuration_t *cProducerConfiguration); | ||
| void SetConsumerSchema(pulsar_consumer_configuration_t *cConsumerConfiguration); |
There was a problem hiding this comment.
| void SetConsumerSchema(pulsar_consumer_configuration_t *cConsumerConfiguration); | |
| void SetConsumerSchema(std::shared_ptr<pulsar_consumer_configuration_t> cConsumerConfiguration); |
|
@lcartercondon Could you fix the compilation error? |
|
This change is merged as a new PR with fixing some compliation errors: @lcartercondon Thank you for your contribution! |
Added class to allow setting topic schema when creating
producers/consumers