【问题标题】:GCP Pub/Sub Publisher process hangs forever while using Java APIGCP Pub/Sub Publisher 进程在使用 Java API 时永远挂起
【发布时间】:2017-08-25 09:50:24
【问题描述】:

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

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 上。

【问题讨论】:

  • 我遇到了同样的问题,但我是从 IntelliJ 中的主要方法运行的,所以接受的答案对我没有帮助

标签: java google-app-engine google-cloud-platform google-cloud-pubsub


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-01-09
    • 2017-10-28
    • 2022-01-13
    • 2014-08-22
    • 2022-01-03
    • 2016-06-23
    • 1970-01-01
    • 2021-10-12
    • 2021-06-17
    相关资源
    最近更新 更多