# Cloud PubSub V1 Client - Class JavaScriptUDF (2.19.0)

2.19.3 (latest) 2.19.2 2.18.0 2.17.0 2.16.2 2.15.1 2.14.0 2.13.2 2.12.0 2.11.3 2.10.1 2.9.1 2.8.2 2.7.0 2.6.0 2.5.2 2.4.0 2.3.0 2.2.1 2.1.2 1.50.0 1.49.0 1.48.0 1.47.0 1.46.5 1.45.2 1.44.0 1.43.2 1.42.1 1.41.3 1.40.1 1.39.3 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

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setFunctionName

Required. Name of the JavasScript function that should applied to Pub/Sub
messages.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### 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) {
      }

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### 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) {
      }

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |