我正在使用spring-boot 1.2.2。从外部应用程序向嵌入式HornetQ发送消息
我有一个嵌入式大黄蜂队列设置在application.properties
:
spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue
我要添加一个消息到从外部应用程序(而不是一个具有嵌入的队列)“myQueue中”。这可能吗?
在另一个应用程序(没有嵌入hornetq的应用程序)中,我尝试创建一个指向嵌入hornetq服务器的connectionFactory,但我不知道应该使用哪个端口。根据弹簧启动documentation它说它只适用于“本机”模式。
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。 – 2015-03-31 08:35:18