App引擎实例ID [英] App Engine Instance ID

查看:84
本文介绍了App引擎实例ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能获得关于您正在运行的实例的信息吗?我想输出一个简单的标识符,代码当前正在运行的实例用于日志记录。

解决方案

由于没有语言标签,并查看您的个人资料历史记录,我假设您正在使用GAE / J?

在这种情况下,实例ID信息被嵌入到您可以通过 ApiProxy.getCurrentEnvironment()获取的环境属性之一中c $ c>方法。然后,您可以使用键 BackendService.INSTANCE_ID_ENV_ATTRIBUTE 从结果映射中提取实例ID。

即使密钥是存储在BackendService中,这种方法也适用于前端实例。总之,下面的代码会为你获取实例ID:

  String tInstanceId = ApiProxy.getCurrentEnvironment()
.getAttributes()
.get(BackendService.INSTANCE_ID_ENV_ATTRIBUTE)
.toString();

请记住,这种方法完全没有Google的文档记录,并且可能会随时更改而不会发出警告未来。但是由于你的用例只是用于日志记录,我认为现在就足够了。


Is it possible to get info on what instance you're running on? I want to output just a simple identifier for which instance the code is currently running on for logging purposes.

解决方案

Since there is no language tag, and seeing your profile history, I assume you are using GAE/J?

In that case, the instance ID information is embedded in one of the environment attributes that you could get via ApiProxy.getCurrentEnvironment() method. You could then extract the instance id from the resulting map using key BackendService.INSTANCE_ID_ENV_ATTRIBUTE.

Even though the key is stored in BackendService, this approach will also work for frontend instances. So in summary, the following code would fetch the instance ID for you:

String tInstanceId = ApiProxy.getCurrentEnvironment()
                             .getAttributes()
                             .get( BackendService.INSTANCE_ID_ENV_ATTRIBUTE )
                             .toString();

Please keep in mind that this approach is quite undocumented by Google, and might subject to change without warning in the future. But since your use case is only for logging, I think it would be sufficient for now.

这篇关于App引擎实例ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆