Spring Boot - long running application for non-web app

rhinds

I have a simple Spring-Boot application that just uses the AMQP dependency (just 'org.springframework.boot:spring-boot-starter-amqp' - e.g. no web dependencies so no app server being included in the JAR).

All I want is for the application to run and listen to a queue and log some info to the DB whenever a message is recieved - however, as there is no application server, as soon as it starts up it just shuts down again (as there is nothing being done). Is there a best way to keep this application running whilst listening for messages?

There is nothing surprising in the code, just the standard application config, then also a 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 )
    }
}

(One option I considered was just spinning up a scheduled process - just a heartbeat or something, which would probably be nice for monitoring anyway - but is there any other better/standard way?)

guido

You need to make sure to start the message listener container bean, like shown in the examples:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Where should I place the application logic of non-web, non-batch Spring Boot app?

Spring boot web app not running on tomcat 9

Spring Boot: Running as a Java application but classpath contains spring-web

Can Spring actuator be used with non-web Spring Boot application?

Deploying spring boot application to heroku - error message "No web processes running"

JVM crashes when running Spring Boot web app

Integrate a long running service into Spring boot framework

spring boot connection pool with long running requests

Spring Boot Application with Spring Batch not Running Jobs

Spring Boot web app not starting

Running Scripts in a Sprint Boot Web Application

Running a Python script from Spring-Boot Web Application on embedded Tomcat

Javafx Spring Boot - Error When running Application

Compilation error while running a spring boot application

Unable to load Spring Boot application running in Docker

Problem running basic Spring Boot application

Running spring boot application in a different jdk version

Spring Boot Application is not running Flyway migrations on startup

checking whether spring boot application is running or not

Spring Boot Application is not running , Getting error

Error in running jar file of spring boot application

Error in running spring boot application in localhost

Running Spring Boot application with Jersey and Groovy in IntellJ

Release a Spring (not boot) application running with HTTPS

Running Spring Boot application but Jenkins hijacks the port

How to deploy a Spring Boot (non-web) Application on Weblogic 12c

What is the official spring boot way to start a simple non web based java application?

Not able to deploy a Spring Boot application(non-web) war file on weblogic 12c

Spring Boot with H2 is running data.sql every time the web app starts, is this normal?