我正在尝试通过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>
答案 0 :(得分:1)
您的JConsole屏幕快照显示了trackerRec
核心队列的属性。但是,这不是与您的应用程序将使用的trackerRec
JMS队列相对应的核心队列。您需要查看jms.queue.trackerRec
核心队列或trackerRec
树中的JMS
JMS队列。
此外,值得注意的是,三年前,HornetQ代码库已捐赠给Apache ActiveMQ项目,并且代码库以Apache ActiveMQ Artemis代理身份存在。我强烈鼓励您从HornetQ转到ActiveMQ Artemis。自从上一版HornetQ发布以来,已经进行了大量的改进,新功能,错误修复等。另外,由于ActiveMQ Artemis 2.0,核心地址和队列与JMS队列和主题之间不再存在任何分隔。该寻址模型更加直观和强大。