在互联网上摸索了这么多之后,令人惊讶的是,我找不到使用带有 ActiveMQ (Artemis) 的 WildFly 10 中的 JMS 推送到远程消息队列的示例配置。更糟糕的是,这种情况standalone-full.xml
并没有绑定到模式(为什么???),当我终于在 GitHub 上找到了它的 XSD 时,它没有包含说明每个节点/属性的含义以及可以放入什么值的文档。
下面是来自standalone-full.xml 的原始配置。
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
<security-setting name="#">
<role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>
</security-setting>
<address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>
<http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>
<http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">
<param name="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0"/>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
</server>
</subsystem>
下面是我的 CDI 队列客户端,它能够将消息发布到 WildFly 中的本地 Artemis 实例。
@ApplicationScoped
public class QueueClient {
private static final Gson GSON = new Gson();
@Resource(mappedName = "java:jboss/DefaultJMSConnectionFactory")
private ConnectionFactory connectionFactory;
public void sendMessage(String destinationName, Object message) throws JMSException {
try (Connection conn = connectionFactory.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
Queue queue = session.createQueue(destinationName);
final Message consignment = session.createMessage();
consignment.setStringProperty("MEDIA_TYPE", "application/json");
consignment.setStringProperty("BODY", GSON.toJson(message));
session.createProducer(queue).send(consignment);
}
}
}
我的目标:将消息发布到远程ActiveMQ 实例。
我所拥有的:server url
、、topic name
和。username
password
我的问题:如何修改配置以实现此目标?
替代问题:如果无法回答上述问题,我该如何实现这个目标?
谢谢!