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

How to subscribe to GCP Pub/Sub messages within R?

我在 Python、https://github.com/googleapis/python-pubsub

中使用 Google Cloud Pub/Sub 库

在这里订阅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 代码集成到其他地方。

此任务有哪些可用选项?

鉴于这个问题是几个月前才打开的,我想OP现在可能已经解决了他的问题。

对于未来的读者,我想提一下 googlePubsubR 现在可以在 CRAN 上使用并且涵盖了大多数 Pub/Sub 使用案例。