Saya menggunakan spring-boot 1.2.2.
Saya memiliki pengaturan antrian lebah yang tertanam di application.properties
:
spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue
Saya ingin menambahkan pesan ke "myQueue" dari aplikasi eksternal (bukan yang memiliki antrian tertanam). Apakah ini mungkin?
Di aplikasi lain (yang tanpa hornetq tertanam), saya mencoba membuat connectionFactory yang menunjuk ke server hornetq tertanam tetapi saya tidak tahu port apa yang harus saya gunakan. Menurut spring-boot dokumentasi katanya hanya valid untuk mode "asli".
spring.hornetq.mode= # connection mode (native, embedded)
spring.hornetq.host=localhost # hornetQ host (native mode)
spring.hornetq.port=5445 # hornetQ port (native mode)
inilah kode saya sejauh ini:
@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;
}
}
Kemudian:
@Autowired
private JmsTemplate jmsTemplate;
@Scheduled(fixedDelay = 1000L)
public void send() {
this.jmsTemplate.convertAndSend("myQueue", "Hello from external app");
}
Tapi saya mendapat masalah koneksi.
Failed to create session factory; nested exception is HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s)