简体   繁体   English

Spring Cloud数据流:注册新的自定义Kryo序列化器

[英]Spring Cloud dataflow: Register new custom kryo serializer

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. 我们喜欢使用kryo,但是我们的某些类需要自定义kryo序列化程序,我之前已经编写了序列化程序。 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. 我们现在使用spring-integration-core-4.3.11,从4.2开始,该模型已更改(根据文档),以使用编解码器而不是MessageConverter接口。

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? 问题是,如何在新的Codec框架中注册kryo序列化程序,我是否要继承自MessageCodec的新Codec实现? Do I create a new Registrar implementation? 是否创建新的注册服务商实施?

Just making the implementation a bean would it be discovered? 只是将实现变成bean会被发现吗? I found Codec being Autowired, but nowhere found them being produced.... 我发现编解码器正在自动接线,但无处发现它们正在生产...。

thanks in advance! 提前致谢!

See KryoCodecAutoConfiguration . 参见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替换标准的PojoCodec ,也可以简单地添加您的注册器(以及任何其他需要的),SCSt会将它们连接到默认的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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM