UcEngineEventConsumer.java 1.87 KB
package com.topdraw.mq.consumer;

import com.topdraw.config.RabbitMqConfig;
import com.topdraw.mq.domain.DataSyncMsg;
import com.topdraw.mq.domain.TableOperationMsg;
import com.topdraw.resttemplate.RestTemplateClient;
import com.topdraw.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

@Component
@Slf4j
public class UcEngineEventConsumer {

    @Autowired
    AutoRoute autoUser;

    @Autowired
    RestTemplateClient restTemplateClient;

    /**
     * 事件
     * @param content
     * @description 基础数据同步
     * @author Hongyan Wang
     * @date 2021/9/7 11:26 上午
     */
    @RabbitHandler
    @RabbitListener(bindings = {
            @QueueBinding(value = @Queue(value = RabbitMqConfig.ENGINE_TO_IPTV_CONSUMER_MEMBER_DIRECT),
                    exchange = @Exchange(value = ExchangeTypes.DIRECT))
    }, containerFactory = "serviceRabbitListenerContainerFactory")
    public void ucEventConsumer(String content) {
        log.info(" receive dataSync msg , content is : {} ", content);
        TableOperationMsg tableOperationMsg = this.parseContent(content);
        autoUser.route(tableOperationMsg);
        log.info("ucEventConsumer ====>>>> end");
    }

    /**
     * 数据解析
     * @param content
     * @return
     */
    private TableOperationMsg parseContent(String content) {
        TableOperationMsg tableOperationMsg = JSONUtil.parseMsg2Object(content,TableOperationMsg.class);
        Assert.notNull(tableOperationMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!");
        return tableOperationMsg;
    }

}