我有一个带有队列的独立远程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上配置了一个汇集连接工厂创建:
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);
}
}
}
有人可以帮我找到合适的配置或源代码吗?
提前致谢。
答案 0 :(得分:0)
我认为您只需要在 Artemis broker.xml
中添加接受者的前缀(请注意,每个目的地都需要预先创建,就像您为 DemoQueue
所做的那样)。
<acceptors>
<acceptor name="artemis">tcp://localhost:61616?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.</acceptor>
</acceptors>
这是 Wildfly pooled-connection-factory
中的完整 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>