We have a SpringBoot application that sends messages into multiple topics, each with a defined JSON Schema. I would like to reduce the boilerplate code so that we don't have to call setSchema
on the PulsarTemplate
instance when the defined type already has that information. Also, we could potentially remove the need to call .send
with topic name since it is known in advance and is static.
Doing this, we could reduce the code from:
@Autowired PulsarTemplate<Type1> template1;
@Autowired PulsarTemplate<Type2> template2;
void send1(...) {
template1.setSchema(Schema.JSON(Type1));
template1.send("topic-1", ...);
}
void send2(...) {
template2.setSchema(Schema.JSON(Type2));
template2.send("topic-2", ...);
}
to
@Autowired PulsarTemplate<Type1> template1;
@Autowired PulsarTemplate<Type2> template2;
void send1(...) {
template1.send(new Type1(...));
}
void send2(...) {
template2.send(new Type2(...));
}
I'm not finding a good solution and would like to know if there is way to do this or is my thinking is not in the right direction at all.
Thank you