ฉันใช้ spring-boot 1.2.2
ฉันมีการตั้งค่าคิวแตนแบบฝังใน application.properties
:
spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue
ฉันต้องการเพิ่มข้อความไปที่ "myQueue" จากแอปพลิเคชันภายนอก (ไม่ใช่ข้อความที่มีคิวฝังตัว) เป็นไปได้ไหม?
ในแอปพลิเคชันอื่น (อันที่ไม่มี Hornetq แบบฝัง) ฉันพยายามสร้าง ConnectionFactory ที่ชี้ไปยังเซิร์ฟเวอร์ Hornetq แบบฝัง แต่ฉันไม่รู้จริงๆว่าฉันควรใช้พอร์ตใด ตาม spring-boot เอกสารประกอบระบุว่าใช้ได้กับโหมด "เนทิฟ" เท่านั้น
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)