Cloud PubSub V1 Client - Class JavaScriptUDF (2.13.2)
Stay organized with collections
Save and categorize content based on your preferences.
Reference documentation and code samples for the Cloud PubSub V1 Client class JavaScriptUDF.
User-defined JavaScript function that can transform or filter a Pub/Sub
message.
Generated from protobuf message google.pubsub.v1.JavaScriptUDF
Namespace
Google \ Cloud \ PubSub \ V1
Methods
__construct
data
array
Optional. Data for populating the Message object.
↳ function_name
string
Required. Name of the JavasScript function that should applied to Pub/Sub messages.
↳ code
string
Required. JavaScript code that contains a function function_name
with the below signature: /** * * Transforms a Pub/Sub message. * * @return {(Object<string, (string | Object<string, string>)>|null)} - To * * filter a message, return `null`. To transform a message return a map * * with the following keys: * * - (required) 'data' : {string} * * - (optional) 'attributes' : {Object<string, string>} * * Returning empty `attributes` will remove all attributes from the * * message. * * * @param {(Object<string, (string | Object<string, string>)>} Pub/Sub * * message. Keys: * * - (required) 'data' : {string} * * - (required) 'attributes' : {Object<string, string>} * * * @param {Object<string, any>} metadata - Pub/Sub message metadata. * * Keys: * * - (optional) 'message_id' : {string} * * - (optional) 'publish_time': {string} YYYY-MM-DDTHH:MM:SSZ format * * - (optional) 'ordering_key': {string} */ function <function_name>(message, metadata) { }
getFunctionName
Required. Name of the JavasScript function that should applied to Pub/Sub
messages.
setFunctionName
Required. Name of the JavasScript function that should applied to Pub/Sub
messages.
getCode
Required. JavaScript code that contains a function function_name
with the
below signature:
/**
* Transforms a Pub/Sub message.
* @return {(Object<string, (string | Object<string, string>)>|null)} - To
* filter a message, return `null`. To transform a message return a map
* with the following keys:
* - (required) 'data' : {string}
* - (optional) 'attributes' : {Object<string, string>}
* Returning empty `attributes` will remove all attributes from the
* message.
*
* @param {(Object<string, (string | Object<string, string>)>} Pub/Sub
* message. Keys:
* - (required) 'data' : {string}
* - (required) 'attributes' : {Object<string, string>}
*
* @param {Object<string, any>} metadata - Pub/Sub message metadata.
* Keys:
* - (optional) 'message_id' : {string}
* - (optional) 'publish_time': {string} YYYY-MM-DDTHH:MM:SSZ format
* - (optional) 'ordering_key': {string}
*/
function <function_name>(message, metadata) {
}
setCode
Required. JavaScript code that contains a function function_name
with the
below signature:
/**
* Transforms a Pub/Sub message.
* @return {(Object<string, (string | Object<string, string>)>|null)} - To
* filter a message, return `null`. To transform a message return a map
* with the following keys:
* - (required) 'data' : {string}
* - (optional) 'attributes' : {Object<string, string>}
* Returning empty `attributes` will remove all attributes from the
* message.
*
* @param {(Object<string, (string | Object<string, string>)>} Pub/Sub
* message. Keys:
* - (required) 'data' : {string}
* - (required) 'attributes' : {Object<string, string>}
*
* @param {Object<string, any>} metadata - Pub/Sub message metadata.
* Keys:
* - (optional) 'message_id' : {string}
* - (optional) 'publish_time': {string} YYYY-MM-DDTHH:MM:SSZ format
* - (optional) 'ordering_key': {string}
*/
function <function_name>(message, metadata) {
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud PubSub V1 Client - Class JavaScriptUDF (2.13.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.2 (latest)](/php/docs/reference/cloud-pubsub/latest/V1.JavaScriptUDF)\n- [2.13.1](/php/docs/reference/cloud-pubsub/2.13.1/V1.JavaScriptUDF)\n- [2.12.0](/php/docs/reference/cloud-pubsub/2.12.0/V1.JavaScriptUDF)\n- [2.11.3](/php/docs/reference/cloud-pubsub/2.11.3/V1.JavaScriptUDF)\n- [2.10.1](/php/docs/reference/cloud-pubsub/2.10.1/V1.JavaScriptUDF)\n- [2.9.1](/php/docs/reference/cloud-pubsub/2.9.1/V1.JavaScriptUDF)\n- [2.8.2](/php/docs/reference/cloud-pubsub/2.8.2/V1.JavaScriptUDF)\n- [2.7.0](/php/docs/reference/cloud-pubsub/2.7.0/V1.JavaScriptUDF)\n- [2.6.0](/php/docs/reference/cloud-pubsub/2.6.0/V1.JavaScriptUDF)\n- [2.5.2](/php/docs/reference/cloud-pubsub/2.5.2/V1.JavaScriptUDF)\n- [2.4.0](/php/docs/reference/cloud-pubsub/2.4.0/V1.JavaScriptUDF)\n- [2.3.0](/php/docs/reference/cloud-pubsub/2.3.0/V1.JavaScriptUDF)\n- [2.2.1](/php/docs/reference/cloud-pubsub/2.2.1/V1.JavaScriptUDF)\n- [2.1.2](/php/docs/reference/cloud-pubsub/2.1.2/V1.JavaScriptUDF)\n- [1.50.0](/php/docs/reference/cloud-pubsub/1.50.0/V1.JavaScriptUDF)\n- [1.49.0](/php/docs/reference/cloud-pubsub/1.49.0/V1.JavaScriptUDF)\n- [1.48.0](/php/docs/reference/cloud-pubsub/1.48.0/V1.JavaScriptUDF)\n- [1.47.0](/php/docs/reference/cloud-pubsub/1.47.0/V1.JavaScriptUDF)\n- [1.46.5](/php/docs/reference/cloud-pubsub/1.46.5/V1.JavaScriptUDF)\n- [1.45.2](/php/docs/reference/cloud-pubsub/1.45.2/V1.JavaScriptUDF)\n- [1.44.0](/php/docs/reference/cloud-pubsub/1.44.0/V1.JavaScriptUDF)\n- [1.43.2](/php/docs/reference/cloud-pubsub/1.43.2/V1.JavaScriptUDF)\n- [1.42.1](/php/docs/reference/cloud-pubsub/1.42.1/V1.JavaScriptUDF)\n- [1.41.3](/php/docs/reference/cloud-pubsub/1.41.3/V1.JavaScriptUDF)\n- [1.40.1](/php/docs/reference/cloud-pubsub/1.40.1/V1.JavaScriptUDF)\n- [1.39.3](/php/docs/reference/cloud-pubsub/1.39.3/V1.JavaScriptUDF) \nReference documentation and code samples for the Cloud PubSub V1 Client class JavaScriptUDF.\n\nUser-defined JavaScript function that can transform or filter a Pub/Sub\nmessage.\n\nGenerated from protobuf message `google.pubsub.v1.JavaScriptUDF`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ PubSub \\\\ V1\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getFunctionName\n\nRequired. Name of the JavasScript function that should applied to Pub/Sub\nmessages.\n\n### setFunctionName\n\nRequired. Name of the JavasScript function that should applied to Pub/Sub\nmessages.\n\n### getCode\n\nRequired. JavaScript code that contains a function `function_name` with the\nbelow signature: \n\n /**\n * Transforms a Pub/Sub message.\n\n * @return {(Object\u003cstring, (string | Object\u003cstring, string\u003e)\u003e|null)} - To\n * filter a message, return `null`. To transform a message return a map\n * with the following keys:\n * - (required) 'data' : {string}\n * - (optional) 'attributes' : {Object\u003cstring, string\u003e}\n * Returning empty `attributes` will remove all attributes from the\n * message.\n *\n * @param {(Object\u003cstring, (string | Object\u003cstring, string\u003e)\u003e} Pub/Sub\n * message. Keys:\n * - (required) 'data' : {string}\n * - (required) 'attributes' : {Object\u003cstring, string\u003e}\n *\n * @param {Object\u003cstring, any\u003e} metadata - Pub/Sub message metadata.\n * Keys:\n * - (optional) 'message_id' : {string}\n * - (optional) 'publish_time': {string} YYYY-MM-DDTHH:MM:SSZ format\n * - (optional) 'ordering_key': {string}\n */\n function \u003cfunction_name\u003e(message, metadata) {\n }\n\n### setCode\n\nRequired. JavaScript code that contains a function `function_name` with the\nbelow signature: \n\n /**\n * Transforms a Pub/Sub message.\n\n * @return {(Object\u003cstring, (string | Object\u003cstring, string\u003e)\u003e|null)} - To\n * filter a message, return `null`. To transform a message return a map\n * with the following keys:\n * - (required) 'data' : {string}\n * - (optional) 'attributes' : {Object\u003cstring, string\u003e}\n * Returning empty `attributes` will remove all attributes from the\n * message.\n *\n * @param {(Object\u003cstring, (string | Object\u003cstring, string\u003e)\u003e} Pub/Sub\n * message. Keys:\n * - (required) 'data' : {string}\n * - (required) 'attributes' : {Object\u003cstring, string\u003e}\n *\n * @param {Object\u003cstring, any\u003e} metadata - Pub/Sub message metadata.\n * Keys:\n * - (optional) 'message_id' : {string}\n * - (optional) 'publish_time': {string} YYYY-MM-DDTHH:MM:SSZ format\n * - (optional) 'ordering_key': {string}\n */\n function \u003cfunction_name\u003e(message, metadata) {\n }"]]