I’m currently using generated Avro objects to send some of my events in my application, so I had to configure this default serializer:
less
Copiar código
@Bean
@Primary
public Serializer defaultSerializer() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.addMixIn(Object.class, JacksonIgnoreAvroPropertiesMixIn.class);
return JacksonSerializer.builder().objectMapper(objectMapper).build();
}
But when I try to send those events, the @EventSourcingHandler works normally, but the @EventHandler doesn’t (it doesn’t throw any exception or log anything at the debug level). What can I do to use Avro objects as my events?
You have a generated java class (via apache-avro-maven-plugin), you have an instance (via newBuilder()) of that class and you serialize it via jackson/json?
However, the event handler is not being triggered. When using standard Java classes, it works fine, but with Avro, it doesn’t. I tried using JacksonAvroModule, but the issue persists.
The apply is for the write model, not for the read model. I’m not really sure what you want to do here. Is the apply part of the aggregate? Or do you just want to add an event to the store? In the latter case you should use a publish on een event store instead. I don’t think currently the event is persistent. Hence the event handler is never triggered.
What I’m trying to do is have my aggregate apply this event to itself, so that my @EventSourcingHandler handles the event, and my @EventHandler handles the same event. It worked before I started using Avro objects. The @EventSourcingHandler is working, but my @EventHandler on my projector isn’t.
I would expect at least something logged. For now it’s still unclear if the event is persisted at all, so if it’s an error storing the event, or if there is an error reading the event. I also fail to understand why Jackson should be involved, and why you wouldn’t just use the class name, and then use from bytebuffer directly. But that’s likely to prevent having to add all the classes explicitly to the serializer? If you use that method on the stored bytes through, does it work?