如何在 R 中订阅 GCP Pub/Sub 消息?

时间:2021-06-01 23:55:59

标签: r google-cloud-platform publish-subscribe

我正在使用 Python 中的 Google Cloud Pub/Sub 库,https://github.com/googleapis/python-pubsub

这里很容易在 Pub/Sub 中订阅消息:

import os
from google.cloud import pubsub_v1

topic_name = 'projects/{project_id}/topics/{topic}'.format(
    project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
    topic='MY_TOPIC_NAME',  # Set this to something appropriate.
)

subscription_name = 'projects/{project_id}/subscriptions/{sub}'.format(
    project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
    sub='MY_SUBSCRIPTION_NAME',  # Set this to something appropriate.
)

def callback(message):
    print(message.data)
    message.ack()

with pubsub_v1.SubscriberClient() as subscriber:
    subscriber.create_subscription(
        name=subscription_name, topic=topic_name)
    future = subscriber.subscribe(subscription_name, callback)

R 中是否有类似的库?这个功能似乎分布在多个 R 库中,主要由 Mark Edmondson 编写。有 googleCloudRunner 中的函数 cr_plumber_pubsub(),但这将在 CloudRun 中使用。我想将此 R 代码集成到其他地方。

此任务有哪些可用选项?

0 个答案:

没有答案