问题
I extended AbstractByteArraySerializer
and now I want to use this serializer like the rest of the available TCP serializers (LF, NULL, L1, ...).
I found the profiles in tcp-encdec.xml
and registered my own profile:
...
<beans profile="use-custom">
<bean id="CUSTOM"
class="custom.tcp.serializer.ByteArrayCustomSerializer">
<property name="maxMessageSize" value="${bufferSize}" />
</bean>
</beans>
...
Spring uses EncoderDecoderMixins.Encoding
to convert Encoding
to a specific profile.
EncoderDecoderMixins.Encoding
is an enum in a final class. Spring converts the decoder
TCP property to a specific profile based on this enum. My CUSTOM serializer won't work since it isn't in the specified Encodings
.
Is there a way to register a new Encoding
or do I have to write a new Source module to use my serializer?
回答1:
Unfortunately, you will need a custom source; we could probably add another enumeration, such as CUSTOM
, where you provide the classname of the deserializer but that will need a change to the standard source.
A quick and dirty work-around would be to modify the source locally:
<int-ip:tcp-connection-factory id="connectionFactory"
...
deserializer="myDeserializer"/>
<bean id="myDeserializer" class="foo.Deser" />
i.e. change the ${decoder}
placeholder to point to your bean.
来源:https://stackoverflow.com/questions/35554870/spring-xd-using-custom-tcp-serializer