統合グラフ
バージョン 4.3 から、Spring Integration はアプリケーションのランタイムオブジェクトモデルへのアクセスを提供します。これには、オプションでコンポーネントメトリクスを含めることができます。グラフとして公開され、統合アプリケーションの現在の状態を視覚化するために使用できます。o.s.i.support.management.graph
パッケージには、Spring Integration コンポーネントのランタイム状態を単一のツリーのような Graph
オブジェクトとして収集、構築、レンダリングするために必要なすべてのクラスが含まれています。IntegrationGraphServer
は、Graph
オブジェクトを作成、取得、リフレッシュするために Bean として宣言する必要があります。結果の Graph
オブジェクトは任意の形式に直列化できますが、JSON はクライアント側で解析および表現するのに柔軟で便利です。デフォルトのコンポーネントのみを持つ Spring Integration アプリケーションは、次のようなグラフを公開します。
{
"contentDescriptor" : {
"providerVersion" : "6.4.1",
"providerFormatVersion" : 1.2,
"provider" : "spring-integration",
"name" : "myAppName:1.0"
},
"nodes" : [ {
"nodeId" : 1,
"componentType" : "null-channel",
"integrationPatternType" : "null_channel",
"integrationPatternCategory" : "messaging_channel",
"properties" : { },
"sendTimers" : {
"successes" : {
"count" : 1,
"mean" : 0.0,
"max" : 0.0
},
"failures" : {
"count" : 0,
"mean" : 0.0,
"max" : 0.0
}
},
"receiveCounters" : {
"successes" : 0,
"failures" : 0
},
"name" : "nullChannel"
}, {
"nodeId" : 2,
"componentType" : "publish-subscribe-channel",
"integrationPatternType" : "publish_subscribe_channel",
"integrationPatternCategory" : "messaging_channel",
"properties" : { },
"sendTimers" : {
"successes" : {
"count" : 1,
"mean" : 7.807002,
"max" : 7.807002
},
"failures" : {
"count" : 0,
"mean" : 0.0,
"max" : 0.0
}
},
"name" : "errorChannel"
}, {
"nodeId" : 3,
"componentType" : "logging-channel-adapter",
"integrationPatternType" : "outbound_channel_adapter",
"integrationPatternCategory" : "messaging_endpoint",
"properties" : { },
"output" : null,
"input" : "errorChannel",
"sendTimers" : {
"successes" : {
"count" : 1,
"mean" : 6.742722,
"max" : 6.742722
},
"failures" : {
"count" : 0,
"mean" : 0.0,
"max" : 0.0
}
},
"name" : "errorLogger"
} ],
"links" : [ {
"from" : 2,
"to" : 3,
"type" : "input"
} ]
}
バージョン 5.2 は、メトリクス管理に従って、Micrometer メーターを優先してレガシーメトリクスを廃止しました。レガシーメトリクスはバージョン 5.4 で削除され、グラフに表示されなくなります。 |
前の例では、グラフは 3 つの最上位要素で構成されています。
contentDescriptor
グラフ要素には、データを提供するアプリケーションに関する一般情報が含まれています。name
は、IntegrationGraphServer
Bean または spring.application.name
アプリケーションコンテキスト環境プロパティでカスタマイズできます。他のプロパティはフレームワークによって提供され、同様のモデルを他のソースと区別できます。
links
グラフ要素は、nodes
グラフ要素のノード間の接続を表します。ソース Spring Integration アプリケーションの統合コンポーネント間の接続を表します。例: MessageChannel
から MessageHandler
を含む EventDrivenConsumer
へ、または AbstractReplyProducingMessageHandler
から MessageChannel
へ。便宜上、リンクの目的を判断できるように、モデルには type
属性が含まれています。可能な型は次のとおりです。
input
:MessageChannel
からエンドポイント、inputChannel
、requestChannel
プロパティへの方向を識別しますoutput
:MessageHandler
、MessageProducer
、SourcePollingChannelAdapter
からoutputChannel
またはreplyChannel
プロパティを介したMessageChannel
への方向error
:PollingConsumer
またはMessageProducer
またはSourcePollingChannelAdapter
上のMessageHandler
からerrorChannel
プロパティを介してMessageChannel
へ。discard
:errorChannel
プロパティを介してDiscardingMessageHandler
(MessageFilter
など)からMessageChannel
へ。route
:AbstractMappingMessageRouter
(HeaderValueRouter
など) からMessageChannel
へ。output
に似ていますが、実行時に決定されます。おそらく、構成されたチャネルマッピングまたは動的に解決されたチャネルです。通常、ルーターはこの目的のために最大 100 個の動的ルートのみを保持しますが、dynamicChannelLimit
プロパティを設定することでこの値を変更できます。
この要素からの情報を視覚化ツールで使用して、nodes
グラフ要素のノード間の接続をレンダリングできます。from
および to
番号は、リンクされたノードの nodeId
プロパティの値を表します。例: link
要素を使用して、ターゲットノードで適切な port
を決定できます。
次の「テキストイメージ」は、型間の関連を示しています。
+---(discard) | +----o----+ | | | | | | (input)--o o---(output) | | | | | | +----o----+ | +---(error)
nodes
グラフ要素は、おそらく最も興味深いものです。その要素には、componentType
インスタンスと name
値を持つランタイムコンポーネントが含まれるだけでなく、オプションでコンポーネントによって公開されるメトリクスも含まれる可能性があるためです。ノード要素には、一般的に一目でわかるさまざまなプロパティが含まれています。例: 式ベースのコンポーネントには、コンポーネントの 1 次式文字列を含む expression
プロパティが含まれます。メトリクスを有効にするには、@EnableIntegrationManagement
を @Configuration
クラスに追加するか、<int:management/>
要素を XML 構成に追加します。詳細については、指標と管理を参照してください。
nodeId
は、あるコンポーネントと別のコンポーネントを区別できるようにする一意の増分識別子を表します。links
要素でも使用され、このコンポーネントと他のコンポーネント(ある場合)との関連(接続)を表します。input
および output
属性は、AbstractEndpoint
、MessageHandler
、SourcePollingChannelAdapter
または MessageProducerSupport
の inputChannel
および outputChannel
プロパティ用です。詳細については、次のセクションを参照してください。
バージョン 5.1 以降、IntegrationGraphServer
は、特定の NamedComponent
の IntegrationNode
に追加のプロパティを設定するために Function<NamedComponent, Map<String, Object>> additionalPropertiesCallback
を受け入れます。例: SmartLifecycle
autoStartup
、running
プロパティをターゲットグラフに公開できます。
server.setAdditionalPropertiesCallback(namedComponent -> {
Map<String, Object> properties = null;
if (namedComponent instanceof SmartLifecycle) {
SmartLifecycle smartLifecycle = (SmartLifecycle) namedComponent;
properties = new HashMap<>();
properties.put("auto-startup", smartLifecycle.isAutoStartup());
properties.put("running", smartLifecycle.isRunning());
}
return properties;
});
グラフランタイムモデル
Spring Integration コンポーネントには、さまざまなレベルの複雑さがあります。例: ポーリングされた MessageSource
には、ソースデータからメッセージを定期的に送信する SourcePollingChannelAdapter
と MessageChannel
もあります。他のコンポーネントは、メッセージ用の requestChannel
(input
)にサブスクライブ(またはポーリング)するための消費 AbstractEndpoint
と、ダウンストリームに送信するための応答メッセージを生成する replyChannel
(output
)を備えたミドルウェアのリクエスト / 応答コンポーネント(JmsOutboundGateway
など)です。一方、MessageProducerSupport
実装(ApplicationEventListeningMessageProducer
など)は、一部のソースプロトコルリスニングロジックをラップし、outputChannel
にメッセージを送信します。
グラフ内で、Spring Integration コンポーネントは、IntegrationNode
クラス階層を使用して表されます。これは、o.s.i.support.management.graph
パッケージに含まれています。例: AggregatingMessageHandler
には ErrorCapableDiscardingMessageHandlerNode
を使用でき(discardChannel
オプションがあるため)、PollingConsumer
を使用して PollableChannel
からコンシュームするときにエラーを生成できます。もう 1 つの例は CompositeMessageHandlerNode
です。EventDrivenConsumer
を使用して SubscribableChannel
にサブスクライブした場合の MessageHandlerChain
用です。
@MessagingGateway (メッセージングゲートウェイを参照)は、各メソッドにノードを提供します。name 属性は、ゲートウェイの Bean 名と短いメソッドシグネチャーに基づいています。ゲートウェイの次の例を検討してください。 |
@MessagingGateway(defaultRequestChannel = "four")
public interface Gate {
void foo(String foo);
void foo(Integer foo);
void bar(String bar);
}
前述のゲートウェイは、次のようなノードを生成します。
{
"nodeId" : 10,
"name" : "gate.bar(class java.lang.String)",
"stats" : null,
"componentType" : "gateway",
"integrationPatternType" : "gateway",
"integrationPatternCategory" : "messaging_endpoint",
"output" : "four",
"errors" : null
},
{
"nodeId" : 11,
"name" : "gate.foo(class java.lang.String)",
"stats" : null,
"componentType" : "gateway",
"integrationPatternType" : "gateway",
"integrationPatternCategory" : "messaging_endpoint",
"output" : "four",
"errors" : null
},
{
"nodeId" : 12,
"name" : "gate.foo(class java.lang.Integer)",
"stats" : null,
"componentType" : "gateway",
"integrationPatternType" : "gateway",
"integrationPatternCategory" : "messaging_endpoint",
"output" : "four",
"errors" : null
}
この IntegrationNode
階層を使用して、クライアント側でグラフモデルを解析したり、一般的な Spring Integration ランタイムの動作を理解したりできます。詳細については、プログラミングのヒントとコツも参照してください。
バージョン 5.3 は、IntegrationPattern
抽象化と、エンタープライズ統合パターン(EIP)を表すすべての標準コンポーネントを導入し、この抽象化を実装し、IntegrationPatternType
列挙値を提供します。この情報は、ターゲットアプリケーションのいくつかの分類ロジックに役立ちます。または、グラフノードに公開されているため、UI がコンポーネントの描画方法を決定するために使用できます。