Skip to content

[feature request] Improvements for Avro messages producing #195

@eshepelyuk

Description

@eshepelyuk

Hello this is a follow up to #181

Since basic functionality now working, let me start from the beginning and provide more complicated examples.
Yet again I am comparing with similar functionality in AKHQ UI

Use case with errors

  1. The schema
{
  "name": "CreateUserProfileWallet",
  "namespace": "Messaging.Contracts.WalletManager.Commands",
  "type": "record",
  "fields": [
    { "name": "CurrencyCode", "type": "string" },
    { "name": "ExpiresOn", "type": ["null", "string"] }
  ]
}
  1. First JSON, where ExpiresOn = null
    { 
      "CurrencyCode": "EUR" 
    }
    kaf invocation and the output
    cat create.null.json | kaf produce --avro-schema-id 29 --input-mode full create_user_profile_wallet
    Failed to encode avro
    %!(EXTRA *errors.errorString=cannot decode textual record 
    "Messaging.Contracts.WalletManager.Commands.CreateUserProfileWallet": only found 1 of 2 fields)
    
  2. Second JSON, where ExpiresOn != null
    {
      "CurrencyCode": "EUR",
      "ExpiresOn": "2022-12-12"
    }
    kaf invocation and the output
    cat create.json | kaf produce --avro-schema-id 29 --input-mode full create_user_profile_wallet
    Failed to encode avro
    %!(EXTRA *errors.errorString=cannot decode textual record 
    "Messaging.Contracts.WalletManager.Commands.CreateUserProfileWallet": cannot decode textual union: expected: '{'; actual: '"')
    

So, the messages are not working with kaf but those files are valid Avro JSON messages and can be sent to a topic using some other tools, e.g. AKHQ.

Existing solution

To overcome a problem - JSON files must be changed to some unfriendly format.

  1. First JSON, where ExpiresOn == null
    {
      "CurrencyCode": "EUR",
      "ExpiresOn": {
        "null": null
      }
    }
  2. Second JSON, where ExpiresOn != null
    {
      "CurrencyCode": "EUR",
      "ExpiresOn": {
       "string": "2022-12-12"
     }
    }    

Improvement request

As a user I'd like kaf to be able to handle plain JSON (as described in the Use case section) for producing Avro encoded message. Without need to convert my plain JSON data to that weird format.

Currently this is working for some other tools, e.g. AKHQ UI, but it is missing for CLI based tools.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions