如何从后端运行Google App Engine端点方法 [英] How to run Google app engine endpoint methods from the backend

查看:167
本文介绍了如何从后端运行Google App Engine端点方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序引擎项目中遵循了我的WarmupServlet的所有配置步骤,并且看到它在启动时运行,但仍然看到我的第一个端点调用是加载请求,最多需要25秒,这是绝对不可接受的。我需要能够单独预热每个端点,以便不会有加载请求。 (显然,设置一个warmp-up servlet是不够的)。所以,我的问题是,我怎样才能在端点中调用一个方法,以便端点能够正确预热以便从WarmupServlet中提供服务?我在下面试过没有成功:

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;
}


推荐答案

文件作为库,这将正确地从Java后端加热MyEndpoint:

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();

这篇关于如何从后端运行Google App Engine端点方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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