MIDHermesProducer - Global

  • Rversion finale: Australia
  • Mis à jour 12 mars 2026
  • 2 minutes de lecture
  • 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.

    Tableau 1. Parameters
    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.

    Tableau 2. Parameters
    Name Type Description
    options Object Contains configuration parameters for the message.
    {
       applicationId: "String",
       callbackFunction: function(),
       headers: {Object},
       key: "String",
       message: "String",
       topic: "String"
    }
    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).
    function(errorMessage, errorType) { 
       //implement error handling here
    };
    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.
    Remarque :
    Don't include the instance prefix; it is added automatically.
    Tableau 3. Returns
    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:
    • org.apache.kafka.common.errors.TimeoutException: Kafka broker unreachable or network issues. Check firewall rules for Hermes bootstrap address and ports.
    • com.service_now.mid.hermes_api.exception.MIDHermesAPIExtensionNotStartedException: Extension not started. Verify MID Hermes API extension context is active.
    • java.lang.IllegalArgumentException: Invalid parameters. Ensure topic and message are provided.
    Additional steps to resolve errors:
    • Verify MID Hermes API extension is running in MID Server UI.
    • Check network connectivity to Hermes.
    • Review MID Server logs with property mid.hermes.debug=true for detailed diagnostics.
    • Confirm IPKI certificate is valid in MID Server keystore.

    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.