gpt4 book ai didi

java - 从 Wildfly 13 发送消息到远程 Artemis ActiveMQ

转载 作者:行者123 更新时间:2023-12-01 06:03:18 24 4
gpt4 key购买 nike

我正在尝试将 Wildfly 13 - 实例连接到独立的 Artemis ActiveMQ 以从中生成和使用消息。因此我遵循了Wildfly 13 Documentation的相关部分和 Artemis ActiveMQ Documentation 。此外,我尝试使用 this教程并使用 JMS 2.0 Simplified-API 对其进行了一些自定义。

当我向/product 发送有效负载时,没有抛出异常。所以我认为 JNDI 存在问题。我已经使用 Wireshark 监控了正在进行的网络 Activity 并能够看到 Wildfly 和 Artemis ActiveMQ 之间的包交换。 Wildfly 不断尝试访问远程队列,但以

结束
AMQ11901 7: Queue does not exist

到目前为止,我还是不明白为什么会发生这种情况。

这是我到目前为止所拥有的:

Wildfly 配置(standalone-full-ha.xml)

//...
<outbound-socket-binding name="ImportantMessages-remote">
<remote-destination host="127.0.0.1" port="61616"/>
</outbound-socket-binding>
//...
<subsystem xmlns="urn:jboss:domain:messaging-activemq:3.0">
<server name="default">
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10" redistribution-delay="1000"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<remote-connector name="ImportantMessages-remote" socket-binding="ImportantMessages-remote"/>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<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">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<broadcast-group name="bg-group1" jgroups-cluster="activemq-cluster" connectors="http-connector"/>
<discovery-group name="dg-group1" jgroups-cluster="activemq-cluster"/>
<cluster-connection name="my-cluster" address="jms" connector-name="http-connector" discovery-group="dg-group1"/>
<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" ha="true" block-on-acknowledge="true" reconnect-attempts="-1"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
<pooled-connection-factory name="ImportantMessages-remote" entries="java:/jms/remoteIM" connectors="ImportantMessages-remote"/>
</server>
</subsystem>
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<external-context name="java:global/remoteContext" 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://127.0.0.1:61616"/>
<property name="queue.ImportantMessages" value="ImportantMessages"/>
</environment>
</external-context>
<lookup name="java:/ImportantMessages" lookup="java:global/remoteContext/ImportantMessages"/>
</bindings>
<remote-naming/>
</subsystem>

消息生产者资源

@Stateless
@Path("produce")
public class MessageProducerResource {

private static final Logger LOG = Logger.getLogger(MessageProducerResource.class.getName());

@Inject
@JMSConnectionFactory("java:/jms/remoteIM")
private JMSContext jmsContext;

@Resource(lookup = "java:global/remoteContext/ImportantMessages")
private Queue queue;

@POST
public void sendMessage(String txt) {
jmsContext.createProducer().send(queue, txt);
LOG.info("Sent message containing \"" + txt + "\" to " + queue);
}
}

我相信这些是相关的代码片段。如果您需要任何进一步的信息,请随时询问。有人遇到过类似的问题并可以帮助我吗?

最佳答案

您可能需要在 Artemis 代理上设置安全凭证,并将用户/密码添加到 pooled-connection-factory。

<pooled-connection-factory name="ImportantMessages-remote" entries="java:/jms/remoteIM" connectors="ImportantMessages-remote" user="user123" password="Password123"/>

关于java - 从 Wildfly 13 发送消息到远程 Artemis ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51892142/

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