---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# を使用するようにプロデューサーイベント通知フレームワークを構成する Hermes メッセージングサービス

# を使用するようにプロデューサーイベント通知フレームワークを構成する Hermes メッセージングサービス {#ariaid-title1}

* リリースバージョン: Australia
* 
* 更新日 2026年03月12日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：7分

インスタンスで Hermes メッセージングサービス を使用している場合は、Kafka メッセージバスのプロデューサーイベント通知フレームワークを構成する必要があります。

## 始める前に

必要なロール：admin

Hermes メッセージングサービスをアクティブ化する必要があります。詳細については、「[Activating the Hermes Messaging Service](https://www.servicenow.com/docs/access?context=hermes-messaging-service-activation&version=australia&pubname=australia-servicenow-platform&ft:locale=en-US)」を参照してください。  
次のコードスニペットは、Hermes メッセージングサービスを使用してトピックにメッセージを送信するために必要な要素を構成するために呼び出す必要がある HermesEventPublisher メソッドを示しています。その後、 [ProducerV2](https://servicenow-prod.fluidtopics.net/MBZxOp37IEUSe~Bzki47Ig#ProducerV2ScopedAPI "ProducerV2 API は、ServiceNow インスタンスから Kafka トピックにメッセージを公開するメソッドを提供します。") API が呼び出されてメッセージが送信されます。

    publishEventToHermesKafka: function(tmfEventPayload) {
      if (gs.nil(tmfEventPayload)) {
        return;
      }
      this.publishMessageThroughProducerV2API(tmfEventPayload)

    },

    publishMessageThroughProducerV2API: function(message) {
      if (gs.nil(message)) return;
      var comptableTopicSysIds = this.fetchTopicsForMessage(message);
      if (gs.nil(comptableTopicSysIds)) return;

      for (var i = 0; i < comptableTopicSysIds.length; i++) {
        var partitionKey = this.fetchPartionKey(message);
        var headers = this.fetchMessageHeaders(message)
        try {
          var producer = new sn_ih_kafka.ProducerV2();
          producer.send(comptableTopicSysIds[i], partitionKey, JSON.stringify(message), false, headers);
        } catch (ex) {
          this._logger.logErr("Publishing message to Hermes Kafka Failed, error is: " + ex);
        }
      }
    },

## 手順

1. Hermes メッセージングサービス への安全な接続をセットアップします。  
   詳細については、「[Set up a secure connection to the Hermes Messaging Service](https://www.servicenow.com/docs/access?context=set-up-secure-connection-to-hermes&version=australia&pubname=australia-servicenow-platform&ft:locale=en-US)」を参照してください。
2. Hermes メッセージングサービス にメッセージを公開するときに、[HermesEventPublisherOOB:fetchTopicsForMessage(オブジェクトメッセージ)](https://servicenow-prod.fluidtopics.net/ynZAgIIFBgPtw0JTx39FOQ#HEPO-fetchTopicsForMessage_O "渡されたメッセージに関連付けられているすべての Kafka トピックを返します。") メソッドのデフォルト機能をカスタムトピックピッカーロジックで上書きします。  
   HermesEventPublisher - fetchTopicsForMessage() メソッドでは、指定されたメッセージを送信する Kafka トピックを決定するロジックを指定する必要があります。次に、これらのトピックレコードのsys_idsをアレイで返します。

   メッセージペイロードの属性に基づいてトピックを選択するか、実装で単一のトピックのみを使用する場合は、メッセージごとに同じトピックを返すことができます。  
   次の例は、渡された各メッセージに対して同じトピックレコードsys_idを返す方法を示しています。

       // Return the same topic for all messages if your 
        // implementation only supports one kind of topic

       fetchTopicsForMessage: function(message) { 
       // Return the same sys_id for all passed messages which
       // implies that all of the messages are published to the same topic.
       return ['91564fc087f8351063151f473cbb35f8'];
       },

   次の例は、メッセージ内のイベントタイプに基づいてメッセージを送信するトピックを識別する方法を示しています。

       // Fetch the topic based on the message content. 
       // This could be based on the message domain type or the message event type.

       fetchTopicsForMessage: function(message) { 
       // Implement to return topic based on a message content
       // Implementor may decide a topic based on 'eventType' or any other attribute.

       var eventType = message.eventType;

       var topicSysIdsArr = this.fetchTopicBasedOnEventType(eventType);
       return topicSysIdsArr

       },

3. [HermesEventPublisherOOB:fetchPartionKey(オブジェクトメッセージ)](https://servicenow-prod.fluidtopics.net/ynZAgIIFBgPtw0JTx39FOQ#HEPO-fetchPartionKey_O "渡されたメッセージに関連付けられたパーティションキーを返します。") メソッドのデフォルト機能をカスタムロジックで上書きして、メッセージをHermes メッセージングサービスに公開するときに使用するパーティションキーを返します。  
   次のリストには、返されるパーティションキーのタイプと、それに関連する利点がいくつか含まれています。
   * 自動生成された一意の ID。このタイプのパーティションキーを使用すると、メッセージがトピックパーティション間で均等に公開されます。これはデフォルトの実装です。
   * メッセージイベントタイプ (またはその他のメッセージ属性) に基づく一意のキー。このタイプのパーティションキーは、そのイベントタイプ (または他のメッセージ属性) のメッセージの順序付けを保証します。
   * 同じパーティションキー。これにより、メッセージは同じパーティションに送信されます。このタイプのパーティションキーにより、Kafka コンシューマーグループレベルでメッセージの厳密な順序付けが保証されます。

   次の例は、各パーティションキーのランダム ID を返す方法を示しています。

       fetchPartionKey: function(message) { 
       // Implement it for custom partition key 
       // Random message keys ensure better distribution of message across partitions. 
       // Same message keys ensure that message always goes to the same partition.   
       // This ensures strict sequencing of messages at the Kafka consumer group level. 
       return gs.generateGUID(); 
       },

   次の例は、メッセージ内のイベントタイプに基づいてパーティションキーを返す方法を示しています。

       // Implementation where the partition key is decided based on the event type.
       fetchPartionKey: function(message) { 

       var eventType = message.eventType;
       var partionKey = fetchPartionKeyForMessage(eventType);
       return partionKey;
       },

4. [HermesEventPublisherOOB:fetchMessageHeaders(オブジェクトメッセージ)](https://servicenow-prod.fluidtopics.net/ynZAgIIFBgPtw0JTx39FOQ#HEPO-fetchMessageHeaders_O "渡されたメッセージに関連付けられたメッセージヘッダーを返します。") メソッドのデフォルト機能をカスタムロジックで上書きし、Hermes メッセージングサービスを介してメッセージを公開する前に、指定されたメッセージのヘッダーをフェッチします。  
   これらのヘッダーの詳細については、 [Apache Kafka](https://kafka.apache.org/) のドキュメントを参照してください。  
   次の例は、メッセージ内のイベントタイプに基づいてヘッダーを返す方法を示しています。

       fetchMessageHeaders: function(message) { 
       // Returned headers are based on the event type passed in the message object. 
         var eventType = message.eventType;
         var headerObject = fetchHeadersBasedOnEventType(eventType);
         return headerObject;
       },


