[英]HornetQ: Remove all messages from queue not working with consumer on queue
[英]Unable to read messages from HornetQ queue in springboot application
我正在嘗試通過springboot設置消費者,但遇到了困難。 我已經看到了JMS使用者設置的示例配置,並做了相同的操作,但是以某種方式使用者沒有正確設置,並且在Jconsole隊列上顯示0使用者。 這是我的springboot設置:
@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;
}
}
具有隊列目標的偵聽器
@Component
public class TrackerJmsListener {
@JmsListener(destination = "trackerRec",containerFactory = "myFactory")
public void handleMessage(String message) {//implicit message type conversion
System.out.println("received: " + message);
}
}
我很困惑,因為在控制台上沒有顯示錯誤,並且消費者沒有讀取任何內容。 如果我更改了jms端口或隊列名稱,則在啟動springboot應用程序后,我會在控制台上看到錯誤消息,因此我的基本配置似乎正確。
服務器中hornetq的基本設置。
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>
您的JConsole屏幕截圖顯示了trackerRec
核心隊列的屬性。 但是,這不是與您的應用程序將使用的trackerRec
JMS隊列相對應的核心隊列。 您需要查看jms.queue.trackerRec
核心隊列或JMS
樹中的trackerRec
JMS隊列。
另外,值得注意的是,三年前,HornetQ代碼庫已捐贈給Apache ActiveMQ項目,並且該代碼庫作為Apache ActiveMQ Artemis代理得以繼續存在。 我強烈建議您從HornetQ轉到ActiveMQ Artemis。 自從上一版HornetQ發布以來,已經進行了大量的改進,新功能,錯誤修復等。 另外,由於ActiveMQ Artemis 2.0,核心地址和隊列與JMS隊列和主題之間不再存在任何分隔。 該尋址模型更加直觀和強大。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.