A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

4.1.5 接收添加选课消息 接收到添加选课的消息调用添加选课方法完成添加选课,并发送完成选课消息。在com.xuecheng.learning.mq包下添加ChooseCourseTask类
[AppleScript] 纯文本查看 复制代码
@Component public class ChooseCourseTask {       private static final Logger LOGGER = LoggerFactory.getLogger(ChooseCourseTask.class);  
     @Autowired  
   LearningService learningService;   
    @Autowired 
    RabbitTemplate rabbitTemplate;  
     /**    
  * 接收选课任务  
    */     @RabbitListener(queues = {RabbitMQConfig.XC_LEARNING_ADDCHOOSECOURSE})     public void receiveChoosecourseTask(XcTask xcTask,Message message,Channel channel) throws  IOException {         LOGGER.info("receive choose course task,taskId:{}",xcTask.getId());    
     //接收到 的消息id    
     String id = xcTask.getId();     
    //添加选课  
       try {         
    String requestBody = xcTask.getRequestBody();       
      Map map = JSON.parseObject(requestBody, Map.class);   
          String userId = (String) map.get("userId");      
       String courseId = (String) map.get("courseId");     
        String valid = (String) map.get("valid");     
        Date startTime = null;        
     Date endTime = null;  
           SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY‐MM‐dd HH:mm:ss");        
     if(map.get("startTime")!=null){       
          startTime =dateFormat.parse((String) map.get("startTime"));      
       }         
    if(map.get("endTime")!=null){      
           endTime =dateFormat.parse((String) map.get("endTime"));    
         }         
    //添加选课    
         ResponseResult addcourse = learningService.addcourse(userId, courseId,  valid,startTime, endTime,xcTask);      
       //选课成功发送响应消息
            if(addcourse.isSuccess()){

[AppleScript] 纯文本查看 复制代码
 //发送响应消息              
   rabbitTemplate.convertAndSend(RabbitMQConfig.EX_LEARNING_ADDCHOOSECOURSE,  RabbitMQConfig.XC_LEARNING_FINISHADDCHOOSECOURSE_KEY, xcTask );    
             LOGGER.info("send finish choose course taskId:{}",id);      
       }   
      } catch (Exception e) {       
      e.printStackTrace();         
    LOGGER.error("send finish choose course taskId:{}", id);   
      }     
    } }




0 个回复

您需要登录后才可以回帖 登录 | 加入黑马