Java GAE任务队列从Spring Boot引发CallNotFoundException

时间:2019-07-20 07:55:23

标签: java spring-boot google-app-engine google-cloud-platform task-queue

我正在春季靴下运行GAE。我想实现一个推送队列,但不断得到:

com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't 
make API call taskqueue.BulkAdd in a thread that is neither the 
original request thread nor a thread created by ThreadManager

起初,我试图像这样在rest控制器中添加任务:

@RestController
public class MyController {

   @GetMapping("/taskqueues/testTaskQueue")
   public ResponseEntity testTaskQueue(@RequestParam String key) {

       Queue queue = QueueFactory.getDefaultQueue();
       queue.add(TaskOptions.Builder.withUrl("/testTaskQueue")
            .param("key", key));

       return new ResponseEntity<>(null, HttpStatus.OK);
   }
}

接下来,我尝试通过这种方式在Spring Boot中定义servlet:

@Bean
public ServletRegistrationBean<Enqueue> exampleServletBean() {
    ServletRegistrationBean<Enqueue> bean = new 
    ServletRegistrationBean<>(
            new Enqueue(), "/taskqueues/enqueue");
    bean.setLoadOnStartup(1);
    return bean;
}

入队是:

public class Enqueue extends HttpServlet {

   protected void doPost(HttpServletRequest request, 
                  HttpServletResponse response)
                  throws ServletException, IOException {

        // Add the task to the default queue.
        Queue queue = QueueFactory.getDefaultQueue();
        queue.add(TaskOptions.Builder.withUrl("/testTaskQueue")
             .param("key", "54"));
        response.sendRedirect("/");
    }
}

两者都抛出CallNotFoundException。

我该如何进行这项工作?我做错了什么?

0 个答案:

没有答案