亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring boot standalone CommandLineRunner 不會返回

Spring boot standalone CommandLineRunner 不會返回

呼喚遠方 2023-03-23 15:20:34
我正在構建一個經典的制作人 -> rabbitmq -> 消費者流程。所有 3 個節點都在單獨的 jvm 甚至單獨的主機上運行Producer 是一個 spring boot 命令行運行器應用程序,預計在完成生產后停止。消費者應用程序是一個 spring boot web 應用程序,它監聽 3 個 rabbitmq 隊列(2 個持久隊列綁定到直接交換,1 個非持久隊列綁定到扇出交換)我的啟動順序如下: - 啟動 rabbitmq - 啟動消費者 - 啟動生產者生產者和消費者 amqp 依賴mvn dependency:tree[INFO] |  +- org.springframework.boot:spring-boot-starter-amqp:jar:2.1.6.RELEASE:compile[INFO] |  |  +- org.springframework:spring-messaging:jar:5.1.8.RELEASE:compile[INFO] |  |  \- org.springframework.amqp:spring-rabbit:jar:2.1.7.RELEASE:compile[INFO] |  |     +- org.springframework.amqp:spring-amqp:jar:2.1.7.RELEASE:compile[INFO] |  |     |  \- org.springframework.retry:spring-retry:jar:1.2.4.RELEASE:compile[INFO] |  |     +- com.rabbitmq:amqp-client:jar:5.4.3:compile[INFO] |  |     \- org.springframework:spring-tx:jar:5.1.8.RELEASE:compile生產者代碼/** * @author [email protected] */@RequiredArgsConstructor@Slf4jpublic class PlatformBrokerExampleProducerJob implements CommandLineRunner {    private final AmqpTemplate template;    @Override    public void run(String... args) {        final Instant now = Instant.now();        final Instant anHourAgo = now.minus(Duration.ofHours(1));        final String directExchangeName = "careassist_queues";        final String fanoutExchangeName = "careassist_schedules_topics";        IntStream.range(0, 60).boxed().forEach(i -> {            final SensorEventDto event = SensorEventDto.builder() //                    .id(UUID.randomUUID().toString()) //                    .businessId("sens-q7ikjxk1ftik") //                    .timestamp(anHourAgo.plus(Duration.ofMinutes(i))) //                    .state(SensorState.on) //                    .build();            final String routingKey = "care.events";            template.convertAndSend(directExchangeName, routingKey, event);            log.info(">>>>>>>>>>> Sent {} to exchange {} with routing key {}", event.getId(), directExchangeName, routingKey);        });
查看完整描述

2 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

AMQP 客戶端有一些后臺線程。

您應該更改main()方法以在跑步者返回后關閉應用程序上下文...

public static void main(String[] args) {
    SpringApplication.run(MyApplication.class, args).close();
}

它會干凈利落地關閉一切,因為它不像System.exit().


查看完整回答
反對 回復 2023-03-23
?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

PlatformBrokerClientConfiguration 綁定隊列。但我看不到任何地方可以關閉隊列。所以這可能是暫停您的實例的原因。

請試試這個。

  public static void main(String[] args) {
    System.exit(SpringApplication.exit(SpringApplication.run(EmployeeDataProduceApp.class, args)));
  }


查看完整回答
反對 回復 2023-03-23
  • 2 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號