GCP Pub/Sub 发布者进程在使用 Java API 时永远挂起

GCP Pub/Sub Publisher process hangs forever while using Java API

直到昨天,我才成功将消息发布到 Pub/Sub 主题中。但是从今天早上开始,代码在发布期间将永远被挂起。我的问题与描述 here 相同。 然后我尝试使用 Java API 创建主题,如下面的代码片段所述

TopicName topic = TopicName.create(projectId, topicId);

try {
  TopicAdminClient topicAdminClient = TopicAdminClient.create();
  topicAdminClient.createTopic(topic); //HANG FOREVER
}catch(Exception e){
  e.printStackTrace();
} 

代码在 topicAdminClient.createTopic 处再次挂起。

我正在为 GCP Pub/Sub 使用 com.google.pubsub.v1 包以及 com.google.cloud.pubsub.v1.TopicAdminClient。我已尝试使用默认身份验证凭据以及使用 服务帐户密钥 设置 GOOGLE_APPLICATION_CREDENTIAL。我不确定我哪里做错了。谁能帮我解决这个问题?

我发布消息的代码如下

FileInputStream fis = new FileInputStream(new File("JSON file path"));
ApiFuture<String> messageId = publishMessage(publisher, 
ByteString.copyFrom(IOUtils.toByteArray(fis)));

publishMessage 定义如下

private static ApiFuture<String> publishMessage(Publisher publisher, ByteString message)
            throws Exception {
    // convert message to bytes
    PubsubMessage pubsubMessage = 
    PubsubMessage.newBuilder().setData(message).build();
    return publisher.publish(pubsubMessage);
}

附加信息: 我尝试执行数据存储 Java api 并且它正在无缝执行。我想也许问题只出在 Pubsub 上。

的,问题已解决。我错误地忘记在 pom 文件中提及包装类型。一旦我提到包装类型为 jar (jar) 它就开始工作了。