package com.persagy.person.mq; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSON; import com.persagy.person.config.ApplicationProperties; import com.persagy.person.pojo.dto.SaasAccount; import com.persagy.person.pojo.dto.SaasGroup; import lombok.extern.slf4j.Slf4j; /** * @version * @description * @company persagy * @author zhangqiankun * @since 2021年3月2日: 下午2:24:08 */ @Slf4j @Component public class CommonTopicProducer { @Autowired private RabbitTemplate rabbitTemplate; @Autowired private ApplicationProperties properties; /** * 创建集团信息时,投递至mq * * @param type 类型 create-创建,update-更新 */ public void sendGroupInfo(SaasGroup saasGroup, String type) { if (properties.isRaabitmqEnable()) { saasGroup.setType(type); String message = JSON.toJSONString(saasGroup); log.info("send rabbitmq group message to " + properties.getCommonExchange() + " : " + message); this.rabbitTemplate.convertAndSend(properties.getCommonExchange(), properties.getGroupRouteKey(), message); } } /** * 创建集团管理员账号信息时,投递至mq * * @param type 类型 create-创建,update-更新 */ public void sendAccountInfo(SaasAccount saasAccount, String type) { if (properties.isRaabitmqEnable()) { saasAccount.setType(type); saasAccount.setPassword(null); String message = JSON.toJSONString(saasAccount); log.info("send rabbitmq account message to " + properties.getCommonExchange() + " : " + message); this.rabbitTemplate.convertAndSend(properties.getCommonExchange(), properties.getAccountRouteKey(), message); } } }