|
@@ -0,0 +1,51 @@
|
|
|
+package com.fdkankan.sale.mq.consumer;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.sale.mq.common.MqQueueUtil;
|
|
|
+import com.fdkankan.sale.mq.param.ManageToSaleParam;
|
|
|
+import com.fdkankan.sale.service.ISysUserService;
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
+import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class ManageToSaleConsumer {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @RabbitListener(
|
|
|
+ queuesToDeclare = @Queue("manageToSale")
|
|
|
+ )
|
|
|
+ public void consumerQueue(Channel channel, Message message) throws IOException {
|
|
|
+ try {
|
|
|
+ String messageId = message.getMessageProperties().getMessageId();
|
|
|
+ String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+ log.info("接受结果mq--messageId:{},msg:{}",messageId,msg);
|
|
|
+ ManageToSaleParam param = JSONObject.parseObject(msg, ManageToSaleParam.class);
|
|
|
+ String command = param.getCommand();
|
|
|
+ switch (command){
|
|
|
+ case MqQueueUtil.updateUserCommand :
|
|
|
+ sysUserService.updateByDb2(param.getData());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("mq----消费失败",e);
|
|
|
+ }finally {
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|