package com.zksy.data.utils;

import com.zksy.data.constant.RabbitMqConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PublisherMessage {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public void emitDelayMessage(String message,Integer duration) {
        rabbitTemplate.convertAndSend(RabbitMqConstant.DELAY_EXCHANGE_NAME, RabbitMqConstant.DELAY_ROUTING_KEY, message, q -> {
            q.getMessageProperties().setDelay(duration);
            return q;
        });
    }

    public void emitToInvoker(String message) {
        rabbitTemplate.convertAndSend(RabbitMqConstant.INVOKER_EXCHANGE_NAME, RabbitMqConstant.INVOKER_ROUTING_KEY, message);
    }
}
