22 トピックの構成例

必要に応じて使用または変更できる一連のサンプル・トピック・スキーム定義を確認することで、Coherenceトピックの構成方法を学習します。トピックの構成方法の詳細は、「トピックの構成」を参照してください。

この章の内容は次のとおりです。

恒久サブスクライバ・グループの定義

次の例は、topicWithDurableSubscriptionトピックに恒久サブスクライバ・グループdurable-subscriptionを静的に構成する方法を示しています。トピックに対してサブスクライバ・グループを定義しないか、1つまたは多数定義できます。topicWithDurableSubscriptionにパブリッシュされたすべての値は、このサブスクライバ・グループに対して蓄積されます。
<topic-mapping>
  <topic-name>topicWithDurableSubscription</topic-name>
  <scheme-name>topic-scheme</scheme-name>
  <value-type>java.lang.String</value-type>
  <subscriber-groups>
    <subscriber-group>
      <name>durable-subscription</name>
    </subscriber-group>
  </subscriber-groups>
</topic-mapping>

ノート:

トピックにパブリッシュされた各値は、すべてのサブスクライバ/サブスクライバ・グループが値を使用するまで保持されるため、サブスクライバ・グループをアクティブに管理することが重要です。静的に構成されたサブスクライバ・グループが不要になった場合は、topic-mapping構成ファイルから削除します。静的に構成および動的に作成されるサブスクライバ・グループのライフ・サイクルは、サブスクライバ・グループのリストサブスクライバ・グループの破棄の説明に従って管理する必要があります。

トピックに保持される値に使用される記憶域に対する値の有効期限と上限の構成

次の例では、paged-topic-scheme要素をパラメータ化して、topic-mappingユーザー定義パラメータ・マクロを使用して構成できるようにする方法を示します。

cache-mappingとともにこの機能を使用する方法の詳細は、「ユーザー定義パラメータ・マクロの使用」を参照してください。同じ使用モデルがtopic-mappingに適用されます。

次の例では、paged-topic-scheme.configurable-topic-scheme.expiry-delayにユーザー定義パラメータのマクロ・デフォルト値0が設定されています。したがって、トピック値のデフォルトの有効期限が失効することはありません。デフォルトのhigh-unitsユーザー定義パラメータ・マクロ値は0Bです。したがって、参照元のtopic-mappingexpiry-delayおよびhigh-unitsパラメータを明示的に定義していないかぎり、paged-type-scheme.configurable-topic-schemeの記憶域制限はありません。この例では、topic-mapping.initial-paramsexpiry-delayhigh-unitsの両方をオーバーライドします。

例22-1 ユーザー定義パラメータ・マクロを使用したpaged-topic-schemeの構成

<cache-config>
   <topic-mapping-schemes>
     <topic-mapping>
        <name>topic</name>
        <scheme>configurable-topic-scheme</scheme>
        <initial-params>
          <init-param>
            <param-name>high-units</param-name>
            <param-value>2G<param-value>
          </init-param>
          <init-param>
            <param-name>expiry-delay</param-name>
            <param-value>12h<param-value>
          </init-param>
        </initial-params>
     <topic-mapping>
   <topic-mapping-scheme>
   <caching-schemes>
     <paged-topic-scheme>
       <scheme-name>configurable-topic-scheme</scheme-name>
       <service-name>DistributedTopicService</service-name>
       <storage>on-heap</storage>
       <expiry-delay>{expiry-delay 0}</expiry-delay>
       <high-units>{high-units 0B}</high-units>
    </paged-topic-scheme>
   <caching-schemes>
</cache-config>

永続トピックの構成

トピックに対して永続性が有効化されており、クラスタ全体が再起動される場合、永続性リカバリ操作中に、サブスクライバおよびサブスクライバ・グループのトピックで未処理の未使用値がリカバリされます。

永続トピックの構成を有効にする構成の例を次に示します。

例22-2 同じトピック・スキームを使用した一時的および永続的なtopic-mappingの構成

<cache-config>
   <topic-mapping-schemes>
     <topic-mapping>
        <name>persistent-topic-*</name>
        <scheme>persistent-topic-scheme</scheme>
     <topic-mapping>
     <topic-mapping>
        <name>transient-topic-*</name>
        <scheme>persistent-topic-scheme</scheme>
	  <initial-params>
          <initial-param>
            <param-name>transient</param-name>
            <param-value>true</param-value>
          </initial-param>
         </initial-params>
     <topic-mapping>
   <topic-mapping-scheme>
   <caching-schemes>
     <paged-topic-scheme>
       <scheme-name>persistent-topic-scheme</scheme-name>
       <service-name>DistributedTopicService</service-name>
       <storage>on-heap</storage>
       <transient>{transient false}</transient>
       <persistence>
         <environment>default-active</environment>
       </persistence>
       <partitioned-quorum-policy-scheme>
	   <recover-quorum>{recover-quorum 0}</recover-quorum>
       <partitioned-quorum-policy-scheme>
       <autostart>true</autostart>
       <expiry-delay>{expiry-delay 0}</expiry-delay>
       <high-units>{high-units 0B}</high-units>
     </paged-topic-scheme>
   <caching-schemes>
</cache-config>

例22-2では、接頭辞persistent-topic-で始まるすべてのトピック名が永続トピックです。接頭辞transient-topic-で始まるすべてのトピック名は一時的なトピックです。paged-topic-schemeのサブ要素transientfalseで、persistence.environmentが定義されている場合、そのトピックは永続的です。transientサブ要素がtrueに設定されている場合、クラスタの完全再起動時の永続性リカバリ操作中、トピックの未使用の値はリカバリされません。この例では、事前定義済の永続性環境default-activeの1つを、paged-topic-scheme.persistence.environmentの値として使用しています。詳細は、「事前定義済の永続性環境の概要」を参照してください。recover-quorumサブ要素の構成については、「永続性リカバリでのクォーラムの使用」を参照してください。topic-mapping.initial-paramrecover-quorumに値が指定されていない場合、デフォルトの0を指定すると、「動的リカバリ・クォーラム・ポリシーの使用」の事前定義値が使用されます。