Is it possible to send send a Java Object (lets say user) to a topic that is consumed and serialised to a User Object in C#?
Lets say I have the following avro schema built from a a Java PoJo (Fields are Name and Age)
{
"namespace": "io.confluent.developer",
"type": "record",
"name": "User",
"fields": [
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "age",
"type": [
"null",
"int"
],
"default": null
}
]
}
Which generates a User.class
Then sending it like so:
Service
@CommonsLog(topic = "Producer Logger")
@RequiredArgsConstructor
public class Producer {
@Value("${topic.name}")
private String TOPIC;
private final KafkaTemplate<String, User> kafkaTemplate;
void sendMessage(User user) {
this.kafkaTemplate.send(this.TOPIC, user.getName(), user);
log.info(String.format("Produced user -> %s", user));
}
}
I also have a Schema registry BUT I do not know how to consume the message in C# and deserialise it to a User class with the same fields:
public class Users
{
public int id = 0;
public string name = string.Empty;
public Users()
{
// Constructor Statements
}
public void GetUserDetails(int uid, string uname)
{
id = uid;
uname = name;
Console.WriteLine("Id: {0}, Name: {1}", id, name);
}
public int Designation { get; set; }
public string Location { get; set; }
}
Thanks for the help.
question from:
https://stackoverflow.com/questions/65847510/is-it-possible-to-send-a-java-object-to-c-sharp-app-using-kafka 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…