远程访问Wildfly从Spring托管HornetQ(使用MessageListenerContainer)

时间:2017-01-03 14:01:16

标签: spring wildfly hornetq

我目前的设置要求我从一个独立的Spring应用程序中监听Wildfly 8中托管的一组HornetQ队列。我的Spring应用程序能够连接到Wildfly的HornetQ并验证我要求它读取的JNDI队列名称;但是,它永远不会从队列中接收消息。

的applicationContext.xml

<!-- Snippet -->
<!-- HornetQ JMS Connection Factory -->
<!-- Also tried HornetQConnectionFactory -->
<bean id="hornetQConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
    <constructor-arg name="ha" value="false"/>
    <constructor-arg>
        <bean class="org.hornetq.api.core.TransportConfiguration">
            <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"/>
            <constructor-arg>
                <map key-type="java.lang.String" value-type="java.lang.Object">
                    <entry key="use-nio" value="true"/>
                    <entry key="host" value="127.0.0.1"/>
                    <entry key="port" value="5455"/>            
                </map>
            </constructor-arg>      
        </bean>     
    </constructor-arg>
</bean>

<bean id="messageListenerAdapter" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
    <constructor-arg ref="springJmsConsumer"/>
    <property name="messageConverter">
        <bean class="com.demo.CustomMessageConverter"/>
    </property>
</bean>

<bean id="queueDestination" class="org.hornetq.jms.client.HornetQQueue">
    <constructor-arg value="demoQueue"/>
</bean>

<bean id="messageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="hornetQConnectionFactory"/>
    <property name="messageListener" ref="messageListenerAdapter"/>
    <property name="destination" ref="queueDestination"/>
    <property name="cacheLevel" value="0"/>
</bean>

<!-- End Snippet -->

独立-full.xml

    <!-- Relevant Snippets from standalone-full.xml -->
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
    <hornetq-server>
        ...
        <connectors>
            ...
            <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
            </netty-connector>
        </connectors>

        <acceptors>
            ...
            <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
            </netty-acceptor>
        </acceptors>
        ...
        <jms-connection-factories>
            <connection-factory name="RemoteConnectionFactory">
                <connectors>
                    <connector-ref connector-name="netty-throughput"/>
                </connectors>
                <entries>
                    <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                </entries>
            </connection-factory>
            ...
        </jms-connection-factories>

        <jms-destinations>
            <jms-queue name="jms.queue.DemoQueue">
                <entry name="java:/jms/queue/DemoQueue"/>
                <entry name="java:/jboss/exported/jms/queue/DemoQueue">
            </jms-queue>
        </jms-destinations>
    </hornetq-server>
</subsystem>
...
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="messaging-throughput" port="5455"/>
    ...
</socket-binding-group>

Spring Server

public class SpringServer {
    ApplicationContext context = null;

    public void run() {
        context = new ClassPathXmlApplicationContext("applicationContext");
    }
}

春季消费者

@Service
public class SpringJmsConsumer implements MessageListener {
    @Override
    public void onMessage(Message message) {
        System.out.println("I received a message");
    }
}

每当我更改主机,端口或queuename时,都会收到一条错误消息,指出无法找到该队列。我确信我已经连接到HornetQ队列;但是,当我启动Spring服务器时,Wildfly控制台没有描述任何新的连接,我希望它能给我一些INFO文本。

任何提示?

谢谢!

0 个答案:

没有答案