gpt4 book ai didi

jms - 如何将 WildFly 连接到远程 Artemis 服务器

转载 作者:行者123 更新时间:2023-12-03 21:22:58 26 4
gpt4 key购买 nike

我有一个带有队列的独立远程 Artemis 服务器,我想配置 WildFly 以便通过 WildFly 本身连接该队列。
版本为 WildFly 12.0.0.Final 阿耳忒弥斯 2.5.0 .

在 Artemis 上,我在 中配置了一个队列broker.xml 像这样的文件:

<addresses>
<address name="DemoQueue">
<anycast>
<queue name="DemoQueue" />
</anycast>
</address>
</addresses>

然后我在 WildFly 上配置了 池连接工厂创建:
  • 一个 出站套接字绑定(bind) 指向远程消息服务器
  • 一个 远程连接器 引用出站套接字绑定(bind)
  • 一个 池连接工厂引用远程连接器

  • 我在 中的最终配置独立-full.xml 文件是这样的:
    <server>
    ...

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    ...
    <outbound-socket-binding name="remote-artemis">
    <remote-destination host="localhost" port="61616"/>
    </outbound-socket-binding>
    </socket-binding-group>

    <subsystem xmlns="urn:jboss:domain:messaging-activemq:3.0">
    <server name="default">
    ...
    <remote-connector name="remote-artemis" socket-binding="remote-artemis"/>
    <pooled-connection-factory name="remote-artemis" entries="java:/jms/RemoteArtemisCF" connectors="remote-artemis"/>
    </server>
    </subsystem>

    <subsystem xmlns="urn:jboss:domain:naming:2.0">
    <bindings>
    <external-context name="java:global/federation/remotequeue" module="org.apache.activemq.artemis" class="javax.naming.InitialContext">
    <environment>
    <property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
    <property name="java.naming.provider.url" value="tcp://localhost:61616"/>
    <property name="queue.queues/DemoQueue" value="DemoQueue"/>
    </environment>
    </external-context>
    <lookup name="java:/DemoQueue" lookup="java:global/federation/remotequeue/DemoQueue"/>
    </bindings>
    <remote-naming/>
    </subsystem>

    </server>

    如下创建消费者我无限期地收到此消息 AMQ151004: Instantiating javax.jms.Queue "DemoQueue" directly since UseJNDI=false .
    @ResourceAdapter("remote-artemis")
    @MessageDriven(mappedName = "DemoQueue",activationConfig =
    {
    @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "DemoQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
    })

    //@Component
    public class Receiver implements MessageListener {
    ...
    }

    而是创建一个传递 JNDI 名称以查找队列的消费者我收到此错误 WFLYNAM0062: Failed to lookup DemoQueue [Root exception is java.lang.RuntimeException: javax.naming.NameNotFoundException: DemoQueue] .

    这是生产者的代码:
    公共(public)类生产者{
        private Logger logger = LogManager.getLogger(this.getClass());

    @Resource(lookup="java:/jms/RemoteArtemisCF")
    private ConnectionFactory connectionFactory;

    @Resource(lookup="java:/DemoQueue")
    private Queue queue;

    public void simpleSend(String msg) {
    Connection connection = null;
    Session session = null;

    try {
    try {
    connection = connectionFactory.createConnection();
    connection.start();

    // Create a Session
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    // Create a MessageProducer from the Session to the Topic or Queue
    MessageProducer producer = session.createProducer(queue);

    // Create a message
    TextMessage message = session.createTextMessage(msg);

    // Tell the producer to send the message
    producer.send(message);
    logger.debug("Message sent");
    } finally {
    // Clean up
    if (session != null) session.close();
    if (connection != null) connection.close();
    }
    } catch (JMSException e) {
    logger.error(e.getMessage(), e);
    }
    }
    }

    谁能帮我找到正确的配置或源代码?

    提前致谢。

    最佳答案

    我认为您只需要在 Artemis broker.xml 中添加接受者的前缀即可(请注意,每个目的地都需要预先创建,就像您为 DemoQueue 所做的那样)。

    <acceptors>
    <acceptor name="artemis">tcp://localhost:61616?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.</acceptor>
    </acceptors>
    这是一个完整的 pooled-connection-factory Wildfly 中的配置 standalone-full.xml (请注意,我在这里也使用身份验证)。
    <pooled-connection-factory name="remote-artemis" entries="java:/jms/RemoteArtemisCF" connectors="remote-artemis" ha="true" transaction="xa" user="admim" password="admim" min-pool-size="15" max-pool-size="30" statistics-enabled="true">
    <inbound-config use-jndi="true" jndi-params="java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;java.naming.provider.url=tcp://localhost:61616;java.naming.security.principal=admin;java.naming.security.credentials=admin" rebalance-connections="true" setup-attempts="-1" setup-interval="5000"/>
    </pooled-connection-factory>

    关于jms - 如何将 WildFly 连接到远程 Artemis 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50331291/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com