gpt4 book ai didi

java - 无法在带有未定义终止符的 channel 上接收 tcp(模式为服务器)消息

转载 作者:行者123 更新时间:2023-12-02 02:30:01 29 4
gpt4 key购买 nike

目前我们在我们的应用程序中使用 Spring Integration 2.1.0 版本(由于遗留应用程序无法切换到最新版本)。申请流程如下:

  1. 所有配置详细信息都在配置文件中定义,例如主机名、端口号、终止符等
  2. 使用 tcp-inbound-channel-adapter 通过 channel 从 TCP 获取消息。
  3. 将其传递到分离器以进一步流动。

这里的问题是,如果消息具有配置文件中定义的终止符以外的终止符,则消息不会到达为拆分器定义的类,如果终止符相同,则工作正常。要求是如果终止符值不同,则应使用 tcp-outbound-channel-adapter 在同一 channel 上显示错误消息(由于异步调用而使用入站和出站)。 我已在跟踪级别启用应用程序和 spring 日志记录,但无法理解消息被卡住的原因和位置。

配置文件的代码是

<Config>
<host>localhost</host>
<port>8888</port>
<mode>server</mode>
<terminator>10</terminator>
<msgLength>65535</msgLength>
<inChannel>telnetInboundCustomChannel</inChannel>
</Config>

连接详细信息的 XML

<beans:bean id="serverCustomSerializer"
class="com.core.serializer.CustomSerializer">
<beans:property name="terminatingChar" value="${server.terminator}"/>
<beans:property name="maxLength" value="${server.msgLength}"/>
</beans:bean>

<beans:bean id="serverFactoryTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<beans:property name="corePoolSize" value="5" />
<beans:property name="queueCapacity" value="0" />

</beans:bean
<int:channel id="telnetLandingChannel" />
<ip:tcp-connection-factory id="serverFactory" type="server"
host="${server.host}" port="${server.port}" single-use="false"
serializer="${server.serializer}" deserializer="${server.serializer}" task-
executor="serverFactoryTaskExecutor"/>

<ip:tcp-inbound-channel-adapter id="serverInboundAdpater"
channel="telnetLandingChannel" connection-factory="serverFactory"
error-channel="errorChannel" auto-startup="false"/>
<ip:tcp-outbound-channel-adapter id="serverOutboundAdapter"
channel="serverReplyChannel"
connection-factory="serverFactory"
auto-startup="true"/>

channel 详细信息和流程的 XML 为:

<int:channel id="telnetInboundCustomChannel" />

<int:splitter id="messageSplitter"
input-channel="telnetInboundCustomChannel" ref="telnetCustomMessageSplitter"
method="splitCustomMessageStream"
outputchannel="base24CustomSplitterChannel" />

<int:filter id="messageFilter" input-
channel="base24CustomSplitterChannel"
output-channel="base24CustomCoreMessageChannel"
ref="telnetCustomMessageFilter"
method="customMessageFilter" />
<!--Other code to get data from filer and pass it to correct router -->

如果某种消息在过滤器类中可见,我可以将逻辑应用于 TCP 连接上的写入错误代码。我也在 TcpNetConnection 类的 run() 上应用了断点。我无法理解 Spring Integration 的内部流程。消息如何到达,甚至直到分离器。我还注意到一件事,如果我发送带有正确终止符的消息,在发送带有错误终止符的消息后,Spring 将在旧消息中附加新消息。

看起来如果没有正确的终止符, Spring 将无法剪切框架,并且卡在 telnetInboundCustomChannel 中。请指导如何解决此问题以及问题原因,以便更好地理解。

最佳答案

目前尚不清楚如何检测不良终止符。根据定义,反序列化器需要在返回之前知道消息是否完整。您可以检测套接字关闭(bite < 0)和 n>0 并返回一条特殊消息,但我不知道您还能如何发出消息,除非您知道要查找哪些无效终止符。

编辑

如果您的意思是检查另一个“特殊”(不可打印)字符,那么您可以使用类似...

if (n > 0 && (bite == bytes.byteValue())) {
break;
}
else (if bite < 0x20) {
return ("Bad terminator for" + new String(buffer, 0, n)).getBytes();
}

关于java - 无法在带有未定义终止符的 channel 上接收 tcp(模式为服务器)消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47251724/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com