mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-03 21:48:13 +08:00
测试rabbitMQ
This commit is contained in:
@@ -28,6 +28,7 @@ import com.jsowell.adapay.vo.DrawCashDetailVO;
|
||||
import com.jsowell.adapay.vo.PaymentInfo;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.constant.RabbitConstants;
|
||||
import com.jsowell.common.core.domain.entity.SysDictData;
|
||||
import com.jsowell.common.core.domain.ykc.LoginRequestData;
|
||||
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
@@ -89,6 +90,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
@@ -267,6 +269,46 @@ public class SpringBootTestController {
|
||||
@Autowired
|
||||
private CarCouponRecordService carCouponRecordService;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Test
|
||||
public void sendRabbitMqTest() {
|
||||
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
|
||||
.orderCode("C123456789")
|
||||
.merchantId("1")
|
||||
.stationId("2")
|
||||
.payAmount(new BigDecimal(100))
|
||||
.orderAmount(new BigDecimal(100))
|
||||
.settleAmount(new BigDecimal(100))
|
||||
.refundAmount(new BigDecimal(0))
|
||||
.build();
|
||||
OrderDetail orderDetail = OrderDetail.builder()
|
||||
.totalElectricityAmount(new BigDecimal(50))
|
||||
.discountElectricityAmount(new BigDecimal(0))
|
||||
.totalServiceAmount(new BigDecimal(50))
|
||||
.discountElectricityAmount(new BigDecimal(0))
|
||||
.build();
|
||||
|
||||
AfterSettleOrderDTO afterSettleOrderDTO = AfterSettleOrderDTO.builder()
|
||||
.orderCode(orderBasicInfo.getOrderCode())
|
||||
.merchantId(orderBasicInfo.getMerchantId())
|
||||
.stationId(orderBasicInfo.getStationId())
|
||||
.orderPayAmount(orderBasicInfo.getPayAmount())
|
||||
.orderConsumeAmount(orderBasicInfo.getOrderAmount())
|
||||
.orderSettleAmount(orderBasicInfo.getSettleAmount())
|
||||
.orderElectricityAmount(orderDetail.getTotalElectricityAmount())
|
||||
.orderElectricityDiscountAmount(orderDetail.getDiscountElectricityAmount())
|
||||
.orderServiceAmount(orderDetail.getTotalServiceAmount())
|
||||
.orderServiceDiscountAmount(orderDetail.getDiscountServiceAmount())
|
||||
.orderRefundAmount(orderBasicInfo.getRefundAmount())
|
||||
.build();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.YKC_EXCHANGE_NAME, RabbitConstants.QUEUE_CHARGE_ORDER_DATA, afterSettleOrderDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectPileConnectorInfoListByPileSnListTest() {
|
||||
List<String> pileSnList = Lists.newArrayList();
|
||||
|
||||
@@ -105,17 +105,17 @@ public class RabbitConfig {
|
||||
// CorrelationData correlationData, boolean b, String s
|
||||
rabbitTemplate.setConfirmCallback(
|
||||
(correlationData, b, s) -> {
|
||||
System.out.println("ConfirmCallback "+"相关数据:"+ correlationData);
|
||||
System.out.println("ConfirmCallback "+"确认情况:"+b);
|
||||
System.out.println("ConfirmCallback "+"原因:"+s);
|
||||
// System.out.println("ConfirmCallback "+"相关数据:"+ correlationData);
|
||||
// System.out.println("ConfirmCallback "+"确认情况:"+b);
|
||||
// System.out.println("ConfirmCallback "+"原因:"+s);
|
||||
});
|
||||
// Message message, int i, String s, String s1, String s2
|
||||
rabbitTemplate.setReturnCallback((message, i, s, s1, s2) -> {
|
||||
System.out.println("ReturnCallback: "+"消息:"+message);
|
||||
System.out.println("ReturnCallback: "+"回应码:"+i);
|
||||
System.out.println("ReturnCallback: "+"回应消息:"+s);
|
||||
System.out.println("ReturnCallback: "+"交换机:"+s1);
|
||||
System.out.println("ReturnCallback: "+"路由键:"+s2);
|
||||
// System.out.println("ReturnCallback: "+"消息:"+message);
|
||||
// System.out.println("ReturnCallback: "+"回应码:"+i);
|
||||
// System.out.println("ReturnCallback: "+"回应消息:"+s);
|
||||
// System.out.println("ReturnCallback: "+"交换机:"+s1);
|
||||
// System.out.println("ReturnCallback: "+"路由键:"+s2);
|
||||
});
|
||||
|
||||
return rabbitTemplate;
|
||||
@@ -136,7 +136,7 @@ public class RabbitConfig {
|
||||
@Override
|
||||
public <T, E extends Throwable> void close(RetryContext retryContext, RetryCallback<T, E> retryCallback, Throwable throwable) {
|
||||
// 重试结束的时候调用 (最后一次重试 )
|
||||
System.out.println("---------------最后一次调用");
|
||||
// System.out.println("---------------最后一次调用");
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.jsowell.mq;
|
||||
|
||||
import com.jsowell.common.constant.RabbitConstants;
|
||||
import com.jsowell.pile.dto.AfterSettleOrderDTO;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -16,7 +18,7 @@ public class OrderRabbitListener {
|
||||
* 多线程消费请求消息
|
||||
* @param message
|
||||
*/
|
||||
// @RabbitListener(queues = RabbitConstants.QUEUE_CHARGE_ORDER_DATA)
|
||||
@RabbitListener(queues = RabbitConstants.QUEUE_CHARGE_ORDER_DATA)
|
||||
public void receiveChargeOrderData(AfterSettleOrderDTO afterSettleOrderDTO, Channel channel, Message message) throws IOException {
|
||||
log.info("接收到订单结算数据:{}", afterSettleOrderDTO);
|
||||
//由于配置设置了手动应答,所以这里要进行一个手动应答。注意:如果设置了自动应答,这里又进行手动应答,会出现double ack,那么程序会报错。
|
||||
|
||||
Reference in New Issue
Block a user