31.2. 使用集成 Artemis 资源适配器远程连接
					JBoss EAP 包括一个资源适配器,可用于连接其集成的 ActiveMQ Artemis 消息服务器。默认情况下,messaging-  使用适配器来进行连接。但是,您也可以使用相同的资源适配器来连接在 JBoss EAP 远程实例中运行的 Artemis 服务器。
				activemq 子系统中定义的 pooled- connection-factory
						在  池连接工厂分配有 messaging-activemq 子系统中默认配置的 activemq- rajava: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 :
				
- 创建一个指向远程消息传递服务器的出站套接字绑定: - /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! - Toggle word wrap Toggle overflow 
- 创建远程连接器,引用在第 1 步中创建的 outbound-socket-binding。 - /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! - Toggle word wrap Toggle overflow 
- 创建一个 pooled-connection-factory,引用在第 2 步中创建的 remote-connector。 - /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! - Toggle word wrap Toggle overflow 注意- 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 服务器后,必须先使用 pooled-connection-factory 资源的名称为来自远程服务器的 Message-Driven Beans (MDB)注释掉 @ResourceAdapter 注释。
				
					如果 MDB 需要发送消息到远程服务器,则必须使用其中一个 JNDI 条目 查找 pooled-connection-factory 来注入 pooled-connection-factory。
				
@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;
@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;配置 Jakarta 消息传递目的地
					MDB 还必须指定它将使用消息的目的地。执行此操作的标准方法是定义与本地服务器上的 JNDI 查找对应的 destinationLookup 激活配置属性。
				
					如果本地服务器不为远程 Artemis 服务器包含 JNDI 绑定,请指定目的地名称,如远程 Artemis 服务器中配置,使用 目标 激活配置属性,并将 useJNDI 激活配置属性设置为 false。这指示 Artemis 资源适配器自动创建 Jakarta 消息目的地,而无需查找 JNDI。
				
					在上例中,激活配置属性将 MDB 配置为使用来自远程 Artemis 服务器上托管的名为 myQueue 的 Jakarta Messaging Queue 的消息。在大多数情况下,MDB 不需要查找其他目的地来处理已使用的消息,如果消息上定义了 JMSReplyTo 目标,它也可使用它。
				
如果 MDB 需要远程服务器上定义的任何其他 Jakarta 消息传递目的地,则必须使用客户端 JNDI。如需更多信息 ,请参阅 连接到服务器。