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

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

import javax.annotation.Resource;

/**
 * rocketmq 被动接收用户信息
 */
@Component
@Slf4j
//启用rockertmq consumer，打开下面的注解监听
//@RocketMQMessageListener(topic = "ta-cipher-persist", consumerGroup = "ta-cipher-encode")
public class RocketMqUserConsumer implements RocketMQListener<String> {

    @Resource(name = "userRocketMqCollectServiceImpl")
    private IUserMqCollectService userMqCollectService;

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