diff --git a/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/RpcChannel.java b/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/RpcChannel.java index 7a35144..8a65f1b 100644 --- a/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/RpcChannel.java +++ b/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/RpcChannel.java @@ -22,8 +22,10 @@ import org.slf4j.LoggerFactory; import com.baidu.jprotobuf.pbrpc.data.RpcDataPackage; +import com.baidu.jprotobuf.pbrpc.transport.handler.ErrorCodes; import io.netty.channel.Channel; +import io.netty.channel.ChannelFutureListener; import io.netty.util.Timeout; /** @@ -138,7 +140,11 @@ public void doTransport(Connection connection, RpcDataPackage rpcDataPackage, LOG.debug("Do send request with service name '" + rpcDataPackage.serviceName() + "' method name '" + rpcDataPackage.methodName() + "' bound channel =>" + channel); - channel.writeAndFlush(state.getDataPackage()); + channel.writeAndFlush(state.getDataPackage()).addListener((ChannelFutureListener) channelFuture -> { + if (!channelFuture.isSuccess() && channelFuture.cause() != null) { + state.handleFailure(ErrorCodes.ST_WRITE_FAILED, channelFuture.cause().getMessage()); + } + }); } long callMethodEnd = System.currentTimeMillis(); diff --git a/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/ErrorCodes.java b/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/ErrorCodes.java index 60ee602..fed3318 100644 --- a/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/ErrorCodes.java +++ b/jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/ErrorCodes.java @@ -36,6 +36,9 @@ public class ErrorCodes { /** read time out. */ public static final int ST_READ_TIMEOUT = 62; + /** 消息发送异常. */ + public static final int ST_WRITE_FAILED = 4001; + /** onceTalkTimeout timeout message. */ public static final String MSG_READ_TIMEOUT = "method request time out, please check 'onceTalkTimeout' property. current value is:";