Spring Cloud dataflow: Register new custom kryo se

2019-06-08 20:06发布

I am creating a system using cloud-dataflow, I have a source and a transformer. We like to use kryo, but some of our classes require custom kryo serializers, I have written serializers before. We are now using spring-integration-core-4.3.11, and since 4.2 the model has changes(per the docs) to use Codecs instead of MessageConverter interface.

The question is, how can I register the kryo serializers in the new Codec framework, do I make a new Codec implementation inheriting from MessageCodec? Do I create a new Registrar implementation?

Just making the implementation a bean would it be discovered? I found Codec being Autowired, but nowhere found them being produced....

thanks in advance!

1条回答
Animai°情兽
2楼-- · 2019-06-08 20:56

See KryoCodecAutoConfiguration.

You can either replace the standard PojoCodec with your own bean, or simply add your registrar (and any others needed) and SCSt will wire them into the default PojoCodec....

@Bean
@ConditionalOnMissingBean(PojoCodec.class)
public PojoCodec codec() {
    Map<String, KryoRegistrar> kryoRegistrarMap = applicationContext.getBeansOfType(KryoRegistrar.class);
    return new PojoCodec(new ArrayList<>(kryoRegistrarMap.values()), kryoCodecProperties.isReferences());
}

@Bean
@ConditionalOnMissingBean(KryoRegistrar.class)
public KryoRegistrar fileRegistrar() {
    return new FileKryoRegistrar();
}
查看更多
登录 后发表回答