Spring Cloud 数据流:注册新的自定义 kryo 序列化程序 [英] Spring Cloud dataflow: Register new custom kryo serializer

查看:52
本文介绍了Spring Cloud 数据流:注册新的自定义 kryo 序列化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用云数据流创建一个系统,我有一个源和一个转换器.我们喜欢使用 kryo,但是我们的一些类需要自定义 kryo 序列化器,我之前编写过序列化器.我们现在使用 spring-integration-core-4.3.11,并且从 4.2 开始,模型发生了变化(根据文档)以使用 Codecs 而不是 MessageConverter 接口.

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.

问题是,我如何在新的 Codec 框架中注册 kryo 序列化程序,我是否可以从 MessageCodec 继承一个新的 Codec 实现?我是否创建新的注册商实施?

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?

只要把实现变成一个 bean 就会被发现吗?我发现编解码器正在自动装配,但没有发现它们正在生产......

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

提前致谢!

推荐答案

参见 KryoCodecAutoConfiguration.

你可以用你自己的 bean 替换标准的 PojoCodec,或者简单地添加你的注册器(和任何其他需要的),SCSt 会将它们连接到默认的 PojoCodec....

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

这篇关于Spring Cloud 数据流:注册新的自定义 kryo 序列化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆