spring-cloud-stream-binder-rocketmq 不支持延时队列,需要使用原生的mq进行消息发送。
一、引入依赖
implementation 'com.alibaba.cloud:spring-cloud-stream-binder-rocketmq:2.1.0.RELEASE'
二、定义生产信道和消费信道
//消费信道
public interface PagePointSink {
String PAGE_POINT_INPUT = "page_point_input";
@Input(PAGE_POINT_INPUT)
SubscribableChannel pagepointInput();
}
//生产信道
public interface PagePointSource {
String PAGE_POINT_OUTPUT = "page_point_output";
@Output(PAGE_POINT_OUTPUT)
MessageChannel pagepointOutput();
}
三、配置文件配置
spring.cloud.stream.bindings.page_point_output.destination=page_point
spring.cloud.stream.bindings.page_point_output.content-type=application/json
spring.cloud.stream.bindings.page_point_input.destination=page_point
spring.cloud.stream.bindings.page_point_input.content-type=application/json
spring.cloud.stream.bindings.page_point_input.group=page_point_input
四、延时发送
1、生产端
import java.util.Date;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.