package com.yanzuoguang.redis.mq; import org.springframework.beans.factory.InitializingBean; import org.springframework.stereotype.Component; import java.nio.charset.StandardCharsets; /** * 任务消费 * * @author 颜佐光 */ @Component public class PlanConsumerInit implements InitializingBean { private final PlanProcedure planProcedure; private final PlanConsumer planConsumer; public PlanConsumerInit(PlanProcedure planProcedure, PlanConsumer planConsumer) { this.planProcedure = planProcedure; this.planConsumer = planConsumer; } @Override public void afterPropertiesSet() { // 应用程序级的任务交给队列处理 planProcedure.initQueue((message, channel) -> planConsumer.plan(new String(message.getBody(), StandardCharsets.UTF_8), message, channel) ); } }