当前位置: 首页 > 知识库问答 >
问题:

Spring Boot-用于非Web应用程序的长期运行应用程序

谷梁迪
2023-03-14

我有一个简单的Spring-Boot应用程序,它只使用AMQP依赖项(仅'org.springframework.boot:spring-boot-starter-amqp'-例如,没有web依赖项,所以JAR中没有包含应用服务器)。

我只想让应用程序运行并监听队列,并在收到消息时将一些信息记录到DB中--然而,由于没有应用程序服务器,它一启动就会再次关闭(因为什么都没有做)。在监听消息的同时,是否有一种最好的方法来保持应用程序的运行?

代码中没有什么令人惊讶的地方,只是标准的应用程序配置,然后还有一个用@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 )
    }
}

(我考虑过的一个选择是将一个预定的过程旋转--仅仅是一个心跳或其他东西,这对监控来说可能是很好的--但是还有其他更好的/标准的方法吗?)

共有1个答案

华星文
2023-03-14

您需要确保启动消息侦听器容器bean,如示例所示:

 @Bean
 SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(queueName);
    container.setMessageListener(listenerAdapter);
    return container;
}
 类似资料:
  • 我试图在SpringMVC中运行SpringBoot应用程序,在SpringMVCPOM中添加SpringBoot应用程序依赖项,并扫描SpringBoot包,但我面临以下问题

  • 本地angular应用程序在-http://localhost:4200/alerts;alerttype=renewals;cor=411119上成功运行 到目前为止,我已经将angular dist文件夹复制到遗留应用程序的webcontent文件夹中,并运行应用程序,如下所示 http://localhost:9086/customer/eWeb/alertapp/alerts;alertt

  • 2020-06-26T09:26:58.880610+00:00Heroku[web.1]:状态从开始更改为>崩溃2020-06-26T12:16:58.291701+00:00Heroku[web.1]:状态从崩溃更改为>开始2020-06-26T12:17:05.611518+00:00Heroku[web.1]:用命令启动进程>2020-06-26T12:17:08.625648+00:00

  • 我正在尝试将Microsoft Team BOT作为Azure Web应用程序运行-可以在此处找到完整的代码 application.py: 在本地运行时,我可以将端口设置为8000,例如,将ngrok指向localhost,并在我的bot通道注册中指定url,一切正常。我一直在努力让我的代码在Azure中工作,但我就是无法做到这一点。我已将脚本配置为在端口8000上运行,并在应用程序设置中设置参

  • 问题内容: 我想使用html applet标记在我的Web应用程序中运行简单applet,但是它给出了类似的错误 java.lang.ClassNotFoundException:MyApplet 请给我示例应用程序,如果可能的话..... 问题答案: 问题是applet引擎在您定义的代码库中找不到MyApplet类。 这是因为您在/ WEB-INF / classes目录中进行了分类。该目录受s