2

在 Apache Ignite 中插入自定义序列化程序

我试图在 Binary Configuration bean 中添加 Kyro Serializer,但在运行时它给了我一个类类型转换错误。

我的代码是

 <property name="binaryConfiguration">
            <bean class="org.apache.ignite.configuration.BinaryConfiguration">
                <property name="typeConfigurations">
                    <list>
                        <bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
                            <property name="typeName" value="testPojo" />
                            <property name="serializer">
                                <bean class="com.esotericsoftware.kryo.serializers.DefaultSerializers" />
                            </property>
                        </bean>
                    </list>
                </property>
            </bean>
        </property>

错误日志是

Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.esotericsoftware.kryo.serializers.DefaultSerializers] to required type [org.apache.ignite.binary.BinarySerializer] for property 'serializer': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:302)
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
    ... 104 more

在挖掘 Apache Ignite 提供的 BinarySerializer 时,得出的结论是,必须为序列化器编写自定义实现作为其他插件序列化器来实现它。

Optimized Marshaller 有什么好处?

4

1 回答 1

4

BinarySerializer是一个接口,可以实现为特定类型定制(反)序列化逻辑。这类似于Externalizablefor BinaryMarshaller,它是自 Ignite 1.5 以来的默认编组器。有关详细信息,请参阅此页面:https ://apacheignite.readme.io/docs/binary-marshaller

OptimizedMarshaller实现传统的序列化协议,该协议在引入二进制格式之前使用。它仍然可用,但建议使用二进制格式。

您还可以实现自己的编组器(例如,基于 Kryo)。为此,请实现Marshaller接口并通过IgniteConfiguration.setMarshaller()属性在配置中提供此实现。

于 2016-03-02T19:05:41.610 回答