package com.yeshi.fanli.util.mq.rabbit.consumer;
|
|
import com.google.gson.Gson;
|
import com.rabbitmq.client.Channel;
|
import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.money.extract.ExtractService;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.mq.rabbit.RabbitmqMsgConsumeUtil;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.nio.charset.StandardCharsets;
|
|
/**
|
* @author hxh
|
* @title: QueueHelloWorldListener
|
* @description:
|
* @date 2024/9/26 13:47
|
*/
|
@Component
|
public class ExtractResultListener {
|
|
@Resource
|
private RabbitTemplate rabbitTemplate;
|
|
@Resource
|
private ExtractService extractService;
|
|
@RabbitListener(queues = "extract-result-fanli", ackMode = "MANUAL")
|
public void onMessage(Message message, Channel channel) throws Exception {
|
RabbitmqMsgConsumeUtil.processMessage(message, channel, rabbitTemplate, () -> {
|
String result = new String(message.getBody(), StandardCharsets.UTF_8);
|
if (!StringUtil.isNullOrEmpty(result)) {
|
AlipayTransferResultInfo alipayTransferResultInfo = new Gson().fromJson(result,
|
AlipayTransferResultInfo.class);
|
try {
|
extractService.processExtractResult(alipayTransferResultInfo);
|
} catch (Exception e) {
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
throw e;
|
}
|
}
|
});
|
}
|
}
|