---
schema_version: "1"
id: f425a441fe105ad4c60cc10e9b2bdcda99f0f89b290996607551139a2081a381
title: Mule サーバーの通知
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.3/mule-server-notifications.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.3/mule-server-notifications
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ff2046bb9bbba7888dfd8e3de730b5f9daacded1e34049788868efc692ee2b54
description: MuleSoft Documentation Site
release: "4.3"
latest: false
---
# Mule サーバーの通知

Mule には、フローコンポーネントの追加、認証の要求失敗、Mule の起動など、Mule サーバーで行われた変更を確認するために使用できる内部通知メカニズムがあります。こうした通知に反応するためのエージェントまたはフローコンポーネントをセットアップできます。

## [](#通知の設定)通知の設定

メッセージ通知は、Mule サーバーとの間で送信されるすべての情報のスナップショットとなります。Mule はメッセージを送受信したときにこうした通知を実行します。こうした追加の通知はパフォーマンスに影響を及ぼすため、デフォルトで無効になっています。メッセージ通知を有効にするには、Mule 設定ファイルで ​`<notifications>`​ 要素を使用して有効にするメッセージの種別を設定します。また、通知リスナーを登録してインターフェースを特定の通知に関連付けます。

たとえば、最初に Spring 設定ファイルで通知リスナーの Bean を作成し、受信する通知の種別のクラスを指定します。

```xml
<bean name="notificationLogger" class="org.myfirm.ProcessorNotificationStore"/>
```

続いて、Spring 設定の参照を追加します。

```xml
<spring:config name="springConfig" files="notification-beans.xml"/>
```

次に、​`<notification>`​ 要素を使用して受信する通知を指定し、​`<notification-listener>`​ 要素を使用してリスナーを登録します。

```xml
<notifications>
    <notification event="MESSAGE-PROCESSOR"/>
    <notification-listener ref="notificationLogger"/>
</notifications>
```

MESSAGE-PROCESSOR 通知を指定すると、通知はメッセージプロセッサーが呼び出される前と後に送信されます。リスナーは受信する通知の種別のインターフェースを実装しているため、リスナーは正しい通知を受信します。

たとえば、​`ProcessorNotificationLogger`​ クラスは ​`org.mule.runtime.api.notification.MessageProcessorNotificationListener`​ を実装します。

```java
public class ProcessorNotificationLogger implements MessageProcessorNotificationListener<MessageProcessorNotification> {

    @Override
    public void onNotification(MessageProcessorNotification notification) {
        // write here the logic to process the notification event
    }
}
```

<table><tbody><tr><td class="icon"><i class="fa icon-caution" title="Caution"></i></td><td class="content">API クラスをクラスパスで使用できるように、忘れずに ​<code>provided</code>​ をスコープとして POM ファイルで Mule と API の連動関係を追加してください。この連動関係は実行時に Mule によって提供されます。</td></tr></tbody></table>

通知種別のリストについては、​[「通知設定リファレンス」](https://docs.mulesoft.com/jp/mule-runtime/4.3/notifications-configuration-reference)​を参照してください。通知リスナーインターフェースのリストについては、下記の​[\[Notification Interfaces\]](<#Notification Interfaces>)​を参照してください。

### [](#別のインターフェースの指定)別のインターフェースの指定

通知に関連付けられたインターフェースを変更するには、​`interface-class`​ 属性で新しいインターフェースを指定します。

```xml
<notifications>
    <notification event="COMPONENT-MESSAGE" interface-class="org.myfirm.MyMessageNotifications"/>
</notifications>
```

### [](#カスタム通知の設定)カスタム通知の設定

カスタム通知を作成する場合、​`event-class`​ 属性も指定します。

```xml
<notifications>
  <notification event="CUSTOM" event-class="org.myfirm.MyMessageNotificationsCustomMessage"
  interface-class="org.myfirm.MyMessageNotifications"/>
</notifications>
```

### [](#通知の無効化)通知の無効化

特定のインターフェースが通知を受信しないようにブロックするには、​`<disable-notification>`​ 要素で指定します。ブロックする通知種別 (イベント)、イベントクラス、インターフェース、インターフェースクラスを指定できます。

```xml
<notifications>
    <disable-notification interface="SECURITY"/>
</notifications>
```

### [](#サブスクリプションの使用)サブスクリプションの使用

リスナーを登録するときに、​`subscription`​ 属性を使用して特定のコンポーネントからの通知のみを受信するように指定できます。たとえば、「MyService1」という名前のフローコンポーネントからのみ通知を受信するようにリスナーを指定するには、次のようにリスナーを設定します。

```xml
<notification-listener ref="endpointNotificationLogger" subscription="MyService1"/>

<object name="endpointNotificationLogger" class="org.myfirm.EndpointNotificationLogger"/>
```

名前に「Service」が付くすべてのフローコンポーネントからの通知の受信に登録するには、次のようにワイルドカード文字列を使用します。

<notification-listener ref="endpointNotificationLogger" subscription="\*Service\*"/>

詳細は、下記の​[\[Registering Listeners Programmatically\]](<#Registering Listeners Programmatically>)​を参照してください。

## [](#カスタム通知の実行)カスタム通知の実行

オブジェクトは Mule でカスタム通知を実行し、カスタムリスナーに通知できます。たとえば、検出エージェントはクライアントが接続したときに「Client Found (クライアントが見つかりました)」という通知を実行する場合もあります。

カスタム通知は次のように実行します。

```text
CustomNotification n = new CustomNotification("Hello");

notificationDispatcher.dispatch(n);
```

`CustomNotificationListener`​ を実装するオブジェクトがこの通知を受信します。​`CustomNotification`​ を拡張して、カスタム通知種別のアクションを定義すると良いでしょう。例:

```text
DiscoveryNotification n = new DiscoveryNotification(client, DiscoveryNotification.CLIENT_ADDED);

notificationDispatcher.dispatch(n);
```

## [](#通知インターフェース)通知インターフェース

次の表は、​`org.mule.runtime.api.notification`​ パッケージの Mule サーバー通知とインターフェースを示しています。オブジェクトは、これらのインターフェースのいずれかを実装して関連付けられた通知のリスナーになることができます。すべてのリスナーは ​`NotificationListener`​ インターフェースを拡張します。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 34%;">
<col style="width: 33%;">
<col style="width: 33%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">通知</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">インターフェース</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Connection (接続) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>接続が行われるか切断されたときに実行されます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ConnectionNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Custom (カスタム) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>コンポーネントの他、ルーター、トランスフォーマー、エージェントなどのオブジェクトによって相互の状態の変更を通信するために実行される場合があります。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>CustomNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Exception (例外) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>例外がスローされました。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ExceptionNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Management (管理) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>内部キューが容量に達するなど、Mule インスタンスまたはそのリソースの状態が変更されました。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ManagementNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule Context (Mule コンテキスト) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule コンテキストの開始などのイベントが発生したときに実行できます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>MuleContextNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Routing (ルーティング) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Async-Reply (非同期返信) ルーターは、すでに処理されたイベントグループについてイベントが受信されたときにこの通知を使用します。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>RoutingNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Security (セキュリティ) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>認証の要求が失敗したときに実行されます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>SecurityNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Transaction (トランザクション) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>トランザクションが開始された、コミットされた、ロールバックされた後に実行されます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>TransactionNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Async-Message (非同期メッセージ) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>非同期作業がスケジュールされ、指定されたフローについて完了したときに実行できます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>AsyncMessageNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Pipeline-Message (パイプラインメッセージ) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>パイプラインの処理の重要なステップで実行されます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>PipelineMessageNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Message-Processor (メッセージプロセッサー) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージプロセッサーが呼び出されました。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>MessageProcessorNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Exception Strategy (例外戦略) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>例外戦略が呼び出されました。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ExceptionStrategyNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Extension (拡張機能) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>カスタムデータを含む拡張機能によって実行できます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ExtensionNotificationListener</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Connector-Message (コネクタメッセージ) 通知</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージが受信されたかコネクタを通じて送信されたときに実行されます。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>ConnectorMessageNotificationListener</code>​</p>
</div></div></td>
</tr>
</tbody>
</table>

リスナーインターフェースにはすべて単一のメソッドがあります。

```java
public void onNotification(T notification);
```

ここで、T は通知クラスです (末尾に「Listener」が付かないリスナークラス)。

実装されているリスナーに応じて、特定の通知のみが受信されます。たとえば、オブジェクトで ​`ManagementNotificationListener`​ が実装されている場合、種別 ​`ManagementNotification`​ の通知のみが受信されます。オブジェクトは複数のリスナーを実装して複数の種別の通知を受信できます。

## [](#プログラムでのリスナーの登録)プログラムでのリスナーの登録

リスナーは次のように登録できます。

notificationListenerRegistry.registerListener(listener);

または

notificationListenerRegistry.registerListener(listener, selector);

ここで、​`listener`​ は ​`NotificationListener<N>`​ インスタンスであり、​`selector`​ はリスナーをコールする前に実行された通知に適用する検索条件として機能する ​`Predicate<N>`​ です。

## [](#通知アクションコード)通知アクションコード

各通知には、通知種別を決定するアクションコードがあります。アクションコードを問い合わせて、その種別を決定することができます。例:

**MyObject.java**

```java
public class MyObject implements ConnectionNotificationListener<ConnectionNotification> {

    (...)

    public void onNotification(ConnectionNotification notification) {

        if (valueOf(ConnectionNotification.CONNECTION_FAILED).equals(notification.getAction().getIdentifier())) {

            // write here the logic to handle the connection failed notification
        }
     }
}
```

## [](#通知ペイロード)通知ペイロード

すべての通知は ​`java.util.EventObject`​ を拡張し、​`getSource()`​ メソッドを使用してオブジェクトのペイロードにアクセスできます。次の表で、通知の各種別のペイロードについて説明します。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Notification (通知)</th>
<th class="tableblock halign-left valign-top">ペイロード種別</th>
<th class="tableblock halign-left valign-top">リソース ID</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Connection (接続) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String (文字列)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>&lt;connector-name&gt;.receiver(&lt;endpoint-uri&gt;)</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">接続されたメッセージレシーバーまたはメッセージディスパッチャー。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Custom (カスタム) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">任意のオブジェクト</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">任意の String (文字列)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">オブジェクト種別は通知を実行したオブジェクトに対してカスタムです。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Exception (例外) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ComponentLocation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コンポーネント名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">通知をトリガーしたフローコンポーネント。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Management (管理) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Object (オブジェクト)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">オブジェクト ID</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">この通知をトリガーした監視対象オブジェクト。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mule Context (Mule コンテキスト) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">MuleContext</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mule コンテキスト ID</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mule コンテキストインスタンス。getMuleContext() のコールと同じ。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Routing (ルーティング) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Message (メッセージ)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">メッセージ ID</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">送信または受信されたメッセージ。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Security (セキュリティ) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">SecurityException</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">例外メッセージ。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">発生したセキュリティ例外。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Transaction (トランザクション) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String (文字列)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">トランザクション ID</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">この通知をトリガーしたトランザクション。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Async-Message (非同期メッセージ) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ComponentLocation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コンポーネント名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">非同期作業をスケジュールしたコンポーネント。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Pipeline-Message (パイプラインメッセージ) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String (文字列)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name (名前)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">パイプライン名。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Message-Processor (メッセージプロセッサー) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ComponentLocation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コンポーネント名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">通知をトリガーしたフローコンポーネント。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Exception Strategy (例外戦略) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ComponentLocation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コンポーネント名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">通知をトリガーしたフローコンポーネント。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Extension (拡張機能) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Object (オブジェクト)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Extension name (拡張名)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ペイロードは拡張機能ごとに変更できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Connector-Message (コネクタメッセージ) 通知</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ComponentLocation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コンポーネント名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">通知をトリガーしたフローコンポーネント。</p></td>
</tr>
</tbody>
</table>