来自远程 ActiveMQ Artemis 的 Wildfly JMS Consumer
我正在尝试在 Wildfly(版本 24)和远程 ActiveMQ Artemis 代理中实现简单的 JMS 生产者和消费者。
standalone.xml
<subsystem xmlns="urn:jboss:domain:messaging-activemq:13.0">
<remote-connector name="remote-artemis" socket-binding="remote-artemis"/>
<pooled-connection-factory
name="remote-artemis"
entries="java:/jms/remoteCF"
connectors="remote-artemis"
client-id="producer-pooled-connection-factory"
user="${artemismq.user}"
password="${artemismq.password}"
enable-amq1-prefix="true"
/>
<external-jms-queue name="testQueue" entries="java:/queue/testQueue"/>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
<socket-binding name="http" port="${jboss.http.port:8080}"/>
<socket-binding name="https" port="${jboss.https.port:8443}"/>
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="${jboss.mail.server.host:localhost}" port="${jboss.mail.server.port:25}"/>
</outbound-socket-binding>
<outbound-socket-binding name="remote-artemis">
<remote-destination host="${artemismq.host}" port="${artemismq.port}"/>
</outbound-socket-binding>
</socket-binding-group>
生产者和消费者
@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;
@Resource(lookup = "java:/queue/testQueue")
private Queue queue;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
try {
out.write("<p>Sending messages to <em>" + queue + "</em></p>");
out.write("<p>Using context <em>" + context + "</em></p>");
out.write("<h2>The following messages will be sent to the destination:</h2>");
for (int i = 0; i < MSG_COUNT; i++) {
String text = "This is message " + (i + 1);
context.createProducer().send(queue, text);
out.write("Message (" + i + "): " + text + "</br>");
JMSConsumer consumer = context.createConsumer(queue);
TextMessage message = (TextMessage) consumer.receive();
out.write("Message received (" + i + "): " + message.getText() + "</br>");
}
} catch (JMSException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
杂项: 制作人独自工作。
结果: 代理收到第一条消息,但消费未执行并且没有任何反应(没有日志)。
I am trying to implement simple JMS Producer and Consumer within Wildfly(Version 24) and remote ActiveMQ Artemis broker.
standalone.xml
<subsystem xmlns="urn:jboss:domain:messaging-activemq:13.0">
<remote-connector name="remote-artemis" socket-binding="remote-artemis"/>
<pooled-connection-factory
name="remote-artemis"
entries="java:/jms/remoteCF"
connectors="remote-artemis"
client-id="producer-pooled-connection-factory"
user="${artemismq.user}"
password="${artemismq.password}"
enable-amq1-prefix="true"
/>
<external-jms-queue name="testQueue" entries="java:/queue/testQueue"/>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
<socket-binding name="http" port="${jboss.http.port:8080}"/>
<socket-binding name="https" port="${jboss.https.port:8443}"/>
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="${jboss.mail.server.host:localhost}" port="${jboss.mail.server.port:25}"/>
</outbound-socket-binding>
<outbound-socket-binding name="remote-artemis">
<remote-destination host="${artemismq.host}" port="${artemismq.port}"/>
</outbound-socket-binding>
</socket-binding-group>
Producer and Consumer
@Inject
@JMSConnectionFactory("java:/jms/remoteCF")
private JMSContext context;
@Resource(lookup = "java:/queue/testQueue")
private Queue queue;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
try {
out.write("<p>Sending messages to <em>" + queue + "</em></p>");
out.write("<p>Using context <em>" + context + "</em></p>");
out.write("<h2>The following messages will be sent to the destination:</h2>");
for (int i = 0; i < MSG_COUNT; i++) {
String text = "This is message " + (i + 1);
context.createProducer().send(queue, text);
out.write("Message (" + i + "): " + text + "</br>");
JMSConsumer consumer = context.createConsumer(queue);
TextMessage message = (TextMessage) consumer.receive();
out.write("Message received (" + i + "): " + message.getText() + "</br>");
}
} catch (JMSException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
Misc:
Producer alone works.
Result:
First message is received by broker but consumption is not executed and nothing happens(no logs).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于
pooled-connection-factory
文档说:您应该创建一个“正常”
connection-factory
供您的消费者使用,例如:或者通过 JBoss CLI:
然后在您的代码中您可以执行如下操作:
如果您需要设置凭证注入的
JMSContext
然后您可以使用@JMSPasswordCredential
。Regarding the
pooled-connection-factory
the documentation says:You should create a "normal"
connection-factory
for your consumer to use, e.g.:Or via the JBoss CLI:
Then in your code you could do something like the following:
If you need to set credentials on the injected
JMSContext
then you can annotate it with@JMSPasswordCredential
.