2 回答

TA貢獻1995條經驗 獲得超2個贊
非常感謝您的所有回復。我剛剛使用下面的代碼片段示例解決了這個問題
def receive_messages_synchronously(project, subscription_name):
"""Pulling messages synchronously."""
# [START pubsub_subscriber_sync_pull]
# project = "Your Google Cloud Project ID"
# subscription_name = "Your Pubsub subscription name"
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_name)
# Builds a pull request with a specific number of messages to return.
# `return_immediately` is set to False so that the system waits (for a
# bounded amount of time) until at lease one message is available.
response = subscriber.pull(
subscription_path,
max_messages=3,
return_immediately=False)
ack_ids = []
for received_message in response.received_messages:
print("Received: {}".format(received_message.message.data))
ack_ids.append(received_message.ack_id)
# Acknowledges the received messages so they will not be sent again.
subscriber.acknowledge(subscription_path, ack_ids)
# [END pubsub_subscriber_sync_pull]
原因是創建的訂閱使用拉取請求。我猜使用的回調方法概念主要是為了“推送”,這可能是因為我沒有提供端點和令牌來發布消息。希望我的猜測是正確的。也讓我知道你的看法。

TA貢獻1811條經驗 獲得超6個贊
這可能是由于以下兩個因素之一造成的:
向 AutoML API 發送請求時使用的憑據無效 - pubsub 很可能在其他上下文中執行并且無法獲取默認憑據
無效的模型資源名稱(確保它是正確的) - 它應該是這樣的:“projects/12423534/locations/us-central1/models/23432423”
添加回答
舉報