question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Providing custom class as a DefaultValueSerDes giving an error

See original GitHub issue

Description We have made our consumer class where we are consuming messages from Kafka producer. We wanted to customize our Kafka stream by providing customized class in DefaultValueSerDes, which is not working and giving me error.

THIS IS MY PROGRAM.CS FILE ` // Stream configuration var config = new StreamConfig();

    config.ApplicationId = "app-testing";
    config.BootstrapServers = "localhost:9092";
    config.DefaultKeySerDes = new StringSerDes();
    config.DefaultValueSerDes = new ABC();

    StreamBuilder builder = new StreamBuilder();

    IKStream<string, ABC> str = builder.Stream<string, ABC>("test-input");
    str.Filter((k, v) => v.Data >= 25 && v.Data <= 50).To("test-output");

    Topology t = builder.Build();

    // Create a stream instance with topology and configuration
    KafkaStream stream = new KafkaStream(t, config);

    // Subscribe CTRL + C to quit stream application
    Console.CancelKeyPress += (o, e) =>
    {
        stream.Dispose();
    };

    // Start stream instance with cancellable token
    await stream.StartAsync();  `

THIS IS MY PROVIDED JSON TYPE IN KAFKA PRODUCER {“Name”: “DND”, “Data”: 37}

THIS IS MY CUSTOMIZED CLASS ABC.CS ` public class ABC : ISerDes { public string Name { get; set; } public int Data { get; set; }

    public object DeserializeObject(byte[] data, SerializationContext context)
    {
        var bytesAsString = Encoding.UTF8.GetString(data);
        return JsonConvert.DeserializeObject<ABC>(bytesAsString);
    }

    public void Initialize(SerDesContext context)
    {
        context.Config.BootstrapServers = "localhost:9092";
        context.Config.ApplicationId = "app-testing";
    }

    public byte[] SerializeObject(object data, SerializationContext context)
    {
        var a = JsonConvert.SerializeObject(data);
        return Encoding.UTF8.GetBytes(a);
    }
}`

THIS IS THE ERROR WE ARE RECEIVING kafka

How to reproduce

Checklist

Please provide the following information:

  • A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.
  • A code snippet with your topology builder (ex: builder.Stream<string, string>(“topic”).to(“an-another-topic”)😉
  • Streamiz.Kafka.Net nuget version.
  • Apache Kafka version.
  • Client configuration.
  • Operating system.
  • Provide logs (with in debug mode (log4net and StreamConfig.Debug) as necessary in configuration).
  • Critical issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LGouelleccommented, Oct 10, 2022

@Shikha4599

Perfect ! So I close this issue. If you have another question/issue, please open a new one.

1reaction
Shikha4599commented, Oct 10, 2022

Hi @Shikha4599,

Thanks for your issue.

Could you please test this implementation for ABC.cs :

    public class ABC : AbstractSerDes<ABC>
    {
        public string Name { get; set; }
        public int Data { get; set; }
        
        public override ABC Deserialize(byte[] data, SerializationContext context)
        {
            var bytesAsString = Encoding.UTF8.GetString(data);
            return JsonConvert.DeserializeObject<ABC>(bytesAsString);
        }

        public override byte[] Serialize(ABC data, SerializationContext context)
        {
            var a = JsonConvert.SerializeObject(data);
            return Encoding.UTF8.GetBytes(a);
        }
    }

This worked. Thankyou so much for the response @LGouellec

Read more comments on GitHub >

github_iconTop Results From Across the Web

Providing custom class as a DefaultValueSerDes giving an ...
We wanted to customize our Kafka stream by providing customized class in DefaultValueSerDes, which is not working and giving me error.
Read more >
python - Reasoning behind custom class Exception
I am learning Python and when I learned that we can build Custom classes for exception, I got into a confusion of Why...
Read more >
How to Define Custom Exception Classes in Python
The construction of custom exception classes can enrich our class design. A custom error class could logs errors, inspect an object.
Read more >
Game crashing when custom classes are used in a script
Hi, I've been working on a game in Godot 4 since beta but now I've stumbled across a very strange error. When I...
Read more >
ehmicky/error-custom-class: Create custom error classes
This package works in both Node.js >=16.17.0 and browsers. This is an ES module. It must be loaded using an import or import()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found