[英]Spring Integration : No publisher available to publish TCP Connection related events
我正在使用 Spring 與 Spring 引導集成。 我有一個帶有 TcpOutboundGateway 設置的 TCP 客戶端 [TcpNetClientConnectionFactory]。 我可以在生產中看到以下警告[沒有可發布的發布者]。
根據我的檢查,當 org.springframework.context.ApplicationEventPublisher 為 null 時會顯示此警告。
代碼:
@Bean
@ServiceActivator(inputChannel = "a04A08OutgoingChannel")
public MessageHandler a04A08OutgoingGate() {
final TcpOutboundGateway gate = new TcpOutboundGateway();
// Connection configured in client mode to send the message over the TCP socket
// and wait for acknowledgement
gate.setConnectionFactory(connectionFactory.connectionFactory(host, port));
gate.setReplyChannelName("a04A08ReplyToString");
gate.setRemoteTimeout(60_000);
return gate;
}
@Transformer(inputChannel = "a04A08ReplyToString")
public String transform(byte[] bytes) {
String reply = new String(bytes);
log.debug("transform - a04A08ReplyToString channel " + reply);
return new String(bytes);
}
public String outgoingMessage(String message) {
String reply = null;
log.info("Message being Sent : " + message);
try {
// Send the message to the TCP socket and wait for acknowledgement
reply = a04a08OutgoingGateway.sendMessage(message);
} catch (ConnectException e) {
log.error(e.getMessage(),e);
}
log.info("Acknowledgement received : " + reply);
return reply;
}
ConnectionFactory.java:
public AbstractClientConnectionFactory connectionFactory(String host, int port) {
final AbstractClientConnectionFactory connectionFactory = new TcpNetClientConnectionFactory(host, port);
connectionFactory.setSerializer(customDeserializer);
connectionFactory.setDeserializer(customDeserializer);
//connectionFactory.setSoKeepAlive(true);
connectionFactory.setSingleUse(true);// This property when set to false ensures that one shared connection is used for all
// request/replies and each caller blocks waiting for the socket
return connectionFactory;
}
編輯 1:包括 CustomDeserializer.java
@Override
public void serialize(String object, OutputStream outputStream) throws IOException {
log.info("[Serialize] Serializing data : length ==> " + object.length());
outputStream.write(object.getBytes());
log.info("[Serialize] data posted to stream");
}
@Override
public byte[] deserialize(InputStream inputStream) throws IOException {
log.info("[Deserialize] De-Serializing data");
BufferedReader input = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer stringbuffer = new StringBuffer();
while (true) {
int value = input.read();
if (value == 28) {
break;
} else {
if (value != -1) {
stringbuffer.append((char) value + "");
} else {
break;
}
}
}
log.info("[deserialize.readFromSocket()]: " + stringbuffer.toString());
return stringbuffer.toString().getBytes();
}
TCP服務器能夠接收到TCP客戶端發送的消息。 [注意:TCP 服務器是不同的系統,不是我們維護的]。我有 2 個查詢。
這個警告會有影響嗎? 任何人都可以詳細說明警告嗎? 即使看到警告,來自 TCP 客戶端的消息也會毫無問題地發送到 TCP 服務器。
我們最近在生產中遇到了以下問題(由:org.springframework.messaging.MessagingException:等待回復時出現異常;嵌套異常是 java.net.SocketTimeoutException:讀取超時)。 當我們遇到以下異常時,可以遠程登錄到服務器端口,但服務器沒有收到消息。 重啟 TCP 服務器后問題自動解決。 我的問題:這個問題是否與第 1 點中的警告有關。 即使在正常情況下將消息發送到服務器而沒有任何問題,也會看到這些警告。
PS:我還檢查了帖子: 沒有發布者可用於發布 TcpConnectionOpenEvent / TcpConnectionCloseEvent
不相關; 如果重新啟動它可以解決它,聽起來像是服務器問題。
連接工廠必須聲明為@Bean
,以便 spring 可以注入事件發布者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.