0
votes

What would be the easiest way to implement GZIP compression decorators on JacksonSerializer for Events and Messages in Axon? I'm trying to GZIP JSON messages before saving events to MySQL as BLOB.

I tried implementing decorator like this:

public class GzipSerializer implements Serializer {

  private Serializer serializer;
  ...

and then configuring it using:

  @Autowired
  public void serializerConfiguration(Configurer configurer) {
    Serializer defaultSerializer = new GzipSerializer(JacksonSerializer.defaultSerializer());
    configurer.configureSerializer(configuration -> defaultSerializer)
        .configureMessageSerializer(configuration -> defaultSerializer)
        .configureEventSerializer(configuration -> defaultSerializer);
  }

but it does not seem to work. Is there maybe some easier way (or possibly already implemented functionality)?

2

2 Answers

3
votes

it seems that you're using Spring (Boot?) to wire your application. In that case, the way to define/override the serializers is by declaring beans:

@Primary  // <-- Use the Primary annotation for the generic serializer. This makes sure spring returns this instance when no specific qualifier is provided
@Bean
public Serializer serializer() {
  return new GzipSerializer(....);
}

We recommend using the Jackson based serializer only for messages, as some other object structures don't match Jackson's expectations. Aggregates (for snapshots) and Sagas, for example, are unlikely to meet these expectations.

You can define a serializer for messages as follows:

@Qualifier("messageSerializer") // <-- this qualifier tells Axon you intend to use this to serialize messages (incl. events)
@Bean
public Serializer serializer() {
  return new GzipSerializer(....);
}
0
votes

In Spring boot, you can use the configuration properties for that like below without java code.

axon:
  serializer:
    messages: jackson
    general: jackson
    events: jackson