package cn.component.message.mq.base;

import cn.util.core.LogKit;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AtvSenderBase {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMessage(JSONObject jsonObject, final long delayTimes) {
        //给延迟队列发送消息
        amqpTemplate.convertAndSend(getExchange(), getRouteKey(), jsonObject, message -> {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        });
        LogKit.info("send delay message jsonObject:{}", jsonObject);
    }

    protected abstract String getExchange();

    protected abstract String getRouteKey();

}
