【发布时间】:2015-06-04 06:50:02
【问题描述】:
我使用的是 spring-boot 1.2.2。
我在application.properties 中有一个嵌入式大黄蜂队列设置:
spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue
我想从外部应用程序(不是具有嵌入式队列的应用程序)向“myQueue”添加一条消息。这可能吗?
在另一个应用程序(没有嵌入式 hornetq 的应用程序)中,我尝试创建一个指向嵌入式 hornetq 服务器的 connectionFactory,但我真的不知道应该使用哪个端口。根据 spring-boot documentation 它说它只对“native”模式有效。
spring.hornetq.mode= # connection mode (native, embedded)
spring.hornetq.host=localhost # hornetQ host (native mode)
spring.hornetq.port=5445 # hornetQ port (native mode)
到目前为止,这是我的代码:
@EnableJms
@Configuration
public class HornetQConfig {
@Bean
public CachingConnectionFactory connectionFactory() {
CachingConnectionFactory cachingConnectionFactory =
new CachingConnectionFactory();
cachingConnectionFactory.setSessionCacheSize(10);
cachingConnectionFactory.setCacheProducers(false);
cachingConnectionFactory.setTargetConnectionFactory(hornetQConnectionFactory());
return cachingConnectionFactory;
}
@Bean
public HornetQConnectionFactory hornetQConnectionFactory() {
HornetQConnectionFactory connectionFactory =
new HornetQConnectionFactory(false, transportConfiguration());
return connectionFactory;
}
@Bean
public TransportConfiguration transportConfiguration() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "localhost");
map.put("port", 5445);
TransportConfiguration configuration =
new TransportConfiguration(
"org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", map);
return configuration;
}
}
然后:
@Autowired
private JmsTemplate jmsTemplate;
@Scheduled(fixedDelay = 1000L)
public void send() {
this.jmsTemplate.convertAndSend("myQueue", "Hello from external app");
}
但我遇到了连接问题。
Failed to create session factory; nested exception is HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s)
【问题讨论】:
-
我正在寻找类似的东西(最终我想对两个嵌入式 HornetQ 设置进行集群),但也没有弄清楚。我认为首先,您需要在嵌入式服务器上添加一个允许在实际端口上连接的传输,默认情况下只会配置一个 InVMConnectorFactory。
标签: spring-boot hornetq