野蝇14 + 无法在 vm 队列中查找



无法通过 ConnectionFactory 查找 invm 队列

Hashtable<String, Object> properties = new Hashtable<>();
properties.put("connectionFactory.ConnectionFactory", "(tcp://localhost:8080)?httpUpgradeEnabled=true&retryInterval=3000&reconnectAttempts=-1&initialConnectAttempts=10&maxRetryInterval=3000&clientFailureCheckPeriod=1000");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
InitialContext jndiContext = new InitialContext(properties);
ConnectoryFactory connFactory = (ConnectionFactory) jndiContext.lookup(connectionFactory);
Connection connection = connFactory.createConnection(userName, password);
session = connection.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE);
Hashtable<String, Object> properties = new Hashtable<>();
properties.put(Context.INITIAL_CONTEXT_FACTORY, factoryInitial);
InitialContext ctx = new InitialContext(properties);
destination = (Destination) ctx.lookup("dynamicQueues/TestQueue"); //I can't put queue name in jndi.properties
MessageProducer producer = session.createProducer(destination);
producer.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, msgTTL);
if (session.getTransacted() && session.getAcknowledgeMode() == Session.SESSION_TRANSACTED) {
   session.commit();
}

当我执行上面的代码时,它会抛出错误,指出队列"测试队列"不存在。我尝试过使用动态队列/测试队列和 jms/TestQueue 的查找队列,但在这两种情况下我都遇到了相同的错误

你能告诉我这个代码有什么问题吗?

请在下面找到Wildfly ActiveMQ Artemis配置

<server name="default" persistence-enabled="true">
    <cluster password="${jboss.messaging.cluster.password:CHANGE ME!!}"/>
    <bindings-directory path="/opt/shared/messaging/live/bindings"/>
    <journal-directory path="/opt/shared/messaging/live/journal"/>
    <large-messages-directory path="/opt/shared/messaging/live/largemessages"/>
    <paging-directory path="/opt/shared/messaging/live/paging"/>
    <security-setting name="#">
        <role name="guest" send="true" consume="true" create-durable-queue="true" delete-durable-queue="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" redelivery-delay="60000" max-delivery-attempts="5" max-size-bytes="50485760" page-size-bytes="10485760" address-full-policy="PAGE" 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>
    <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"/>
    <jms-queue name="TestQueue" entries="java:/jms/TestQueue java:jboss/exported/jms/TestQueue"/>
    <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"/>
</server>

我只想与您分享一些链接,以便进一步阅读。

如果开始使用 wildfly 进行开发,则快速入门是一个很好的切入点。

这里有一个外部客户端示例:https://github.com/wildfly/quickstart/tree/14.x/helloworld-jms

在这里,它的所有内容都在野蝇容器内运行:https://github.com/wildfly/quickstart/tree/14.x/helloworld-mdb

这里有关于野蝇 14 中消息传递的一般文档:https://docs.wildfly.org/14/Admin_Guide.html#Messaging

您正在使用的初始上下文工厂(即 org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory(是一个客户端的JNDI实现,用于独立的ActiveMQ Artemis。由于您使用的是 Wildfly,因此您应该使用他们的 JNDI 实现(即 org.wildfly.naming.client.WildFlyInitialContextFactory (。然后,可以从 Wildfly 服务器查找连接工厂和目标,而无需在代码中指定连接工厂 URL。

此外,没有"invm 队列"这样的东西。

相关内容

  • 没有找到相关文章

最新更新