Issue
I've got an app running in App Engine's Java 11 standard environment, where I want to make sure that Tasks are called on a particular version of the app (the one creating them). I can add the AppEngineRouting
field to the task creation request to achieve this, but there's a catch: normally, the version ID is accessible using ApiProxy.getCurrentEnvironment().getVersionId()
, or at least it used to be under the venerable Java 8 standard environment. Under Java 11, ApiProxy.getCurrentEnvironment()
is consistently null
for me.
Am I missing something, or has ApiProxy
been secretly "deprecated" for Java 11 standard? And if so, what is the currently accepted method of getting info like app, version and service IDs, or milliseconds remaining before request deadline?
Solution
After a bit of looking around, I realized that under the Java 11 Standard Environment system, these are available as App Engine-set envvars [1]. If you need to get things that previously used to be available in ApiProxy
, you best bet is to read the corresponding variable via System.getenv(String name)
.
Further, you can set custom envvars in the app.yaml
file, without having to pass them to your program via -Dname=value
.
[1] https://cloud.google.com/appengine/docs/standard/java11/runtime#environment_variables
Answered By - Zalán Meggyesi
Answer Checked By - Marie Seifert (JavaFixing Admin)