【问题标题】:Spring XD Using custom TCP serializerSpring XD 使用自定义 TCP 序列化程序
【发布时间】:2016-02-22 13:24:38
【问题描述】:

我扩展了AbstractByteArraySerializer,现在我想像其他可用的 TCP 序列化器(LF、NULL、L1、...)一样使用这个序列化器。

我在tcp-encdec.xml 中找到了个人资料并注册了自己的个人资料:

...

<beans profile="use-custom">
    <bean id="CUSTOM"
        class="custom.tcp.serializer.ByteArrayCustomSerializer">
        <property name="maxMessageSize" value="${bufferSize}" />
    </bean>
</beans>

...

Spring 使用 EncoderDecoderMixins.EncodingEncoding 转换为特定配置文件。

EncoderDecoderMixins.Encoding 是最终类中的枚举。 Spring 将decoder TCP 属性转换为基于此枚举的特定配置文件。我的 CUSTOM 序列化程序无法工作,因为它不在指定的 Encodings 中。

有没有办法注册一个新的Encoding 或者我必须编写一个新的源模块才能使用我的序列化器?

【问题讨论】:

    标签: java spring tcp spring-xd


    【解决方案1】:

    很遗憾,您需要自定义来源;我们可能会添加另一个枚举,例如CUSTOM,您可以在其中提供反序列化器的类名,但这需要更改标准源代码。

    一种快速而肮脏的解决方法是在本地修改源代码:

    <int-ip:tcp-connection-factory id="connectionFactory"
        ...
        deserializer="myDeserializer"/>
    
    <bean id="myDeserializer" class="foo.Deser" />
    

    即将 ${decoder} 占位符更改为指向您的 bean。

    【讨论】:

    • 感谢您的快速回复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 2013-09-09
    • 2013-03-09
    • 2022-07-21
    相关资源
    最近更新 更多