npr
npr

Reputation: 4775

Programmatically calling gcloud background functions in the Emulator

I have deployed a gcloud background function (pubsub) in emulator.

It is getting succesfully invoked from command line

functions call helloPubSub --data='{"message":"Hello World"}'

How to invoke gcloud local function from local server code ?

= = =

Below is my code on server side to publish to topic

pubsub
  .topic(topicName)
  .publisher()
  .publish(dataBuffer)
  .then(results => {
    const messageId = results[0];
    console.log(`Message ${messageId} published.`);
    res.status(200)
    res.send({hello:'world'})

  })
  .catch(err => {
    console.error('ERROR:', err);
    res.status(200)
    res.send({err:err})
  });    

I receive following error message

{"err":{"code":7,"metadata":{"_internal_repr":{}},"note":"Exception occurred in retry method that was not classified as transient"}}

Upvotes: 1

Views: 412

Answers (1)

VictorGGl
VictorGGl

Reputation: 1916

In the official docs it states:

Note: Functions deployed in the Emulator with non-HTTP triggers like Cloud Storage or Cloud Pub/Sub will not be invoked by these services. The Emulator is intended as a development environment only, so you would need to call these functions manually to have them invoked.

So if you deployed a function locally with Cloud Pub/Sub trigger, the only way to invoke it is using the command line command:

functions call [your-function]

Upvotes: 1

Related Questions