How to run Google app engine endpoint methods from the backend

送分小仙女□ 提交于 2019-12-06 14:15:34

问题


I have followed all the configuration steps for my WarmupServlet in my app engine project and I see it run at startup, but still I see my first endpoint call as a loading request which takes up to 25 seconds which is absolutely unacceptable. I need to be able to warm up each endpoint individually so that there will be no loading requests. (Apparently just setting up a warmp-up servlet is not enough.) So, my question is, how can I call a method in endpoints so that the endpoint is properly warmed up to serve from my WarmupServlet? I tried below with no success:

MyEndpoint me = new MyEndpoint();
me.getMyEntity(1L);

where

@ApiMethod(name = "getMyEntity")
public MyEntity getMyEntity(@Named("id") Long id) {
    EntityManager mgr = getEntityManager();
    MyEntity myEntity = null;
    try {
        myEntity = mgr.find(MyEntity.class, id);
    } finally {
        mgr.close();
    }
    return myEntity;
}

回答1:


After adding the client endpoints jar file as a library, this properly warms up MyEndpoint from the Java backend:

NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

Myendpoint.Builder endpointBuilder = new Myendpoint.Builder(
          HTTP_TRANSPORT,
          JSON_FACTORY,
          null);

endpointBuilder.setApplicationName("My App");
Myendpoint endpoint = endpointBuilder.build();
endpoint.getMyEntity(1L).execute();


来源:https://stackoverflow.com/questions/43021806/how-to-run-google-app-engine-endpoint-methods-from-the-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!