如何将 WildFly 连接到远程 Artemis 服务器
Posted
技术标签:
【中文标题】如何将 WildFly 连接到远程 Artemis 服务器【英文标题】:How to connect WildFly to a Remote Artemis Server 【发布时间】:2018-10-24 04:06:32 【问题描述】:我有一个带有队列的独立远程 Artemis 服务器,我想配置 WildFly 以便通过 WildFly 本身连接该队列。 版本为 WildFly 12.0.0.Final 和 Artemis 2.5.0。
在 Artemis 上,我在 broker.xml 文件中配置了一个队列,如下所示:
<addresses>
<address name="DemoQueue">
<anycast>
<queue name="DemoQueue" />
</anycast>
</address>
</addresses>
然后我在 WildFly 上配置了一个 pooled-connection-factory 创建:
一个outbound-socket-binding指向远程消息服务器 一个 remote-connector 引用 outbound-socket-binding 一个 pooled-connection-factory 引用远程连接器我在 standalone-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]
。
这是生产者的代码: 公共类生产者
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);
谁能帮我找到正确的配置或源代码?
提前致谢。
【问题讨论】:
您找到解决方案了吗? 不,我没有找到解决办法 【参考方案1】:我认为您只需要在 Artemis broker.xml
中添加接受者的前缀(请注意,每个目的地都需要预先创建,就像您为 DemoQueue
所做的那样)。
<acceptors>
<acceptor name="artemis">tcp://localhost:61616?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.</acceptor>
</acceptors>
这是 Wildfly standalone-full.xml
中完整的 pooled-connection-factory
配置(注意我这里也使用了身份验证)。
<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>
【讨论】:
以上是关于如何将 WildFly 连接到远程 Artemis 服务器的主要内容,如果未能解决你的问题,请参考以下文章
如何将 JMS 消息从 WildFly 10 发送到远程 ActiveMQ
如何使用 ActiveMQ Artemis 在 Wildfly 24 服务上配置 jms-queue