package com.zcxk.charge.xxl.jobs;

import com.alibaba.fastjson.JSONObject;
import com.zcxk.core.common.pojo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Andy
 * @version V1.0
 * @description: TODO
 * @date 2021/8/18
 **/
@Component
@Slf4j
public class BaseJob {

    @Value("${receive.exchange.name}")
    private  String receiveExchangeName;

    @Value("${dispath.routing.key}")
    private  String dispathRoutingKey;

    @Resource
    private AmqpTemplate messageRabbitTemplate;

    public void send(Message message){
        log.debug("消息发送 exchange={}  routingkey={} 用户id={}",receiveExchangeName,dispathRoutingKey,message.getUserId());
        messageRabbitTemplate.convertAndSend(receiveExchangeName,dispathRoutingKey, JSONObject.toJSONString(message));
    }
}
