Mule ESB 学习笔记(19)Mule和RSS的整合

阅读更多

定时扫描特定目录的rss文件:




    

    
        
            
            
            
        
         
        
            
        
    


 

轮询特定的路径:




    

    
        
        
        
    

 

 

定期从jms发送rss文件信息,并读取:




   
   
   
     
       
   
    
    
        

        
            
        
    

    
        
            
        
        
           
        
    


 

 

手动生成rss文件:




    

    

    
        
            
            
               
        
        
    

 

 

package com.easyway.esb.mule.rss;

import org.mule.api.annotations.param.Payload;

import com.sun.syndication.feed.synd.SyndEntry;

import java.util.concurrent.atomic.AtomicInteger;
/**
 * 
 * @author longgangbai
 *
 */
public class EntryReceiver
{
    private AtomicInteger count = new AtomicInteger(0);

    public void readEntry(@Payload SyndEntry entry) throws Exception
    {
        count.getAndIncrement();
    }

    public int getCount()
    {
        return count.get();
    }
}

 

 

package com.easyway.esb.mule.rss;

import org.mule.api.annotations.param.Payload;

import com.sun.syndication.feed.synd.SyndFeed;

import java.util.concurrent.atomic.AtomicInteger;
/**
 * 
 * @author longgangbai
 *
 */
public class FeedReceiver
{
    private AtomicInteger count = new AtomicInteger(0);

    public void readFeed(@Payload SyndFeed feed) throws Exception
    {
        count.set(feed.getEntries().size());            
    }

    public int getCount()
    {
        return count.get();
    }
}

 

 测试代码:

/*
 * Copyright (c) EASYWAY 2011 All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.easyway.esb.mule.rss;
import java.io.File;

import org.apache.commons.io.FileUtils;
import org.mule.api.MuleContext;
import org.mule.api.client.MuleClient;
import org.mule.api.context.MuleContextFactory;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;
/**
 * 

鍔熻兘鎻忚堪,璇ラ儴鍒嗗繀椤讳互涓枃鍙ュ彿缁撳熬銆�p> * * 鍒涘缓鏃ユ湡 2013-8-26
* @author $Author$
* @version $Revision$ $Date$ * @since 3.0.0 */ public class MuleRssMain { public static void main(String[] args) { try { String configFile = "jms-rss-consume.xml"; System.setProperty("mule.verbose.exceptions","true"); String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext muleContext = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); muleContext.start(); MuleClient client = muleContext.getClient(); FeedReceiver component = (FeedReceiver)muleContext.getRegistry().get("feedConsumer"); String path=MuleRssMain.class.getClassLoader().getResource("./sample-feed.rss").getFile(); String feed=FileUtils.readFileToString(new File(path)); client.dispatch("jms://feed.in", feed, null); Thread.sleep(2000); System.out.println(component.getCount()); client = muleContext.getClient(); component = (FeedReceiver)muleContext.getRegistry().get("feedConsumer"); client.dispatch("jms://feed.split.in", feed, null); Thread.sleep(5000); System.out.println(component.getCount()); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }

 

 

你可能感兴趣的:(mule,ESB,SOA,http,polling轮询,RSS)