ah- / rdkafka-dotnet

C# Apache Kafka client
Other
242 stars 73 forks source link

does rdkafka support to push the Json string to the queue #100

Open ghost opened 7 years ago

ghost commented 7 years ago

Hello, I have a use case where i have push the Json string data to the queue. Is there a way to send the using this library?

thank you.

treziac commented 7 years ago

You can send anything you want - it's just a byte array, you have to serialize it first, and deserialize it when reading, like in the sample in the README

using (Producer producer = new Producer("127.0.0.1:9092"))
using (Topic topic = producer.Topic("testtopic"))
{
    byte[] data = Encoding.UTF8.GetBytes(YOUR_JSON_STRING);
    DeliveryReport deliveryReport = await topic.Produce(data);
    Console.WriteLine($"Produced to Partition: {deliveryReport.Partition}, Offset: {deliveryReport.Offset}");
}
ghost commented 7 years ago

@treziac , thank you. I was able to send the json string as you described. I have a requirement where i need push the raw messages in the queue as json. So my consumer can consume those messages.