Ver Fonte

注释说明

yegang há 2 anos atrás
pai
commit
ed4eb04c31

+ 11 - 2
src/main/java/com/sw/activemq/consumer/MessageConsumerService.java

@@ -40,6 +40,7 @@ public class MessageConsumerService {
                 map.put("mid",mid);
                 snatchMaskService.doDecrAndCreateOrder(uid, mid);
                 MsgPara msgPara = new MsgPara(uid+"",mid+"");
+                //订单生成后发送延时消息,处理订单状态
 				iMessageProducerService.delayMessage(new ActiveMQQueue("delay.mask.queue"),msgPara, (long) 60000);
             } catch (JMSException e) {
                 e.printStackTrace();
@@ -47,21 +48,29 @@ public class MessageConsumerService {
         }
     }
 
+    /**
+     * 延时队列消费端
+     * @param msgPara 消息
+     */
     @JmsListener(destination = "delay.mask.queue")
     public void delayMask(MsgPara msgPara) {    // 进行消息接收处理
         if (null !=msgPara) {
+            // 获取口罩id
             Integer mid =Integer.parseInt(msgPara.getMid());
+            // 获取用户id
             Integer uid = Integer.parseInt(msgPara.getUid());
             QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("uid", uid);
             queryWrapper.eq("mid", mid);
+            //查询订单
             TOrder order = tOrderService.getOne(queryWrapper);
             if (order != null) {
-                if ("2".equals(order.getState())) {
+                if ("2".equals(order.getState())) { //判断订单是否已经处理
                     System.out.println("订单已处理");
                     return;
-                } else if("1".equals(order.getState())) {
+                } else if("1".equals(order.getState())) { //判断订单是否没有处理
                     order.setState("3");
+                    //修改订单状态
                     tOrderService.updateById(order);
                     System.out.println("订单已过期");
                 }

+ 11 - 0
src/main/java/com/sw/activemq/producer/impl/MessageProducerServiceImpl.java

@@ -28,11 +28,20 @@ public class MessageProducerServiceImpl implements IMessageProducerService {
 	public void sendMessage(Map<String, Object> message) {
 		jmsMessagingTemplate.convertAndSend(this.queue, message);
 	}
+
+	/**
+	 * 描述 :延时队列
+	 * @param destination 队列
+	 * @param data 消息
+	 * @param time 延时时间
+	 * @param <T>
+	 */
 	@Override
 	public <T extends Serializable> void delayMessage(Destination destination, T data, Long time) {
 		Connection connection =null;
 		Session session =null;
 		MessageProducer messageProducer =null;
+		//获取连接工厂
 		ConnectionFactory connectionFactory = jmsMessagingTemplate.getConnectionFactory();
 		try {
 			//获取连接
@@ -47,7 +56,9 @@ public class MessageProducerServiceImpl implements IMessageProducerService {
 			ObjectMessage objectMessage = session.createObjectMessage( data);
 			// 设置延迟时间
 			objectMessage.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,time);
+			// 发送消息
 			messageProducer.send(objectMessage);
+			//提交
 			session.commit();
 		} catch (JMSException e) {
 			e.printStackTrace();