Spring Boot application for non-web applications

I have a simple Spring-Boot application that just uses the AMQP dependency (just 'org.springframework.boot:spring-boot-starter-amqp'- for example, no web dependencies, so the application server is not included in the JAR).

All I want is an application to start and listen to the queue and write some information to the database whenever a message arrives - however, since there is no application server, as soon as it starts, it just shuts down again (because nothing is done). Is there a better way to save this app while listening to messages?

There is nothing surprising in the code, just the standard configuration of the application, as well as the class marked with @RabbitListener

@SpringBootApplication
class PersistenceSeriveApplication {

    static void main(String[] args) {
        SpringApplication.run PersistenceSeriveApplication, args
    }
}

@Configuration
@EnableRabbit
class QueueConfiguration {

    @Bean public Queue applicationPersistenceQueue( @Value( '${amqp.queues.persistence}' ) String queueName ) {
        new Queue( queueName )
    }
}

( , , - - , , , - / ?)

+4
1

bean, :

 @Bean
 SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(queueName);
    container.setMessageListener(listenerAdapter);
    return container;
}
+2

Source: https://habr.com/ru/post/1614070/


All Articles