Skip to content

Latest commit

 

History

History
121 lines (83 loc) · 3.76 KB

provider-gcpcloud.md

File metadata and controls

121 lines (83 loc) · 3.76 KB

Concis GCPCloud Provider

The GCPCloud Provider (namespace \Concis\Provider\GCPCloud) is a collection of EventHandlers tied to events originating from inside of Google Cloud Platform.

Just like Google Cloud Functions supporting various triggers, Concis also supports (several of) these.

Cloud Pub/Sub Topic EventHandler

This type of EventHandler is invoked by messages published to Google Cloud Platform Pub/Sub topics.

  • Class: \Concis\Provider\GCPCloud\Pubsub\EventHandler
  • Shorthand: gcpcloud_pubsub

💡 You could compare EventHandlers registered like this to deploying a Google Cloud Function using --trigger-topic.

Example

$eventHandler = \Concis\EventHandler::gcpcloud_pubsub(function (string $subscription, \Concis\Provider\GCPCloud\Pubsub\Datatype\PubsubMessage $message) {
    // Your handling code here …
});

Arguments

Invoking the EventHandler

  1. Set up some ENV vars to use

    BUCKET_NAME=my-bucket
    GC_PROJECT=my-gcp-project
    PUBSUB_TOPIC=my-topic
    CONCIS_URL=https://example.org/
  2. Register your EventHandler as a Push Endpoint for your Cloud Pub/Sub Topic

    gcloud pubsub topics create $PUBSUB_TOPIC --project=$GC_PROJECT
    gcloud pubsub subscriptions create $PUBSUB_TOPIC-subscription --project=$GC_PROJECT --topic $PUBSUB_TOPIC --push-endpoint="$CONCIS_URL"
  3. Trigger a message

    gcloud pubsub topics publish $PUBSUB_TOPIC --project=$GC_PROJECT --message '{"foo": "bar"}'

🔰 References:

Cloud Storage EventHandler

This type of EventHandler is invoked by messages published by Cloud Storage. The messages are transported over HTTP

  • Class: \Concis\Provider\GCPCloud\CloudStorage\EventHandler
  • Shorthand: gcpcloud_cloud_storage

💡 You could compare EventHandlers registered like this to deploying a Google Cloud Function using --trigger-resource.

Example

$eventHandler = \Concis\EventHandler::gcpcloud_cloud_storage(function(\Concis\Provider\GCPCloud\CloudStorage\Datatype\CloudStorageObject $object = null, array $attributes = []) {
    // Your handling code here …
});

Arguments

Invoking the EventHandler

  1. Set up some ENV vars to use

    BUCKET_NAME=my-bucket
    GC_PROJECT=my-gcp-project
    GC_REGION=europe-west1
    TRIGGER_NAME=my-trigger
    CONCIS_URL=https://example.org/
  2. Create a Bucket

    gsutil mb "gs://$BUCKET_NAME/" -c "STANDARD" -p $GC_PROJECT -l $GC_REGION
  3. Create a Trigger Notification in the JSON format on your bucket. It will automatically also create a Cloud Pub/Sub Topic.

    gsutil notification create -t $TRIGGER_NAME -f json gs://$BUCKET_NAME
  4. Create a Push Subscription onto the created Cloud Pub/Sub Topic

    gcloud pubsub subscriptions create $TRIGGER_NAME-subscription --project=$GC_PROJECT --topic $TRIGGER_NAME --push-endpoint="$CONCIS_URL"
  5. Trigger a message by uploading a file to your Bucket

    NOW=$(date +%s)
    gsutil cp README.md gs://c-all-data-dev-test-bramus/README-$NOW.md