rabbitmq的消費者消費不了消息的情況彙總

1. 問題描述

         通過rabbitmq隊列,消費方出現不能消費消息的情況,經過細查rabbitmq的配置沒有問題,然而消費方不能執行邏輯。

 

  交換機配置exchange:

 

  交換機綁定的隊列:
 

       同樣也發現properties文件中的配置是正確的:

spring.rabbitmq.port = 5672
spring.rabbitmq.username = admin
spring.rabbitmq.password = Aegon_2018
spring.rabbitmq.virtual-host = /fec-uat
spring.rabbitmq.host = rabbitmq-fec.dev

       

 2.解決方案

        最後發現沒有添加@RestController註解。 繼承了AbstractWorkflowEventConsumerInterface的類上添加@RestController註解,即可解決問題!

      經過查看源碼發現,最終執行的approve方法,是一個restFul接口,因此需要在類上添加一個@RestController將接口暴露出來。

@RestController
public class WorkflowEventConsumer extends AbstractWorkflowEventConsumerInterface {}

 

     其中  

@PostMapping({"/api/implement/workflow/approve"}) public abstract ApprovalResultCO approve(@RequestBody ApprovalNotificationCO approvalNoticeCO);

    是一個restFul接口。

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hand.hcf.app.mdata.client.workflow.event;

import com.hand.hcf.app.mdata.base.util.OrgInformationUtil;
import com.hand.hcf.app.mdata.client.workflow.dto.ApprovalNotificationCO;
import com.hand.hcf.app.mdata.client.workflow.dto.ApprovalResultCO;
import com.hand.hcf.app.mdata.client.workflow.dto.WorkflowMessageCO;
import com.hand.hcf.app.mdata.client.workflow.enums.DocumentOperationEnum;
import com.hand.hcf.core.exception.BizException;
import com.hand.hcf.core.security.domain.PrincipalLite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

public abstract class AbstractWorkflowEventConsumerInterface implements WorkflowEventConsumerInterface {
    @Value("${spring.application.name:}")
    private String applicationName;
    private static final Logger logger = LoggerFactory.getLogger(AbstractWorkflowEventConsumerInterface.class);

    public AbstractWorkflowEventConsumerInterface() {
    }

    @Transactional(
        rollbackFor = {Exception.class}
    )
    public void workFlowConsumer(WorkflowCustomRemoteEvent workflowCustomRemoteEvent) {
        String destinationService = this.applicationName + ":**";
        WorkflowMessageCO workflowMessage = workflowCustomRemoteEvent.getWorkflowMessage();
        if (destinationService.equalsIgnoreCase(workflowCustomRemoteEvent.getDestinationService()) && workflowMessage.getStatus() > DocumentOperationEnum.APPROVAL.getId()) {
            if (logger.isInfoEnabled()) {
                logger.info("接收到工作流事件消息:" + workflowCustomRemoteEvent);
            }

            PrincipalLite userBean = workflowMessage.getUserBean();
            OrgInformationUtil.setAuthentication(userBean);
            this.doWorkFlowConsumer(workflowCustomRemoteEvent, workflowMessage);
        }

    }

    protected void doWorkFlowConsumer(WorkflowCustomRemoteEvent workflowCustomRemoteEvent, WorkflowMessageCO workflowMessage) {
        ApprovalNotificationCO approvalNotificationCO = new ApprovalNotificationCO();
        approvalNotificationCO.setDocumentId(workflowMessage.getDocumentId());
        approvalNotificationCO.setDocumentOid(workflowMessage.getEntityOid());
        approvalNotificationCO.setDocumentCategory(Integer.parseInt(workflowMessage.getEntityType()));
        approvalNotificationCO.setDocumentStatus(workflowMessage.getStatus());
        approvalNotificationCO.setDocumentTypeId(workflowMessage.getDocumentTypeId());
        approvalNotificationCO.setDocumentTypeCode(workflowMessage.getDocumentTypeCode());
        ApprovalResultCO approvalResultCO = this.approve(approvalNotificationCO);
        if (Boolean.FALSE.equals(approvalResultCO.getSuccess())) {
            throw new BizException(approvalResultCO.getError());
        }
    }

    @PostMapping({"/api/implement/workflow/approve"})
    public abstract ApprovalResultCO approve(@RequestBody ApprovalNotificationCO approvalNoticeCO);
}

 

workflowEventConsumer接口:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hand.hcf.app.mdata.client.workflow.event;

import org.springframework.context.event.EventListener;

public interface WorkflowEventConsumerInterface {
    @EventListener({WorkflowCustomRemoteEvent.class})
    void workFlowConsumer(WorkflowCustomRemoteEvent event);
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章