Browse Source

队列模块代码优化

guq 7 years ago
parent
commit
8b3f7ead94

+ 3 - 1
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/controller/TransfersController.java

@@ -5,6 +5,7 @@ import com.usoftchina.saas.transfers.po.MessageInfo;
 import com.usoftchina.saas.transfers.service.SendService;
 import com.usoftchina.saas.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -14,12 +15,13 @@ import org.springframework.web.bind.annotation.RestController;
  * @create: 2019-01-06 22:15
  **/
 @RestController
+@RequestMapping("/send")
 public class TransfersController {
 
     @Autowired
     private SendService sendService;
 
-    @RequestMapping("/sendMsg")
+    @PostMapping("/Message")
     public Result sendMsg(@RequestBody MessageInfo info) {
         if (StringUtils.isEmpty(info)) {
             return Result.error("信息为空");

+ 1 - 1
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/service/ReceiveService.java

@@ -58,7 +58,7 @@ public class ReceiveService {
        logger.info("---------收到消息,消息id={},开始消费---------", info.getMsgId());
         Executable task = null;
        try {
-           switch(BillCodeSeq.valueOf(info.getBizType())){
+           switch(BillCodeSeq.valueOf(info.getBizType())) {
                case PURCHASE:
                    task = new SendPurchaseTask();
                    break;

+ 4 - 4
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/service/SendService.java

@@ -67,7 +67,7 @@ public class SendService {
                 logger.info("msgId={},已发送服务器", messageId);
             } else {
                 //失败则进行具体的后续操作:进入延迟队列
-                BrokerMessagelog message = brokerMessageLogMapper.getMessage(messageId);
+                BrokerMessagelog message = brokerMessageLogMapper.getLiveMessage(messageId);
                 String info = message.getMessage();
                 if (!StringUtils.isEmpty(info)) {
                     MessageInfo messageInfo = JsonUtils.fromJsonString(info, MessageInfo.class);
@@ -93,14 +93,14 @@ public class SendService {
         brokerMessageLogMapper.updateMessageLogandAddRetry(messagelog);
 
         //发送至延迟队列
-        rabbitTemplate.setConfirmCallback(delayConfirmCallback);
+        rabbitTemplate.setConfirmCallback(confirmCallback);
         //消息唯一ID
         CorrelationData correlationData = new CorrelationData(info.getMsgId());
         rabbitTemplate.convertAndSend(rabbitConfig.getExchange(), rabbitConfig.getRoutingkey(), info,
                 new ExpirationMessagePostProcessor(rabbitConfig.getExpired()), correlationData);
     }
 
-    //回调函数: confirm确认
+    /*//回调函数: confirm确认
     final RabbitTemplate.ConfirmCallback delayConfirmCallback = new RabbitTemplate.ConfirmCallback() {
         @Override
         public void confirm(CorrelationData correlationData, boolean confirm, String cause) {
@@ -112,6 +112,6 @@ public class SendService {
                 logger.info("msgId={},发送延迟队列失败:{}", messageId, cause);
             }
         }
-    };
+    };*/
 
 }

+ 7 - 1
applications/transfers/transfers-server/src/main/resources/mapper/BrokermessagelogMapper.xml

@@ -50,6 +50,9 @@
       <if test="reason != null" >
         reason,
       </if>
+      <if test="retry != null" >
+        retry,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
       <if test="msgId != null" >
@@ -67,6 +70,9 @@
       <if test="reason != null" >
         #{reason,jdbcType=VARCHAR},
       </if>
+      <if test="retry != null" >
+        #{retry},
+      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.transfers.po.BrokerMessagelog" >
@@ -109,7 +115,7 @@
   </select>
 
   <select id="getLiveMessage" parameterType="string" resultMap="BaseResultMap">
-    select * from BrokerMessagelog where msgId = #{msgId} and retry &lt;= 3
+    select * from BrokerMessagelog where msgId = #{msgId} and retry &lt; 3
   </select>
 
   <select id="getDeadMessage" parameterType="string" resultMap="BaseResultMap">