1.2.3 RabbitmqConfig配置类 消息队列设置如下: 1、创建“ex_cms_postpage”交换机 2、每个Cms Client创建一个队列与交换机绑定 3、每个Cms Client程序配置队列名称和routingKey,将站点ID作为routingKey。

package com.xuecheng.manage_cms_client.config;  
 import org.springframework.amqp.core.*; 
import org.springframework.beans.factory.annotation.Qualifier; 
import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration;  
 /**  * @author Administrator  * @version 1.0  **/ @Configuration public class RabbitmqConfig {  
  //队列bean的名称     
public static final String QUEUE_CMS_POSTPAGE = "queue_cms_postpage";  
   //交换机的名称 
    public static final String EX_ROUTING_CMS_POSTPAGE="ex_routing_cms_postpage"; 
    //队列的名称    
 @Value("${xuecheng.mq.queue}")  
  public  String queue_cms_postpage_name;   
  //routingKey 即站点Id   
  @Value("${xuecheng.mq.routingKey}")  
  public  String routingKey;   
  /** 
    * 交换机配置使用direct类型  
    * @return the exchange   
   */  
  @Bean(EX_ROUTING_CMS_POSTPAGE) 
   public Exchange EXCHANGE_TOPICS_INFORM() {     
   return ExchangeBuilder.directExchange(EX_ROUTING_CMS_POSTPAGE).durable(true).build();  
   }    
//声明队列 
    @Bean(QUEUE_CMS_POSTPAGE) 
   public Queue QUEUE_CMS_POSTPAGE() {   
     Queue queue = new Queue(queue_cms_postpage_name);   
      return queue;  
   }   
   /** 
    * 绑定队列到交换机  
    * 
    * @param queue  
  the queue  
    * @param exchange the exchange

* @return the binding    
 */   
@Bean  
  public Binding BINDING_QUEUE_INFORM_SMS(@Qualifier(QUEUE_CMS_POSTPAGE) Queue queue,  @Qualifier(EX_ROUTING_CMS_POSTPAGE) Exchange exchange) { 
      return BindingBuilder.bind(queue).to(exchange).with(routingKey).noargs();   
 }
} 

1.2.4 定义消息格式 消息内容采用json格式存储数据,如下: 页面id:发布页面的id



{  
  "pageId":""
}

1.2.5 PageDao 1、使用CmsPageRepository 查询页面信息


public interface CmsPageRepository extends MongoRepository<CmsPage,String> {
}

2、使用CmsSiteRepository查询站点信息,主要获取站点物理路径


public interface CmsSiteRepository extends MongoRepository<CmsSite,String> {
 }