Skip to content

Commit

Permalink
Adds isStringRegistryKey boolean option (#90)
Browse files Browse the repository at this point in the history
- the option allows to have simple string keys instead of avro keys

Co-authored-by: Oleksandr Krupko <[email protected]>
  • Loading branch information
OleksandrKrupko and Oleksandr Krupko authored May 18, 2020
1 parent a8e10fb commit ee5fcaa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ When instantiating kafka-avro you may pass the following options:
* `shouldFailWhenSchemaIsMissing` **Boolean** Set to true if producing a message for which no AVRO schema can be found should throw an error
* `keySubjectStrategy` **String** A SubjectNameStrategy for key. It is used by the Avro serializer to determine the subject name under which the event record schemas should be registered in the schema registry. The default is TopicNameStrategy. Allowed values are [TopicRecordNameStrategy, TopicNameStrategy, RecordNameStrategy]
* `valueSubjectStrategy` **String** A SubjectNameStrategy for value. It is used by the Avro serializer to determine the subject name under which the event record schemas should be registered in the schema registry. The default is TopicNameStrategy. Allowed values are [TopicRecordNameStrategy, TopicNameStrategy, RecordNameStrategy]
* `isStringRegistryKey` **Boolean** Set to true to not send requests for Avro schemas for keys. Set to `false` by default

### Producer

Expand Down Expand Up @@ -301,6 +302,8 @@ You can use `docker-compose up` to up all the stack before you call your integra
* `grunt release:major` for major number jump.

## Release History
- **3.0.3**, *15 May 2020*
- Adds support for string type schema registry keys parameter, feature by [OleksandrKrupko](github.com/OleksandrKrupko).
- **3.0.2**, *14 Jan 2020*
- Adds support for basic authentication to schema registry, using Axios auth Request Config parameter, feature by [Bookaway](github.com/Bookaway).
- **3.0.1**, *13 Jan 2020*
Expand Down
1 change: 1 addition & 0 deletions lib/kafka-avro.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const KafkaAvro = module.exports = CeventEmitter.extend(function (opts) {
schemaRegistryUrl: opts.schemaRegistry,
auth: opts.schemaRegistryAuth || null,
selectedTopics: opts.topics || null,
isStringRegistryKey: opts.isStringRegistryKey || false,
fetchAllVersions: opts.fetchAllVersions || false,
fetchRefreshRate: opts.fetchRefreshRate || 0,
parseOptions: opts.parseOptions,
Expand Down
9 changes: 7 additions & 2 deletions lib/schema-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const SchemaRegistry = module.exports = cip.extend(function (opts) {
/** @type {Array.<string>|null} The user selected topics to fetch, can be null */
this.selectedTopics = opts.selectedTopics;

/** @type {boolean} Is a string key. Defines the need to download a key schema */
this.isStringRegistryKey = opts.isStringRegistryKey;

/** @type {boolean} Fetch all versions for each topic. */
this.fetchAllVersions = opts.fetchAllVersions;

Expand Down Expand Up @@ -246,10 +249,13 @@ SchemaRegistry.prototype._storeTopics = Promise.method(function (schemaTopics) {
*/
SchemaRegistry.prototype._processSelectedTopics = Promise.method(function () {
const topics = [];
const self = this;

this.selectedTopics.forEach(function (selectedTopic) {
topics.push(selectedTopic + '-value');
topics.push(selectedTopic + '-key');
if (!self.isStringRegistryKey) {
topics.push(selectedTopic + '-key');
}
});

return topics;
Expand Down Expand Up @@ -298,7 +304,6 @@ SchemaRegistry.prototype._fetchLatestVersion = Promise.method(function (schemaTo
.then((response) => {
log.debug('_fetchLatestVersion() :: Fetched latest topic version from url:',
fetchLatestVersionUrl);

return {
version: response.data.version,
schemaTopic: schemaTopic,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kafka-avro",
"version": "3.0.2",
"version": "3.0.3",
"main": "./lib/kafka-avro",
"description": "Node.js bindings for librdkafka with Avro schema serialization.",
"homepage": "https://github.com/waldophotos/kafka-avro",
Expand Down

0 comments on commit ee5fcaa

Please sign in to comment.