Electricity supplier (15)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44050355/article/details/100587017

Electricity supplier fifteenth day:
Polling delay queue:
We use messaging middleware to do a distributed transaction: messaging middleware malpractice {message} uncertainty
poll:
solve the periodic long
delay queue:
solve periodically compare short, high accuracy!

	轮询延迟队列在电商中的使用场景!
	
	延迟队列:
		在电商生成二维码的时候,主动去询问支付宝是否支付成功!
		1.	先知道如何查询该笔订单是否支付成功!
			
			AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
			AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
			request.setBizContent("{" +
			"\"out_trade_no\":\"20150320010101001\"," +
			"\"trade_no\":\"2014112611001004680 073956707\"," +
			"\"org_pid\":\"2088101117952222\"," +
			"      \"query_options\":[" +
			"        \"[\\\"TRADE_SETTE_INFO\\\"]\"" +
			"      ]" +
			"  }");
			AlipayTradeQueryResponse response = alipayClient.execute(request);
			if(response.isSuccess()){
				// 真正的交易完成指的是订单的状态 trade_status TRADE_SUCCESS TRADE_FINISHED
				System.out.println("调用成功");
			} else {
				System.out.println("调用失败");
			}
			
			a.	功能开发:
				bean,mapper,service,service.impl,controller
			b.	测试:
				gware-manage,order-service, payment
				http://payment.gmall.com/queryPaymentResult?orderId=99
			c.	开启延迟队列来进行测试
				在用户点击支付的时候,生成二维码,发送一个消息队列{out_trade_no,延迟时间,检查的次数}
				开启一个消息监听器来消费消息,判断用户是否支付!
				
				1.	开启延迟队列
					schedulerSupport="true"
					重启activemq
				2.	功能开发:
				
				3.	测试:
					gware-manage,gmall-user-manage,passport,manage-service, cart-service,cart-web,order-service,order-web, payment
					
					
				
			
	轮询:定时扫描过期的订单!将过期订单进行关闭
		  spring task
		  
		    1.  先获取过期订单 过期时间<new Date() and  是未支付状态
			2.  循环处理过期订单
			3.  处理交易记录表
			
			使用技术:
			spring task + spring boot! 轮询。// 单线程操作
				//	多线程操作呢?
			使用线程池:业务必须具有独立性!
				
				1.	实现接口AsyncConfigurer
				2.	Executor getAsyncExecutor()  中创建线程池
				3.	开启异步@EnableAsync 
				4.	在业务方法上添加@Async
			
			电商中还有什么地方可以使用多线程?多线程编排
				提交订单:
					验证库存:
					验证价格:
					查询优惠价格:
	
拆单:
	1.	为什么需要拆单:
		因为仓库位置不同,商家不同,物流不同
	2.	什么时候拆单:
		支付的时候
	3.	拆单之后是否有影响:
		没有!
	4.	看拆单的接口:
	
	5.	功能实现
	
	6.	测试:	
		必须将商品改为不同的仓库!

Guess you like

Origin blog.csdn.net/weixin_44050355/article/details/100587017