31.2. リモート接続の統合された Artemis リソースアダプターの使用
JBoss EAP には、統合 ActiveMQ Artemis メッセージングサーバーに接続するためのリソースアダプターが含まれています。デフォルトで、messaging-activemq
サブシステムに定義された pooled-connection-factory
はアダプターを使用して接続を確立します。ただし、同じリソースアダプターを使用して、JBoss EAP のリモートインスタンス内で実行している Artemis サーバーへの接続も確立できます。
messaging-activemq
サブシステムにデフォルトで設定されている activemq-ra
のプールされた接続ファクトリーには、java:jboss/DefaultJMSConnectionFactory
エントリーが割り当てられます。このエントリーは messaging-activemq
サブシステムに必要です。activemq-ra
のプールされた接続ファクトリーを削除する場合は、このエントリーを別の接続ファクトリーに割り当てる必要があります。そうしないと、デプロイメントのサーバーログに以下のエラーが表示されます。
WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.DefaultJMSConnectionFactory"]
WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.DefaultJMSConnectionFactory"]
JBoss EAP のリモートインスタンス内で実行している Artemis サーバーに接続するには、以下の手順に従って新しい pooled-connection-factory
を作成します。
リモートメッセージングサーバーを指す outbound-socket-binding を作成します。
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-server:add(host=<server host>, port=8080)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-server:add(host=<server host>, port=8080)
Copy to Clipboard Copied! 手順 1 で作成した outbound-socket-binding を参照する remote-connector を作成します。
/subsystem=messaging-activemq/server=default/http-connector=remote-http-connector:add(socket-binding=remote-server,endpoint=http-acceptor)
/subsystem=messaging-activemq/server=default/http-connector=remote-http-connector:add(socket-binding=remote-server,endpoint=http-acceptor)
Copy to Clipboard Copied! 手順 2 で作成した remote-connector を参照する pooled-connection-factory を作成します。
/subsystem=messaging-activemq/server=default/pooled-connection-factory=remote-artemis:add(connectors=[remote-http-connector], entries=[java:/jms/remoteCF])
/subsystem=messaging-activemq/server=default/pooled-connection-factory=remote-artemis:add(connectors=[remote-http-connector], entries=[java:/jms/remoteCF])
Copy to Clipboard Copied! 注記Artemis 1.x では、宛先名の接頭辞が必要でした (トピックの場合は jms.topic、キューの場合は jms.queue)。Artemis 2.x では接頭辞は必要ありませんが、Artemis 1.x との互換性のために、EAP は引き続き接頭辞を追加し、互換性モードで実行するように Artemis に指示します。リモート Artemis 2.x サーバーに接続する場合は、互換性モードではなく、接頭辞は不要になる可能性があります。接頭辞なしで宛先を使用する場合は、
enable-amq1-prefix
属性を false に設定して、接頭辞を含まないように接続ファクトリーを設定できます。
MDB を pooled-connection-factory を使用するように設定する
pooled-connection-factory
をリモート Artemis サーバーに接続するよう設定した後、リモートサーバーからメッセージを読み取るメッセージ駆動 Bean (MDB) では、pooled-connection-factory
リソースの名前を使用して @ResourceAdapter
アノテーションを付加する必要があります。
import org.jboss.ejb3.annotation.ResourceAdapter; @ResourceAdapter("remote-artemis") @MessageDriven(name = "MyMDB", activationConfig = { ... }) public class MyMDB implements MessageListener { public void onMessage(Message message) { ... } }
import org.jboss.ejb3.annotation.ResourceAdapter;
@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = { ... })
public class MyMDB implements MessageListener {
public void onMessage(Message message) {
...
}
}
MDB がリモートサーバーにメッセージを送信する必要がある場合は、JNDI エントリー
の 1 つを使用して検索することにより、pooled-connection-factory
を挿入する必要があります。
@Inject @JMSConnectionFactory("java:/jms/remoteCF") private JMSContext context;
@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;
JMS 宛先の設定
MDB は、メッセージを消費する宛先も指定する必要があります。これを実行するための標準的な方法は、ローカルサーバーの JNDI ルックアップに対応する destinationLookup
アクティベーション設定プロパティーを定義することです。
@ResourceAdapter("remote-artemis") @MessageDriven(name = "MyMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "myQueue"), ... }) public class MyMDB implements MessageListener { ... }
@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "myQueue"),
...
})
public class MyMDB implements MessageListener {
...
}
ローカルサーバーにリモート Artemis サーバーの JNDI バインディングが含まれない場合は、destination
アクティベーション設定プロパティーを使用して、リモート Artemis サーバーに設定されているように宛先の名前を指定し、useJNDI
アクティベーション設定プロパティーを false
に設定します。これは、JNDI ルックアップを必要とせずに JMS 宛先を自動的に作成するように Artemis リソースアダプターに指示します。
@ResourceAdapter("remote-artemis") @MessageDriven(name = "MyMDB", activationConfig = { @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"), ... }) public class MyMDB implements MessageListener { ... }
@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"),
...
})
public class MyMDB implements MessageListener {
...
}
上記の例では、アクティベーション設定プロパティーは、リモート Artemis サーバーでホストされている myQueue
という名前の JMS キューからメッセージを消費するように MDB を設定します。ほとんどの場合、MDB は、消費されたメッセージを処理するために他の宛先をルックアップする必要がなく、メッセージに定義されている場合は、JMSReplyTo
宛先を使用できます。
MDB でリモートサーバーに定義された他の JMS 宛先が必要な場合は、クライアント側 JNDI を使用する必要があります。詳細は、サーバーへの接続 を参照してください。