CommonTopicProducer.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.persagy.person.mq;
  2. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Component;
  5. import com.alibaba.fastjson.JSON;
  6. import com.persagy.person.config.ApplicationProperties;
  7. import com.persagy.person.pojo.dto.SaasAccount;
  8. import com.persagy.person.pojo.dto.SaasGroup;
  9. import lombok.extern.slf4j.Slf4j;
  10. /**
  11. * @version
  12. * @description
  13. * @company persagy
  14. * @author zhangqiankun
  15. * @since 2021年3月2日: 下午2:24:08
  16. */
  17. @Slf4j
  18. @Component
  19. public class CommonTopicProducer {
  20. @Autowired
  21. private RabbitTemplate rabbitTemplate;
  22. @Autowired
  23. private ApplicationProperties properties;
  24. /**
  25. * 创建集团信息时,投递至mq
  26. *
  27. * @param type 类型 create-创建,update-更新
  28. */
  29. public void sendGroupInfo(SaasGroup saasGroup, String type) {
  30. if (properties.isRaabitmqEnable()) {
  31. saasGroup.setType(type);
  32. String message = JSON.toJSONString(saasGroup);
  33. log.info("send rabbitmq group message to " + properties.getCommonExchange() + " : " + message);
  34. this.rabbitTemplate.convertAndSend(properties.getCommonExchange(), properties.getGroupRouteKey(), message);
  35. }
  36. }
  37. /**
  38. * 创建集团管理员账号信息时,投递至mq
  39. *
  40. * @param type 类型 create-创建,update-更新
  41. */
  42. public void sendAccountInfo(SaasAccount saasAccount, String type) {
  43. if (properties.isRaabitmqEnable()) {
  44. saasAccount.setType(type);
  45. saasAccount.setPassword(null);
  46. String message = JSON.toJSONString(saasAccount);
  47. log.info("send rabbitmq account message to " + properties.getCommonExchange() + " : " + message);
  48. this.rabbitTemplate.convertAndSend(properties.getCommonExchange(), properties.getAccountRouteKey(), message);
  49. }
  50. }
  51. }