cr_plumber_pubsub: Plumber - Pub/Sub parser

View source: R/plumber.R

cr_plumber_pubsubR Documentation

Plumber - Pub/Sub parser

Description

A function to use in plumber scripts to accept Pub/Sub messages

Usage

cr_plumber_pubsub(message = NULL, pass_f = function(x) x)

Arguments

message

The pubsub message

pass_f

An R function that will work with the data parsed out of the pubsub message$data field.

Details

This function is intended to be used within plumb API scripts. It needs to be annotated with a @post URL route and a @param message The pubsub message as per the plumber documentation.

pass_f should be a function you create that accepts one argument, the data from the pubsub message$data field. It is unencoded for you. Make sure the function returns a 200 response otherwise pub/sub will keep resending the message! return(TRUE) is adequate.

The Docker container for the API will need to include googleCloudRunner installed in its R environment to run this function. This is available in the public gcr.io/gcer-public/cloudrunner image.

Use cr_pubsub to test this function once deployed.

See Also

Google Pub/Sub tutorial for Cloud Run. You can set up Pub/Sub messages from Google Cloud Storage buckets via gcs_create_pubsub

Other Cloud Run functions: cr_jwt_create(), cr_run_email(), cr_run_get(), cr_run_list(), cr_run_schedule_http(), cr_run()

Examples

## Not run: 

# within a plumber api.R script:

# example function echos back pubsub message
pub <- function(x) {
  paste("Echo:", x)
}

#' Recieve pub/sub message
#' @post /pubsub #nolint
#' @param message a pub/sub message
function(message = NULL) {
  googleCloudRunner::cr_plumber_pubsub(message, pub)
}

## End(Not run)

googleCloudRunner documentation built on March 18, 2022, 8 p.m.