MIDHermesProducer - Global
The MIDHermesProducer API provides a method to send data from the MID Server to a Hermes topic.
Sending data via the Hermes Messaging Service rather than using the MID Server ECC Queue can be a more efficient way to get data to a ServiceNow instance.
This API requires the ServiceNow MID Hermes API (com.glide.mid.hermes_api) plugin. The calling user must have the kafka_admin role. Before calling this API, follow the steps to Configure the MID Hermes API Extension.
Use this API in scripts that run on the MID Server, such as MID Server background scripts or in Workflow Studio action script steps with the Required Runtime set to MID.
MIDHermesProducer - MIDHermesProducer()
Creates a MIDHermesProducer for sending messages to Hermes topics.
| Name | Type | Description |
|---|---|---|
| None |
This example instantiates a MIDHermesProducer.
var producer = new MIDHermesProducer();
MIDHermesProducer - send(Object options)
Sends a message from the MID Server to the specified Hermes topic.
The 4000-4050 port range must be open to send messages to a Hermes topic. For more information, see Producing and consuming messages from a Kafka client.
| Name | Type | Description |
|---|---|---|
| options | Object | Contains configuration parameters for the message. |
| options.applicationId | String | Optional. Application identifier for topic routing. When provided, messages are routed to snc.{instance}.{applicationId}.{topic}, otherwise they are routed to
snc.{instance}.{topic}. |
| options.onErrorCallback | Function | Optional. JavaScript function to execute if message delivery fails. The function accepts two parameters: String errorMessage and String errorType (the fully qualified Java exception
class name). |
| options.headers | Object | Optional. Key-value pairs for message headers. Any headers supported by Apache Kafka are valid. |
| options.key | String | Optional. Message key for partitioning in Apache Kafka. Messages with the same key are sent to the same partition, ensuring ordering. |
| options.message | String | Content of the message to send to the topic. Any value formatted as a string is valid. |
| options.topic | String | Name of the Hermes topic to send the message to. Note: Don't include the instance prefix; it is added automatically. |
| Type | Description |
|---|---|
| None | This method does not return a value. Message delivery is asynchronous. Success: Messages are delivered asynchronously to Hermes Kafka brokers. Check MID Server logs for delivery confirmation. Failure: If message delivery fails, the optional callback function (if provided) is invoked with error details. Common errors include:
Additional steps to resolve errors:
|
This example sends a message to a Hermes topic.
// Create producer instance
var producer = new MIDHermesProducer();
// Define error callback function
var errorCallback = function(errorMessage, errorType) {
gs.error("Message delivery failed: " + errorType + " - " + errorMessage);
};
// Send message with all optional parameters
producer.send({
topic: "order-events",
applicationId: "sn_streamconnect",
message: JSON.stringify({
orderId: "ORD-12345",
status: "completed",
timestamp: new Date().getTime()
}),
key: "customer-456",
headers: {
"content-type": "application/json",
"source": "mid-server",
"version": "1.0"
},
onErrorCallback: errorCallback
});
The message is sent asynchronously. Check MID Server logs for delivery confirmation.