package com.docus.server.collect.dept.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.RocketMqUserConsumer#send(String)
 * @see com.docus.server.collect.user.mq.test.MQTestRestController
 */
@Component
@Slf4j
//启用rockertmq consumer，打开下面的注解监听
//@RocketMQMessageListener(topic = "ta-cipher-persist", consumerGroup = "ta-cipher-encode")
public class RocketMqDeptConsumer implements RocketMQListener<String> {

    @Resource(name = "deptJmsMqCollectServiceImpl")
    private IDeptMqCollectService deptMqCollectService;

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