{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":885,"path":"api-reference/server-api-reference/ProducerV2ScopedAPI.md","title":"ProducerV2 - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# ProducerV2- Scoped\n\nThe ProducerV2 API provides methods to publish messages from your ServiceNow instance to a Kafka topic.\n\n**Note:** This API requires a Stream Connect subscription. For more information, see [https://www.servicenow.com/now-platform/workflow-data-fabric.html](https://www.servicenow.com/now-platform/workflow-data-fabric.html).\n\nThis API requires the ServiceNow Stream Connect Installer plugin \\(com.glide.hub.stream\\_connect.installer\\) and runs in the `sn_ih_kafka` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## ProducerV2 - send\\(String topicSysID, String key, String message, Boolean isSync, Object headers, String schemaID\\)\n\nSends the specified message to the specified Kafka topic.\n\n<table id=\"table_vn5_c3f_nvb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntopicSysID\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the topic to publish the message to. Topics are stored in the Kafka Topics \\[sys\\_kafka\\_topic\\] table.\n\n</td></tr><tr><td>\n\nkey\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the key for a specific partition in the topic.\n\n</td></tr><tr><td>\n\nmessage\n\n</td><td>\n\nString\n\n</td><td>\n\nMessage text.\n\n</td></tr><tr><td>\n\nisSync\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to require the script to wait for the send method to complete before continuing.Valid values:\n\n-   true: Wait for the step to complete before continuing the associated flow.\n-   false: Do not wait for the step to complete before continuing the associated flow.\n\n</td></tr><tr><td>\n\nheaders\n\n</td><td>\n\nObject\n\n</td><td>\n\nHeaders for the message, defined as key-value pairs. ```\n\"headers\": {\n  \"<key>\": \"<value>\"\n}\n```\n\nFor example, `var headers = { \"origin\": \"sn_business_rule\" };` -   `key`: String. Name of the header.\n-   `value`: String. Value of the header.\n\n</td></tr><tr><td>\n\nschemaID\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the schema record.Required if you're using a schema to convert plain-text messages to Avro messages and back. Schemas are stored in the Stream Connect Schemas \\[stream\\_connect\\_schema\\] table. For more information, see [Schema management in Stream Connect](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/integrate-applications/schema-management.md).\n\n</td></tr></tbody>\n</table><table id=\"table_wn5_c3f_nvb\" class=\"returns\"><thead><tr><th>\n\nObject property\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndelivery\n\n</td><td>\n\nKafka producer delivery. Reflects the value set for the **isSync** parameter.Possible values:\n\n-   async - Asynchronous delivery\n-   sync - Synchronous delivery\n\nData type: String\n\n</td></tr><tr><td>\n\noffset\n\n</td><td>\n\nThe offset of the message in the partition of the topic in Hermes Kafka. This value is only returned for synchronous delivery.Data type: Number\n\n</td></tr><tr><td>\n\npartition\n\n</td><td>\n\nPartition of the topic in which the message is stored. This value is only returned for synchronous delivery.Data type: Number\n\n</td></tr></tbody>\n</table>### Asynchronous delivery\n\nThis example shows how to send changed incident information to the Kafka topic with a sys\\_id of 75135aa2ff0311105cf343d0653bf155, using a schema with a sys\\_id of f9d083f3ff610210ef7343d3653bf12e.\n\n```\nvar message = {\n  'number': current.number.toString(),\n  'short_description': current.short_description.toString(),\n  'caller_id': current.caller_id.getDisplayValue(),\n  'priority': current.priority.toString(),\n  'state': current.state.toString()\n};\n\nvar headers = {\n    'origin': 'sn_business_rule'\n};\n\nvar producer = new sn_ih_kafka.ProducerV2();\nproducer.send('75135aa2ff0311105cf343d0653bf155', gs.generateGUID(), JSON.stringify(message), false, headers, 'f9d083f3ff610210ef7343d3653bf12e');\n\n```\n\n### Synchronous delivery\n\nThis example shows how get the return values of a Kafka message.\n\n```\nvar message = \"Defect fix\";\n \nvar producer = new sn_ih_kafka.ProducerV2();\n \nvar response = producer.send('63820c0e1b492210dcff64e5604bcb93', gs.generateGUID(), JSON.stringify(message), true, null);\ngs.log(\"Partition was \"+response.partition);\ngs.log(\"Offset was :\"+response.offset);\ngs.log(\"Delivery was :\"+response.delivery);\n```\n\nOutput:\n\n```\n*** Script: Partition was 1\n*** Script: Offset was :258072\n*** Script: Delivery was :sync\n```\n\n"}}