我正在構(gòu)建一個(gè)經(jīng)典的制作人 -> rabbitmq -> 消費(fèi)者流程。所有 3 個(gè)節(jié)點(diǎn)都在單獨(dú)的 jvm 甚至單獨(dú)的主機(jī)上運(yùn)行Producer 是一個(gè) spring boot 命令行運(yùn)行器應(yīng)用程序,預(yù)計(jì)在完成生產(chǎn)后停止。消費(fèi)者應(yīng)用程序是一個(gè) spring boot web 應(yīng)用程序,它監(jiān)聽 3 個(gè) rabbitmq 隊(duì)列(2 個(gè)持久隊(duì)列綁定到直接交換,1 個(gè)非持久隊(duì)列綁定到扇出交換)我的啟動(dòng)順序如下: - 啟動(dòng) rabbitmq - 啟動(dòng)消費(fèi)者 - 啟動(dòng)生產(chǎn)者生產(chǎn)者和消費(fèi)者 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生產(chǎn)者代碼/** * @author louis.gueye@gmail.com */@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); });
Spring boot standalone CommandLineRunner 不會(huì)返回
呼喚遠(yuǎn)方
2023-03-23 15:20:34