package com.ssj.rabbitmq;

import com.ssj.framework.core.rabbitmq.TopicRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.ssj.bean.weixin.push.domain.SendTemplateShort;

import com.ssj.service.weixin.push.service.PushTemplateService;


public class TopicRabbitConsumer {
	
	  private static Logger logger = LoggerFactory.getLogger(TopicRabbitConsumer.class);
		
	  @Autowired
	  private PushTemplateService pushTemplateService;
	  
	  @RabbitListener(queues = {TopicRabbitConfig.topic_push_messages_wx},containerFactory = "customContainerFactory")
	  @RabbitHandler
	  public void handleMessage(Message message){
		  logger.info("消息队列开始消费 ....");
		  SendTemplateShort sendTemplateShort=JSONObject.parseObject(message.getBody(),SendTemplateShort.class);
		  logger.error("开始消费推送信息队列数据："+JSONObject.toJSONString(sendTemplateShort));
		  pushTemplateService.saveAndSendPushWxTemplate(sendTemplateShort);   
		  logger.info("消息队列完成消费...");
	  }
}


