新建分支

This commit is contained in:
19991905653
2024-04-09 09:29:59 +08:00
parent 95405fa625
commit 342d0d82e1
47 changed files with 2392 additions and 109 deletions

View File

@@ -0,0 +1,41 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.service.CartService;
import com.chaozhanggui.system.cashierservice.service.IntegralService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Slf4j
@Component
@RabbitListener(queues = {RabbitConstants.INTEGRAL_QUEUE_PUT})
@Service
public class IntegralConsumer {
@Autowired
private RedisUtil redisUtil;
@Autowired
private IntegralService integralService;
@RabbitHandler
public void listener(String message) {
try {
JSONObject jsonObject = JSON.parseObject(message);
integralService.integralAdd(jsonObject);
} catch (Exception e) {
e.getMessage();
}
}
}

View File

@@ -61,7 +61,20 @@ public class RabbitConfig {
public Binding bindingPut_Register() {
return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT);
}
@Bean
public DirectExchange defaultIntegral() {
return new DirectExchange(RabbitConstants.INTEGRAL_PUT);
}
@Bean
public Queue queueIntegral() {
return new Queue(RabbitConstants.INTEGRAL_QUEUE_PUT, true); //队列持久
}
@Bean
public Binding bindingIntegral() {
return BindingBuilder.bind(queueIntegral()).to(defaultIntegral()).with(RabbitConstants.INTEGRAL_ROUTINGKEY_PUT);
}

View File

@@ -29,4 +29,13 @@ public interface RabbitConstants {
public static final String PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT = "print_mechine_collect_routingkey_put_wx";
public static final String INTEGRAL_PUT="integral_put";
public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put";
public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put";
}

View File

@@ -36,7 +36,10 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, content, correlationId);
}
public void printCoupons(String content){
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_QUEUE_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId);
}
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
logger.info(" 回调id:" + correlationData);