我按照https://cloud.google.com/tasks/docs/creating-appengine-tasks
中的描述创建任务它在99%的情况下都有效,但是有时我会遇到以下异常:
java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init> (ManagedChannelOrphanWrapper.java:103)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init> (ManagedChannelOrphanWrapper.java:53)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init> (ManagedChannelOrphanWrapper.java:44)
at io.grpc.internal.AbstractManagedChannelImplBuilder.build (AbstractManagedChannelImplBuilder.java:411)
at by.company.application.QueueService.createTask (QueueService.java:76)
QueueService中的方法代码:
private void createTask(String queueName, String payload, long timeShiftMillis) {
String queuePath = QueueName.of(gcpProjectId, gcpLocation, queueName).toString();
try (CloudTasksClient client = CloudTasksClient.create()) {
Task.Builder taskBuilder = Task
.newBuilder()
.setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder()
.setBody(ByteString.copyFrom(payload, Charset.defaultCharset()))
.setRelativeUri("/" + queueName)
.setHttpMethod(HttpMethod.POST)
.build());
taskBuilder.setScheduleTime(Timestamp
.newBuilder()
.setSeconds(Instant.now(Clock.systemUTC()).plusMillis(timeShiftMillis).getEpochSecond()));
Task build = taskBuilder.build();
if (!gcpTaskEnabled) {
return;
}
client.createTask(queuePath, build);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Can't create task", e);
}
}
答案 0 :(得分:0)
这看起来像https://github.com/googleapis/google-cloud-java/issues/3648。尝试升级到最新版本的google-cloud-tasks(及其依赖项)以获取修复。