このコンテンツは選択した言語では利用できません。

A.4. Content-based Router


Overview

A content-based router enables you to route messages to the appropriate destination, where the routing decision is based on the message contents. This pattern maps to the corresponding content-based router pattern in Apache Camel.

Figure A.1. Content-based Router Pattern

Content-based router pattern

Example ServiceMix EIP route

Example A.1, “ServiceMix EIP Content-based Route” shows how to define a content-based router using the ServicMix EIP component. If a test:echo element is present in the message body, the message is routed to the http://test/pipeline/endpoint endpoint. Otherwise, the message is routed to the test:recipients endpoint.

Example A.1. ServiceMix EIP Content-based Route

<eip:content-based-router service="test:router" endpoint="endpoint">
  <eip:rules>
    <eip:routing-rule>
      <eip:predicate>
        <eip:xpath-predicate xpath="count(/test:echo) = 1" namespaceContext="#nsContext" />
      </eip:predicate>
      <eip:target>
        <eip:exchange-target uri="endpoint:test:pipeline:endpoint" />
      </eip:target>
    </eip:routing-rule>
    <eip:routing-rule>
      <!-- There is no predicate, so this is the default destination -->
      <eip:target>
        <eip:exchange-target service="test:recipients" />
      </eip:target>
    </eip:routing-rule>
  </eip:rules>
</eip:content-based-router>

Equivalent Apache Camel XML route

Example A.2, “Apache Camel Content-based Router Using XML Configuration” shows how to define an equivalent route using Apache Camel XML configuration.

Example A.2. Apache Camel Content-based Router Using XML Configuration

<route>
  <from uri="jbi:endpoint:http://progress.com/demos/test/router/endpoint"/>
  <choice>
    <when>
      <xpath>count(/test:echo) = 1</xpath>
      <to uri="jbi:endpoint:http://progress.com/demos/test/pipeline/endpoint"/>
    </when>
    <otherwise>
      <!-- This is the default destination -->
      <to uri="jbi:service:http://progress.com/demos/test/recipients"/>
    </otherwise>
  </choice>
</route>

Equivalent Apache Camel Java DSL route

Example A.3, “Apache Camel Content-based Router Using Java DSL” shows how to define an equivalent route using the Apache Camel Java DSL.

Example A.3. Apache Camel Content-based Router Using Java DSL

from("jbi:endpoint:http://progress.com/demos/test/router/endpoint").
    choice().when(xpath("count(/test:echo) = 1")).to("jbi:endpoint:http://progress.com/demos/test/pipeline/endpoint").
    otherwise().to("jbi:service:http://progress.com/demos/test/recipients");
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.