环境 jectd 版本 0.5
etcd 版本 3.4
本人泥腿子 java 对于使用第三方包,假如是第三方包抛出异常,是不是没办法捕获解决。
如果我手动关闭 etcd 服务端,就会这样,这个异常是 jetcd 包里抛出的
00:22:31.569 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - Watching for key=a
00:22:31.577 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=24444
00:22:58.621 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND DATA: streamId=3 padding=0 endStream=false length=52 bytes=000000002f0a1a08b298eaf1948386fccd0110cdd2918bd2b881cf8e01181120035a11120f0a01611010181120022a0433333333
00:22:58.622 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - Watching for key=a
00:22:58.622 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=3333
00:23:23.851 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND GO_AWAY: lastStreamId=2147483647 errorCode=0 length=0 bytes=
00:23:23.856 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND PING: ack=false bytes=73747577769755401
00:23:23.856 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] OUTBOUND PING: ack=true bytes=73747577769755401
00:23:23.857 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] OUTBOUND GO_AWAY: lastStreamId=0 errorCode=2 length=24 bytes=436f6e6e656374696f6e2072657365742062792070656572
00:23:23.861 [grpc-nio-worker-ELG-1-2] DEBUG io.netty.handler.codec.http2.Http2ConnectionHandler - [id: 0x138691d4, L:/127.0.0.1:58759 ! R:/127.0.0.1:2379] Sending GOAWAY failed: lastStreamId '0', errorCode '2', debugData 'Connection reset by peer'. Forcing shutdown of the connection.
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.writev0(Native Method)
at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:51)
at sun.nio.ch.IOUtil.write(IOUtil.java:148)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:504)
at io.netty.channel.socket.nio.NioSocketChannel.doWrite(NioSocketChannel.java:423)
然后我重启 etcd 服务端,继续 put key 还是能继续 watch 到的:
00:23:50.692 [grpc-nio-worker-ELG-1-3] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x56feb4a4, L:/127.0.0.1:58801 - R:/127.0.0.1:2379] INBOUND DATA: streamId=3 padding=0 endStream=false length=71 bytes=00000000420a1a08b298eaf1948386fccd0110cdd2918bd2b881cf8e01181320045a11120f0a01611010181220032a04333333335a11120f0a01611010181320...
00:23:50.692 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - Watching for key=a
00:23:50.693 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=3333
00:23:50.693 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=4444
假如我在线上要用这个 java 的 etcd 客户端,我肯定起个线程来 watch,但是问题来了,假如 etcd 挂了 抛出了这个异常 然后这个异常导致线程退出,我难道还要线程退出的时候重新开始 watch 吗,这样感觉就麻烦了。话说面对这样的情况 该如何优雅的解决,诚心请教各位大佬了
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.