1

我按照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);
}
}
4

1 回答 1

0

这看起来像https://github.com/googleapis/google-cloud-java/issues/3648。尝试升级到最新版本的 google-cloud-tasks(及其依赖项)以获取修复。

于 2019-02-20T23:00:13.780 回答