Reputation: 180
I have a GCP pubsub Push subscription. This subscription is pushing to a GCP Cloud run instance that receives the pubsub messages as HTTP requests. I am currently trying to add custom attributes to the publisher so that I can receive them in the Cloud run instance. It looks like attributes are not supported since they do not show up in the pubsub.Message
when I unmarshal the body of the request either in the HTTP headers.
That leads me to conclude that custom attributes are not supported when using pubsub push subscriptions. Is this true?
Upvotes: 0
Views: 256
Reputation: 17206
Message attributes work for push subscriptions, including when using CloudRun. They are located in the request body message. For example, to access the value of an attribute named test
, one would do the following in Node:
app.post('/', (req, res) => {
const pubSubMessage = req.body.message;
console.log(`test attribute: ${pubSubMessage.attributes.test}`);
res.status(204).send();
});
Upvotes: 0