การส่งข้อความไปยัง HornetQ แบบฝังจากแอปพลิเคชันภายนอก

ฉันใช้ 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)

person jax    schedule 31.03.2015    source แหล่งที่มา
comment
ฉันกำลังดูสิ่งที่คล้ายกัน (ในที่สุดฉันต้องการรวมการตั้งค่า HornetQ ที่ฝังไว้สองรายการ) แต่ยังไม่เข้าใจเช่นกัน ฉันคิดว่าในการเริ่มต้น คุณจะต้องเพิ่มการขนส่งบนเซิร์ฟเวอร์แบบฝังตัวที่อนุญาตให้เชื่อมต่อกับพอร์ตจริง โดยค่าเริ่มต้นจะมีการกำหนดค่าเฉพาะ InVMConnectorFactory เท่านั้น   -  person ci_    schedule 31.03.2015


คำตอบ (1)


ปัญหาคือเซิร์ฟเวอร์ HornetQ แบบฝังได้รับการกำหนดค่าเพียง InVMAcceptorFactory ตามค่าเริ่มต้น คุณต้องเพิ่ม AcceptorFactory ที่รับฟังพอร์ตจริง ๆ เช่น NettyAcceptorFactory

คุณสามารถใช้ HornetQConfigurationCustomizer เพื่อกำหนดค่านี้ได้ ตัวอย่างด้านล่างใช้โฮสต์/พอร์ตแบบฮาร์ดโค้ด แต่คุณสามารถสร้างคุณสมบัติของคุณเองได้อย่างง่ายดายเพื่อให้สามารถกำหนดค่านี้ได้

@Bean
public HornetQConfigurationCustomizer hornetCustomizer() {
    return new HornetQConfigurationCustomizer() {
        @Override
        public void customize(Configuration configuration) {
            Set<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("host", "localhost");
            params.put("port", "5445");
            TransportConfiguration tc = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);
            acceptors.add(tc);
        }
    };
}

ในแอปพลิเคชันของคุณที่มีเซิร์ฟเวอร์แบบฝังตัว คุณกำหนดค่าให้เป็นแบบฝังตัว (ตามที่ฉันเชื่อว่าคุณมีอยู่แล้ว เพียงเพื่อให้แน่ใจว่า):

spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue

และในแอปพลิเคชัน "อื่นๆ" ที่คุณต้องการเชื่อมต่อกับเซิร์ฟเวอร์แบบฝัง คุณสามารถกำหนดค่า HornetQ ในโหมดเนทิฟได้:

spring.hornetq.mode=native
spring.hornetq.host=localhost
spring.hornetq.port=5445
person ci_    schedule 02.04.2015
comment
ฉันไม่สามารถทำงานนี้ได้ แอปพลิเคชันทั้งสองเริ่มต้นได้ดีโดยไม่มีข้อผิดพลาด เมื่อฉันพยายามส่งข้อความ ฉันได้รับ org.hornetq.api.core.HornetQNotConnectedException: HQ119007: Cannot connect to server(s). Tried with all available servers. - person jax; 10.04.2015
comment
ฉันเริ่มใช้พอร์ตอื่น 5455 และทุกอย่างเริ่มทำงาน ... ไม่แน่ใจว่าทำไม - person jax; 10.04.2015