RpcServiceContext上下文

22 篇文章 0 订阅
18 篇文章 1 订阅

消费者: web 

提供者: buss-service

同一服务器: 192.168.100.228

视角: buss-service

RpcServiceContext serviceContext = RpcContext.getServiceContext();
//web->buss-service

LOGGER.warn("getRequest->{}", JsonUtil.toJson(serviceContext.getRequest()));
//getRequest->null
LOGGER.warn("getResponse->{}", JsonUtil.toJson(serviceContext.getResponse()));
//getResponse->null
LOGGER.warn("get->{}", JsonUtil.toJson(serviceContext.get()));
//get->{}
LOGGER.warn("getAttachments->{}", JsonUtil.toJson(serviceContext.getAttachments()));
//getAttachments->{"traceId":"aaef470a3a164379b4f12517f743f5d6","input":"392","remote.application":"web"}
LOGGER.warn("getInterfaceName->{}", JsonUtil.toJson(serviceContext.getInterfaceName()));
//getInterfaceName->null
LOGGER.warn("getLocalAddressString->{}", JsonUtil.toJson(serviceContext.getLocalAddressString()));
//getLocalAddressString->192.168.100.228:21000
LOGGER.warn("getLocalHost->{}", JsonUtil.toJson(serviceContext.getLocalHost()));
//getLocalHost->192.168.100.228
LOGGER.warn("getLocalHostName->{}", JsonUtil.toJson(serviceContext.getLocalHostName()));
//getLocalHostName->192.168.100.228
LOGGER.warn("getLocalPort->{}", JsonUtil.toJson(serviceContext.getLocalPort()));
//getLocalPort->21000
LOGGER.warn("getMethodName->{}", JsonUtil.toJson(serviceContext.getMethodName()));
//getMethodName->test
LOGGER.warn("getObjectAttachments->{}", JsonUtil.toJson(serviceContext.getObjectAttachments()));
//getObjectAttachments->{"traceId":"aaef470a3a164379b4f12517f743f5d6","input":"392","remote.application":"web"}
LOGGER.warn("getRemoteAddressString->{}", JsonUtil.toJson(serviceContext.getRemoteAddressString()));
//getRemoteAddressString->192.168.100.228:36992
LOGGER.warn("getRemoteApplicationName->{}", JsonUtil.toJson(serviceContext.getRemoteApplicationName()));
//getRemoteApplicationName->web
LOGGER.warn("getRemoteHost->{}", JsonUtil.toJson(serviceContext.getRemoteHost()));
//getRemoteHost->192.168.100.228
LOGGER.warn("getRemoteHostName->{}", JsonUtil.toJson(serviceContext.getRemoteHostName()));
//getRemoteHostName->saas-network-01
LOGGER.warn("getRemotePort->{}", JsonUtil.toJson(serviceContext.getRemotePort()));
//getRemotePort->36992
URL url = serviceContext.getUrl();
if(url != null) {
	LOGGER.warn("getAbsolutePath->{}", JsonUtil.toJson(url.getAbsolutePath()));
    //getAbsolutePath->/com.myb.wh.buss.service.base.FileService
	LOGGER.warn("getAddress->{}", JsonUtil.toJson(url.getAddress()));
    //getAddress->192.168.100.228:21000
	LOGGER.warn("getAllParameters->{}", JsonUtil.toJson(url.getAllParameters()));
    //getAllParameters->{"release":"3.1.0","dubbo":"2.0.2","interface":"com.myb.wh.buss.service.base.FileService","application":"buss-service","anyhost":"true","pid":"3178994","side":"provider","metadata-type":"remote","methods":"copyFile,deleteFile,getUploadParam,deleteFolder,test,upload,html2Jpg,getFilesByDirectory,ofd2Pdf,jpg2Pdf,batchDeleteFile,html2Pdf,watermarkDIY","logger":"slf4j","deprecated":"false","service-name-mapping":"true","qos.enable":"false","timeout":"10000","bind.port":"21000","register-mode":"instance","generic":"false","bind.ip":"192.168.100.228","payload":"8388608","background":"false","dynamic":"true","service.filter":"dubboExceptionFilter,-exception","dispatcher":"message","qos.accept.foreign.ip":"false","timestamp":"1700834530470"}
	LOGGER.warn("getParameters->{}", JsonUtil.toJson(url.getParameters()));
    //getParameters->{"release":"3.1.0","dubbo":"2.0.2","interface":"com.myb.wh.buss.service.base.FileService","application":"buss-service","anyhost":"true","pid":"3178994","side":"provider","metadata-type":"remote","methods":"copyFile,deleteFile,getUploadParam,deleteFolder,test,upload,html2Jpg,getFilesByDirectory,ofd2Pdf,jpg2Pdf,batchDeleteFile,html2Pdf,watermarkDIY","logger":"slf4j","deprecated":"false","service-name-mapping":"true","qos.enable":"false","timeout":"10000","bind.port":"21000","register-mode":"instance","generic":"false","bind.ip":"192.168.100.228","payload":"8388608","background":"false","dynamic":"true","service.filter":"dubboExceptionFilter,-exception","dispatcher":"message","qos.accept.foreign.ip":"false","timestamp":"1700834530470"}
	LOGGER.warn("getPath->{}", JsonUtil.toJson(url.getPath()));
    //getPath->com.myb.wh.buss.service.base.FileService
	LOGGER.warn("getServiceInterface->{}", JsonUtil.toJson(url.getServiceInterface()));
    //getServiceInterface->com.myb.wh.buss.service.base.FileService
	LOGGER.warn("getServiceKey->{}", JsonUtil.toJson(url.getServiceKey()));
    //getServiceKey->com.myb.wh.buss.service.base.FileService
	LOGGER.warn("getIp->{}", JsonUtil.toJson(url.getIp()));
    //getIp->192.168.100.228
	LOGGER.warn("getApplication->{}", JsonUtil.toJson(url.getApplication()));
    //getApplication->buss-service
	LOGGER.warn("getBackupAddress->{}", JsonUtil.toJson(url.getBackupAddress()));
    //getBackupAddress->192.168.100.228:21000
	LOGGER.warn("getHost->{}", JsonUtil.toJson(url.getHost()));
    //getHost->192.168.100.228
	LOGGER.warn("getPort->{}", JsonUtil.toJson(url.getPort()));
    //getPort->21000
	LOGGER.warn("getRemoteApplication->{}", JsonUtil.toJson(url.getRemoteApplication()));
    //getRemoteApplication->null
	LOGGER.warn("getServiceName->{}", JsonUtil.toJson(url.getServiceName()));
    //getServiceName->com.myb.wh.buss.service.base.FileService
	LOGGER.warn("getSide->{}", JsonUtil.toJson(url.getSide()));
    //getSide->provider
	ServiceModel serviceModel = url.getServiceModel();
	if(serviceModel != null) {
		LOGGER.warn("getServiceKey->{}", JsonUtil.toJson(serviceModel.getServiceKey()));
		//getServiceKey->com.myb.wh.buss.service.base.FileService
        LOGGER.warn("getServiceName->{}", JsonUtil.toJson(serviceModel.getServiceName()));
        //getServiceName->com.myb.wh.buss.service.base.FileService
	}
}

//如果buss-service还是消费者, 链路继续调用其它提供者, 下面将会有值, 具体属性值, 基本和上面URL一致			
URL consumerUrl = serviceContext.getConsumerUrl();
if(consumerUrl != null) { //为null
	LOGGER.warn("getAbsolutePath->{}", JsonUtil.toJson(consumerUrl.getAbsolutePath()));
	LOGGER.warn("getAddress->{}", JsonUtil.toJson(consumerUrl.getAddress()));
	LOGGER.warn("getAllParameters->{}", JsonUtil.toJson(consumerUrl.getAllParameters()));
	LOGGER.warn("getApplication->{}", JsonUtil.toJson(consumerUrl.getApplication()));
	LOGGER.warn("getBackupAddress->{}", JsonUtil.toJson(consumerUrl.getBackupAddress()));
	LOGGER.warn("getAuthority->{}", JsonUtil.toJson(consumerUrl.getAuthority()));
	LOGGER.warn("getCategory->{}", JsonUtil.toJson(consumerUrl.getCategory()));
	LOGGER.warn("getIp->{}", JsonUtil.toJson(consumerUrl.getIp()));
	LOGGER.warn("getPath->{}", JsonUtil.toJson(consumerUrl.getPath()));
	LOGGER.warn("getParametersv", JsonUtil.toJson(consumerUrl.getParameters()));
	LOGGER.warn("getPort->{}", JsonUtil.toJson(consumerUrl.getPort()));
	LOGGER.warn("getHost->{}", JsonUtil.toJson(consumerUrl.getHost()));
	LOGGER.warn("getRemoteApplication->{}", JsonUtil.toJson(consumerUrl.getRemoteApplication()));
	LOGGER.warn("getServiceInterface->{}", JsonUtil.toJson(consumerUrl.getServiceInterface()));
	LOGGER.warn("getServiceName->{}", JsonUtil.toJson(consumerUrl.getServiceName()));
	LOGGER.warn("getSide->{}", JsonUtil.toJson(consumerUrl.getSide()));
	LOGGER.warn("getServiceKey->{}", JsonUtil.toJson(consumerUrl.getServiceKey()));
	ServiceModel serviceModel = consumerUrl.getServiceModel();
	if(serviceModel != null) {
		LOGGER.warn("getServiceKey->{}", JsonUtil.toJson(serviceModel.getServiceKey()));
		LOGGER.warn("getServiceName->{}", JsonUtil.toJson(serviceModel.getServiceName()));
	}
}

上述为执行内容, 后面在碰到其它场景, 再补充吧, 一般够用了

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Activity上下文(Activity Context)是Android开发中的一个重要概念,它指的是在特定的Activity中可用的资源和数据。在Android中,每个Activity都有自己的上下文,这个上下文包含了该Activity中可以使用的各种资源,如布局文件、图像、音频、颜色、字体等,以及用于操作数据和与系统交互的回调方法。 Activity上下文的用途非常广泛,它可以用于以下几种情况: 1. 加载布局:Activity上下文包含了当前的布局资源,可以用来加载和显示布局。 2. 访问资源:通过Activity上下文,可以在Activity中访问到各种资源,如布局文件、图像、音频、颜色、字体等。 3. 访问本地数据:Activity上下文可以用来访问存储在设备上的本地数据,如SharedPreferences或文件系统中的数据。 4. 处理用户输入:Activity上下文可以用来处理用户的输入事件,如按键、触摸等。 5. 执行系统级操作:Activity上下文提供了与系统交互的方法,如打开其他应用、发送广播、接收广播等。 需要注意的是,Activity上下文是与特定的Activity关联的,当Activity被销毁或跳转到其他Activity时,其上下文也会随之消失。因此,在Activity中访问的资源或数据需要在Activity生命周期内进行管理,以避免出现意外情况。同时,在使用Activity上下文时,也需要注意权限和安全性问题,以避免潜在的安全风险。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一屁小肥咩

您的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值