Spring Cloud dataflow: Register new custom kryo serializer

北战南征 提交于 2019-12-23 05:44:07

问题


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:


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();
}


来源:https://stackoverflow.com/questions/47424269/spring-cloud-dataflow-register-new-custom-kryo-serializer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!