Event namings

Hi,
axon newbie question that I cannot find answer to.

I see in axon server that the PayloadData and the payloadType is the full class name.
This is similar to hibernate’s strategy. The possible problem whit that is that new service might want to put their event in som other structure.

Is there any way to annotate the events to give them a more generic name?

Cheers,
Fredrik

Hi Fredrik,

Axon requires the payload type to be able to deserialize the events payload from storage.

As the payload resembles an actual class, the fully qualified class name is needed.
However, there are option to use some form of aliasing, so that you could store shorter payload types than the fully qualified class name.

For that, you need to customize the Serializer you’re using.

If you’re using the XStreamSerializer, you can leverage the addAlias(String, Class) function to add the aliases you want for your messages.

If you’re using the JacksonSerializer (typically suggested to be used for events), you’ll have to extend from the original serializer and override the resolveClassName(SerializedType) to have more control over how your class names are stored in the payload type field.

I hope this gives you the necessary background Fredrik!

Cheers,
Steven

So that is exactly what I was looking for. Thank you for that.

Might I also suggest adding a simple annotation (easy to do yourself of course but for completeness)
@Event(type=“XXX”), when left out the it would work like today as default

This would make it much clearer when moving from one service to another. Otherwise you potentially have to implement/override the serializers for all your services. It is the same case as for hibernate :slight_smile:

Thanks so much for the quick answer
Cheers, Fredrik

Hi Fredrik,

Thanks for the suggestion, that’s always welcome.
I forgot to mention in my previous response that it’s already on the issue tracker to be discussed, as can be seen here.

I thought you might be interested, so that you could eventually keep track when it’s resolved.

Cheers,
Steven