无法从Tomcat webapp连接到Wildfly上的ActiveMQ

时间:2017-01-20 12:54:04

标签: java tomcat activemq wildfly

我在Wildfly 10中运行ActiveMQ。我可以在Wildfly Java EE应用程序和独立的Java应用程序中生成和使用消息。但我无法从Tomcat应用程序(这是我需要的)连接到ActiveMQ

Wildfly standalone.xml中的ActiveMQ模块如下所示:

   <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.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"/>
            <http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
            <http-connector name="bridge-connector" socket-binding="messaging-remote" endpoint="bridge-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"/>
            <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"/>
            <jms-topic name="MjopTopic" entries="topic/MjopTopic java:/jms/topic/MjopTopic java:/jboss/exported/jms/topic/MjopTopic"/>
            <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" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
        </server>
    </subsystem>

从Tomcat webapp中连接的代码如下所示:

static final String PROVIDER_URL = "http-remoting://127.0.0.1:18080";
static final String CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
static final String DESTINATION = "jms/topic/MjopTopic";

final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, PROVIDER_URL);
env.put(Context.SECURITY_PRINCIPAL, "jmsuser");
env.put(Context.SECURITY_CREDENTIALS, "v13wp01nt*");
env.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");
Context namingContext = new InitialContext(env);

ConnectionFactory cf = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
Topic topic = (Topic) namingContext.lookup(DESTINATION);
JMSContext context = cf.createContext("jmsuser", "v13wp01nt*");

JMSConsumer consumer = context.createSharedDurableConsumer(topic, "vp5");
consumer.setMessageListener(new VPMessageListener());

我从第ConnectionFactory cf = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY)行获得了下一个例外。

  

javax.naming.NamingException:无法调用lookup,status = WAITING

编辑:

我已经在webapp中更改了maven依赖项。

   <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>javax.jms-api</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-remote-naming</artifactId>
        <version>2.0.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-api</artifactId>
        <version>3.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-nio</artifactId>
        <version>3.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>artemis-jms-client</artifactId>
        <version>1.5.1</version>
    </dependency>

但现在又出现了另一个错误:

  

ActiveMQConnectionTimedOutException [errorType = CONNECTION_TIMEDOUT message = AMQ119013:等待接收群集拓扑超时。组:空]

0 个答案:

没有答案