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"]
Copy to Clipboard Toggle word wrap

若要连接在 JBoss EAP 远程实例中运行的 Artemis 服务器,请 按照以下步骤创建新的 pooled-connection-factory

  1. 创建一个指向远程消息传递服务器的出站套接字绑定:

    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-server:add(host=<server host>, port=8080)
    Copy to Clipboard Toggle word wrap
  2. 创建远程连接器,引用在第 1 步中创建的 outbound-socket-binding。

    /subsystem=messaging-activemq/server=default/http-connector=remote-http-connector:add(socket-binding=remote-server,endpoint=http-acceptor)
    Copy to Clipboard Toggle word wrap
  3. 创建一个 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])
    Copy to Clipboard Toggle word wrap
    注意

    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 注释。

import org.jboss.ejb3.annotation.ResourceAdapter;

@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = { ... })
public class MyMDB implements MessageListener {
    public void onMessage(Message message) {
       ...
    }
}
Copy to Clipboard Toggle word wrap

如果 MDB 需要发送消息到远程服务器,则必须使用其中一个 JNDI 条目 查找 pooled-connection-factory 来注入 pooled-connection-factory。

@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;
Copy to Clipboard Toggle word wrap

配置 Jakarta 消息传递目的地

MDB 还必须指定它将使用消息的目的地。执行此操作的标准方法是定义与本地服务器上的 JNDI 查找对应的 destinationLookup 激活配置属性。

@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "myQueue"),
    ...
})
public class MyMDB implements MessageListener {
    ...
}
Copy to Clipboard Toggle word wrap

如果本地服务器不为远程 Artemis 服务器包含 JNDI 绑定,请指定目的地名称,如远程 Artemis 服务器中配置,使用 目标 激活配置属性,并将 useJNDI 激活配置属性设置为 false。这指示 Artemis 资源适配器自动创建 Jakarta 消息目的地,而无需查找 JNDI。

@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"),
    ...
})
public class MyMDB implements MessageListener {
    ...
}
Copy to Clipboard Toggle word wrap

在上例中,激活配置属性将 MDB 配置为使用来自远程 Artemis 服务器上托管的名为 myQueue 的 Jakarta Messaging Queue 的消息。在大多数情况下,MDB 不需要查找其他目的地来处理已使用的消息,如果消息上定义了 JMSReplyTo 目标,它也可使用它。

如果 MDB 需要远程服务器上定义的任何其他 Jakarta 消息传递目的地,则必须使用客户端 JNDI。如需更多信息 ,请参阅 连接到服务器

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat