websocket服务部署出现的问题记录
2022-09-05 本文已影响0人
天草二十六_简村人
一、程序报错
1.1、通道服务本身的报错
- java.io.IOException: Connection reset by peer
2022-09-05 16:53:36.673 ERROR [channel-service,,,] 9 --- [ecutorGroup-7-4] c.x.w.c.n.handler.NettyServerHandler : exceptionCaught
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
1.2、通道服务客户端的报错
- WebsocketNotConnectedException
org.java_websocket.exceptions.WebsocketNotConnectedException: null
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:628)
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:605)
at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:410)
at com.xx.crplatform.application.service.impl.BaseSocketServiceImpl.send(BaseSocketServiceImpl.java:83)
at com.xx.crplatform.application.service.impl.BaseSocketServiceImpl.send(BaseSocketServiceImpl.java:58)
二、访问方式
注意,通道的tcp端口号是8889,无论是内网还是外网,访问的端口都必须8889。
- 内网地址
示例:ws://10.xx.xx.89:8889 - 外网地址
示例:ws://47.xx.xx.197:8889
三、k8s容器的配置
访问方式.png这里需要额外新增两项访问。
而普通的服务只需要像下面这样配置。
jvm端口映射.png
四、遇到的其他问题
4.1、内网域名解析不通的错误
内网地址配置为ws://xxx.inner.com,再通过nginx做监听80端口,反向代理到内网SLB地址(10.xxx.xx.89:8889);
经验证,telnet xxx.inner.com 不通。
最后还是配置内网SLB地址:ws://10.xxx.xx.89:8889,验证才通过。