Home > Back-end >  How to create Session Factory when sending async messages via ActiveMQ Artemis in Spring Boot?
How to create Session Factory when sending async messages via ActiveMQ Artemis in Spring Boot?

Time:05-16

I'm trying to send simple message to a topic from enter image description here

Also, I can login into console (username: artemis; password: simetraehcapa;):

enter image description here

Other configuration in sender app:

@EnableAsync
@EnableScheduling
@Configuration
public class AsyncConfig {

    public static final String EXECUTOR = "SchedulerExecutor";

    @Bean(name = EXECUTOR)
    public Executor asyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(2);
        executor.setQueueCapacity(50);
        executor.setThreadNamePrefix(EXECUTOR   "-");
        executor.initialize();
        return executor;
    }
}

and

@Configuration
public class JmsConfig {

    public static final String QUEUE = "queue";

    @Bean // Serialize message content to json using TextMessage
    public MessageConverter jacksonJmsMessageConverter(ObjectMapper objectMapper) {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        converter.setObjectMapper(objectMapper);
        return converter;
    }
}

and

spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=8161
spring.artemis.user=artemis
spring.artemis.password=simetraehcapa

And finally, how I actually send a message is via simple GET request (http://localhost:8080/send):

@GetMapping("/send")
public void sendMessage(){
    Student s = new Student("MIKE");
    this.jmsTemplate.convertAndSend(JmsConfig.QUEUE, s);
}

And listener class:

@Component
@EnableJms
public class Listener {

    @Autowired
    private JmsTemplate jmsTemplate;

    @JmsListener(destination = "queue")
    public void listen(Student student){
        System.out.println(student);
    }
}

So my questions are:

  1. How to configure Session Factory?
  2. Do I miss some other config which I'm not aware of?

CodePudding user response:

I believe the problem is this line in your configuration:

spring.artemis.port=8161

This pointing to the HTTP port used by the embedded web server in ActiveMQ Artemis. This isn't suitable for JMS clients. You should be using:

spring.artemis.port=61616
  • Related