Customising XStreamSerliazer

Hi,

We use the Axon SpringAMQP event bus, we have multiple applications which use Axon that communicate with each other via the event bus.

Tt often happens that the Event classes, lie in different packages in each of the applications, this results in a failure to deserialise while subscribing to the event.

A suggestion in one the earlier posts was to use something like the below

xStreamSerializer**.addPackageAlias(“patientadministration”,“com.patientadministration.domain”);**

But i am wondering how to configure this ?, can this be configured via Spring XML ?

or will I need to pull the xStreamSerializer instance out of the spring context and then configure this in ?

Thanks
Sudarshan

I think the typical answer for this is to move these event definitions out to a common sub-project that the other projects depend on; thus they all use the events in the same package. This subproject removes the duplication of event definitions, and defines the common “vocabulary” by which all the projects/applications interact. (Of course there are problems to solve, particularly around versioning.)

I totally agree with Kyle.
However, using package aliases typically makes sense, since an application’s “base package” is often something in the sense of com.mycompany.mydepartment.myapp.somesubdomain. In the Event XML is often suffices to mention “mysubdomain.MyEvent”. You can create an alias for com.mycompany.mydepartment.myapp.somesubdomain => somesubdomain. It will make the serialized form of events smaller.

In Spring (4 for sure and perhaps it also works in 3), the easiest way to configure the XStreamSerializer is to use JavaConfig to define the serializer bean (using @Configuration and @Bean). XML configuration is rather limited when it comes to customization.

Cheers,

Allard

Thanks, the suggestion to use JavaConfig rather than XML did the trick !!