"cannot be cast to class" in a pulsar function producing un new message #19962
-
Hi all, I continue to explore pulsar. I'm trying to make a function that reroutes a message if a check fails. Here is how the function is defined:
Here is my code: public class PulsarFonctionPersonne implements Function<Personne, Personne> {
@Override
public Personne process(Personne personne, Context context) throws Exception {
Logger LOG = context.getLogger();
LOG.warn("TRACE 1 --> " + personne.getNom());
try {
new PersonneValidateur().valider(personne);
}
catch(VerificateurException e) {
LOG.warn("TRACE 2 --> " + e.getMessage());
context.newOutputMessage("public/poc-personne/personne-erreur", AvroSchema.of(Personne.class))
.value(personne)
.property("messageErreur", e.getMessage())
.send();
LOG.warn("TRACE 3");
}
return personne;
}
} But I get these messages in the log topic:
I never see "TRACE 3" log or my message in destination topic :-( I don't understand what I should do to avoid this "cannot be cast" error. Can you help me ? THANKS |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
No one to give me an explanation about the error when the function is called:
Thanks |
Beta Was this translation helpful? Give feedback.
-
This seems that the platform classloader is different to function classloader but they both load the cc @dlg99 @jiangpengcheng do you have ideas how we can configure the class loading strategy or user code to avoid such exception? |
Beta Was this translation helpful? Give feedback.
-
seems like you added the |
Beta Was this translation helpful? Give feedback.
-
Works perfectly using org.apache.pulsar.client.api.Schema.AVRO(Personne.class) Thanks |
Beta Was this translation helpful? Give feedback.
@raymondBourges
seems like you added the
pulsar-client
dependency in your function, you can try withSchema.Avro(Personne.class)
instead of theAvroSchema.of(Personne.class)
and remove thepulsar-client
dependency