package com.izouma.nineth.listener;

import com.izouma.nineth.service.AssetMintService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
@RocketMQMessageListener(
        consumerGroup = "${general.mint-group}",
        topic = "${general.mint-topic}",
        consumeMode = ConsumeMode.ORDERLY)
//@ConditionalOnProperty(value = "general.notify-server", havingValue = "true")
public class MintListener implements RocketMQListener<Long> {
    private AssetMintService assetMintService;

    @Override
    public void onMessage(Long assetId) {
        try {
            assetMintService.mint(assetId);
        } catch (Exception e) {
            log.error("铸造失败，assetId:" + assetId, e);
        }
    }
}
