rabbitmq的消费者消费不了消息的情况汇总

1. 问题描述

         通过rabbitmq队列,消费方出现不能消费消息的情况,经过细查rabbitmq的配置没有问题,然而消费方不能执行逻辑。

rabbitmq的消费者消费不了消息的情况汇总_第1张图片

 

  交换机配置exchange:

rabbitmq的消费者消费不了消息的情况汇总_第2张图片

 

  交换机绑定的队列:
 

rabbitmq的消费者消费不了消息的情况汇总_第3张图片

       同样也发现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);
}

 

3、总结

      1. 检查服务有没有连接上消息队列。

      2. 检查队列绑定的路由器是不是和代码里一样的。

     3.检查接口,有没有被调用到。

 

你可能感兴趣的:(项目总结,rabbitmq)