服务端接收并响应请求流程
provider处理请求流程
1 2 3 4 5 6 7 8 9 10 11 12
| - NettyServerWorker线程接收请求 - ByteToMessageDecoder.channelRead() - ByteToMessageDecoder.callDecode() - NettyCodecAdapter.InternalDecoder.decode() - DubboCountCodec.decode()解码 - fireChannelRead(ctx, out, size) - NettyServerHandler.channelRead() - AbstractPeer.received() - MultiMessageHandler.received() - HeartbeatHandler.received() - AllChannelHandler.received() - cexecutor.execute(new ChannelEventRunnable())// 请求派发到线程池处理,逻辑在ChannelEventRunnable.run()里
|
AllChannelHandler.received()方法中:
1
| cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message));
|
会将请求交给 ChannelEventRunnable 进行处理,后续在 DubboServerHandler 线程池里的调用逻辑:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| - provider处理请求流程 - ChannelEventRunnable.run()通道事件,判断RECEIVED事件进行处理 - DecodeHandler.received()解码处理器 - HeaderExchangeHandler.received()基于消息头的处理 - 1.HeaderExchangeHandler.handleRequest()处理请求 - DubboProtocol.requestHandler.reply() - 1.从exporterMap(服务暴露时创建的)中获取对应的invoker对象 - 2.invoker.invoke() - 经过各个filter.invoke() - InvokerWrapper.invoke() - AbstractProxyInvoker.invoke()中 - 1.doInvoke(methodName,paramType, arguments) - JavassistProxyFactory.doInvoke() - com.alibaba.dubbo.demo.provider.DemoServiceImpl.sayHello() - DemoServiceImpl.sayHello() - 2.new RpcResult()上一步的返回结果包装成RpcResult返回,后续处理原路返回 - 2.channel.send(response)响应请求 - // 参见 provider响应请求流程
|
provider请求响应流程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| - provider响应请求流程 - 各个filter的后续处理 - HeaderExchangeHandler.received()中处理请求时走handleRequest(),请求处理完后通过channel.send(response)响应 - AbstractPeer.send() - netty4/NettyChannel.send() - 响应线程NettyServerWorker-3-1 - Thread.run() - DefaultThreadFactory$DefaultRunnableDecorator.run() - SingleThreadEventExecutor.run() - NioEventLoop.run() - SingleThreadEventExecutor.runAllTasks() - // ... - AbstractChannelHandlerContext$WriteAndFlushTask.write() - NettyServerHandler.write() - AbstractPeer.sent() - AbstractChannelHandlerDelegate.sent() - HeartbeatHandler.sent()设置最后的写时间 - WrappedChannelHandler.sent() - AbstractChannelHandlerDelegate.sent() - HeaderExchangeHandler.sent()
|