我正在使用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