narcisoguillen / kafka-node-avro

ISC License
26 stars 13 forks source link

Requesting functionality: be able to send to a topic with a different name than schema #2

Closed ryanscfan closed 4 years ago

ryanscfan commented 5 years ago

Hi,

My topic and schema have different names.

From send.js, it looked like it only sends if it can find a schema with the same data.topic.

SchemaPool.getByName(data.topic).then( schema => {
      schema.parse(data).then(send, reject);
    }, reject);

Please let me know if this functionality is already available!

Thanks, Ryan

narcisoguillen commented 5 years ago

Hey Ryan, thanks for using kafka-node-avro ! ... you are right so far on send it will ask to the SchemaPool for the Schema that matches the name of the topic, the ability to send ( produce ) on a topic with a specific schema is not there.

When I build the send mechanism I assume the topic name should match the schema name.

maybe something like

kafka.send({
  schema     : {Schema},
  messages : {
    foo : 'hello',
    bar : 'world'
  }
}).then( success => {
  // Message was sent encoded with Avro Schema
}, error => {
  // Something wrong happen
});

this means you should manually get the schema with kafka.schemas.getById(1) or kafka.schemas.getByName('my.cool.topic') then use it on the send.

cogitaria-admin commented 4 years ago

I would clarify some of this on the README because it is a definite source of confusion (not by you but in general). The convention is to append -value to the topic when naming a schema. You are doing the same in Registry.fetchByVersion, so it magically works with our topic/schema pairs because we use that convention.

I think it's also important to be very precise with terms like "schema" versus "subject" and pointing out the equivalence of a subject + version identifying an actual schema instance.

As for the globally unique schema ID, how do you even get that? The only way is if you know the subject and version. There is a /schemas/ids end-point but it 404s unless you add the actual ID which is not very RESTful.

This works: http://localhost:8081/subjects/some-topic-value/versions/1