简体   繁体   中英

How to push and consume a message from Spring boot to standalone JBoss Wildfly 10 Artemis Activemq?

I have written a Spring Boot application which aims to push and consume a message from JBoss Wildfly 10 ActiveMQ Artemis (NOTE: not Apache ActiveMQ 5.x). I am running this code through Spring Tool Suite.

I have also setup JBoss Wildfly 10 on my local system (on 8080 port) and have run the same in standalone-full.xml profile in order to create a queue called TestQ in the messaging subsystems of Wildfly.

Next I used JMSTemplate in the Spring Boot code for pushing and consuming the message in the above mentioned queue with the following things in application.properties :

spring.activemq.username=admin
spring.activemq.username=admin
spring.activemq.broker-url=http://localhost:8080

However, I am getting Could not send message error while running my code.

Can you please suggest what changes would be required?

My basic aim is to push and consume message from this external queue using Spring Boot.

I have tried alternatives on the net, but every example I get is for Apache ActiveMQ and not ActiveMQ Artemis embedded into JBoss Wildfly which is required.

I have the below 2 classes:

1.

@SpringBootApplication
@EnableJms
public class App  {

    @Bean
    public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                    DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    public static void main(String[] args) {
        // Launch the application
        ConfigurableApplicationContext context = SpringApplication.run(App.class, args);

        JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);

        System.out.println("Sending a JMS message.");
        jmsTemplate.convertAndSend("sampleQueue", "Hello world!");
    } 
}

2.

@Component
public class ReceiveMessage {

    @JmsListener(destination = "sampleQueue")
    public void receiveMessage(String msg) {
        System.out.println("Received :" + msg);
    }
}

It looks to me like the properties in application.properties are for an ActiveMQ 5.x client rather than an ActiveMQ Artemis client. As the Spring Boot documentation says:

Artemis configuration is controlled by external configuration properties in spring.artemis.* .

Also, you should to expose a port on Wildfly directly to the ActiveMQ Artemis broker rather than using the consolidated port 8080 as this requires httpUpgradeEnabled to be set to true on the Artemis client's URL and there is no way to do that using the Spring Boot integration for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM