简体   繁体   中英

Unable to read messages from HornetQ queue in springboot application

I am trying to setting up consumer with springboot but getting a difficulty. I have seen an example configuration of JMS Consumer setup and did the same but somehow consumer is not setting up properly and on Jconsole Queue is showing 0 consumer. Here is my springboot setup:

@Configuration
@EnableJms
@EnableAutoConfiguration
public class MongoConfiguration {
@Bean
    public ConnectionFactory connectionFactory() {
        final Map<String, Object> properties = new HashMap<>();
        properties.put("host", tcpServerURL);
        properties.put("port", tcpServerPort);
        final org.hornetq.api.core.TransportConfiguration configuration =
                new org.hornetq.api.core.TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", properties);
        return new org.hornetq.jms.client.HornetQJMSConnectionFactory(false, configuration);
    }

    @Bean
    public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                    DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);

        return factory;
    }
}

listener with queue destination

  @Component
    public class TrackerJmsListener {
        @JmsListener(destination = "trackerRec",containerFactory = "myFactory")
        public void handleMessage(String message) {//implicit message type conversion
            System.out.println("received: " + message);
        }
    }

Here is a jconsole of local running hornetq Mbean 在此处输入图片说明

I am confuse as there is no error showing on console and nothing is reading by consumer. If i change jms port or queue name then after starting of springboot app i see error message on console so my basic configuration seems to be right.

Basic setup of hornetq in server.

hornetq-configuration.xml

<?xml version="1.0"?>
<configuration xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hornetq">
    <connectors>
        <connector name="netty-connector">
            <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory
            </factory-class>
        </connector>
    </connectors>
    <acceptors>
        <acceptor name="netty-acceptor">
            <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory
            </factory-class>
        </acceptor>
    </acceptors>
    <security-enabled>false</security-enabled>
</configuration>

hornetq-jms.xml

<?xml version="1.0"?>
<configuration xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hornetq">
    <!--the connection factory used by the example -->
    <connection-factory name="ConnectionFactory">
        <connectors>
            <connector-ref connector-name="netty-connector" />
        </connectors>
        <entries>
            <entry name="ConnectionFactory" />
        </entries>
        <consumer-window-size>0</consumer-window-size>
        <connection-ttl>-1</connection-ttl>
    </connection-factory>
    <queue name="trackerRec">
        <entry name="trackerRec" />
    </queue>
</configuration>

Your JConsole screenshot is showing the attributes for the trackerRec core queue. However, that is not the core queue which corresponds with the trackerRec JMS queue which your application will be using. You need to look at the jms.queue.trackerRec core queue or look at the trackerRec JMS queue in the JMS tree.

Also, it's worth noting that the HornetQ code-base was donated to the Apache ActiveMQ project over three years ago now and that code-base lives on as the Apache ActiveMQ Artemis broker. I strongly encourage you to move from HornetQ to ActiveMQ Artemis. There's been a ton of improvements, new features, bug fixes, etc. since the last HornetQ release. Also, since ActiveMQ Artemis 2.0 there is no longer an arbitrary separation between core addresses & queues and JMS queues & topics. The addressing model is more intuitive and powerful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM