服务C对接微博RTB服务,服务B本地组装数据,服务A接收业务变化;
当服务A变化时,需要通知服务B及时修改
服务A注入:
/** * @author Doctor */ @Component public class WaxPutPlanSendToAdxConfiguration { /** 交换名称 */ public static final String BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG = "business-flow-wax-put-to-adx-exchang"; /** *FanoutExchange广播交换
* @return
*/ @Bean(name = BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG) public FanoutExchange toAdxExchange(){ return new FanoutExchange(BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG, true, false); } }
触发:
/** * amqpTemplate */ @Autowired private AmqpTemplate amqpTemplate;
/** * @描述:通知adx-wax计划列表有更新(包含有规则和无规则) */ public void noticeAdx(){ MessagePostProcessor messagePostProcessor = new MessagePostProcessor() { @Override public Message postProcessMessage(Message message) { return message; } }; amqpTemplate.convertAndSend(WaxPutPlanSendToAdxConfiguration.BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG,"","changed",messagePostProcessor); }
服务B注入:(IpUtils.getLocalhostIp()动态)
/** * @author Doctor */ @Component public class WaxPutPlanReceiveServerConfiguration { /** 交换名称 */ public static final String BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG = "business-flow-wax-put-to-adx-exchang"; /** 通用队列 */ public static final String BUSINESS_FLOW_WAX_PUT_TO_ADX_QUEUE = "business-flow-wax-put-to-adx-queue-"+ IpUtils.getLocalhostIp(); /** * 交换 */ @Bean public FanoutExchange toAdxExchange(){ return new FanoutExchange(BUSINESS_FLOW_WAX_PUT_TO_ADX_EXCHANG, true, false); } /** * 队列 */ @Bean public Queue toAdxQueue() { return new Queue(BUSINESS_FLOW_WAX_PUT_TO_ADX_QUEUE,true); }
/** * 绑定 队列 到 交换 * * @param toAdxExchange 交换 * @param toAdxQueue 队列 */ @Bean public Binding adxBinding(FanoutExchange toAdxExchange, Queue toAdxQueue) { return BindingBuilder.bind(toAdxQueue).to(toAdxExchange); } }
监听:
/** * @描述:接收缓存变更通知 监听队列配置动态名称很重要 * @param msg * @throws Exception */ @RabbitListener(queues = "#{toAdxQueue.name}") public void receiveServerWaxPlanChange(String msg){ //处理业务逻辑 }