package com.docus.server.collect.basic.mq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * rocketmq 基础数据消费者
 *
 * @see com.docus.server.collect.user.mq.test.RocketMQProvdier
 * @see com.docus.server.collect.basic.mq.impl.BasicRocketMqCollectServiceImpl#addTBasic(String)
 */
@Component
@Slf4j
//启用rockertmq consumer，打开下面的注解监听
//@RocketMQMessageListener(topic = "ta-cipher-persist", consumerGroup = "ta-cipher-encode")
public class RocketMqBasicConsumer implements RocketMQListener<String> {

    @Resource(name = "basicRocketMqCollectServiceImpl")
    private IBasicMqCollectService basicMqCollectService;

    @Override
    public void onMessage(String message) {
        try {
            log.info("RocketMQ message:{}", message);
            basicMqCollectService.addTBasic(message);
        } catch (Exception e) {
            log.error("errorMessage:{}", message);
            // 抛出异常会重新消费消息
            throw new RuntimeException("Message processing failed", e);
        }
    }
}
