我正在使用Google PubSub Client for Java将消息发布到gcp pubsub。
我可以在本地尝试发布该消息,但是当我在docker container
中运行相同的应用程序时,它将失败,并且没有任何正确的错误消息。
我已将GCP凭证json保存在容器本身内并指向它。
我尝试过在发布商关闭时进行同样的操作,但最终没有成功。
下面是代码片段:
try {
publisher = Publisher.newBuilder(topicName).setCredentialsProvider(FixedCredentialsProvider.create(creds)).build();
log.info("published ---------------------- " +publisher); // can see this in log
ByteString data = ByteString.copyFromUtf8(message);
log.info("data ---------------------- " +data); // can see this in log
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
log.info("pubsubMessage ---------------------- " +pubsubMessage); // **cannot** see this in log
messageIdFuture = publisher.publish(pubsubMessage);
log.info("messageIdFuture ---------------------- " +messageIdFuture);//cannot see this
} finally {
if(Objects.nonNull(messageIdFuture)){
log.info("published with message ID: " + messageIdFuture.get());}
else{
log.info("message Id null : " + messageIdFuture); //finally this is logged with messageIdFuture null
}
非常感谢任何帮助。