camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaHoopster <hw...@structuralinvest.com>
Subject Re: Writing customer component, endpoint and producer
Date Wed, 10 Mar 2010 07:24:38 GMT

I find this concept rather unintuitive. I'd perceive it as
from (producer) to (consumer). Why is it from (consumer) to (producer) ?

Thanks,


Claus Ibsen-2 wrote:
> 
> from = consumer
> to = producer
> 
> 
> 
> On Wed, Mar 10, 2010 at 8:13 AM, DaHoopster <hwang@structuralinvest.com>
> wrote:
>>
>> Hi,
>>
>> Maybe I am not getting the concept correctly. I am trying to write a web
>> scraper that scrapes a page and generate some messages. I think I need to
>> write a Producer, correct me if I am wrong.
>>
>> So I went ahead and wrote a custom component along with an endpoint and a
>> producer. But for some reason the producer was not created by the
>> endpoint.
>> Could you see what's wrong with my code?
>>
>> Many thanks.
>>
>> Code:
>>
>> ================ Main.java ===================================
>>        this.camelContext.addComponent("scraper", scrapingComponent);
>>        this.camelContext.addRoutes(new RouteBuilder()
>>        {
>>            @Override
>>            public void configure() throws Exception
>>            {
>>                from("scraper:" + ScrapingEndpoint.URI).
>>                process(new Processor()
>>                {
>>                    public void process(final Exchange exchange) throws
>> Exception
>>                    {
>>                        System.out.println("Yay !!!");
>>                    }
>>                });
>>            }
>>        });
>>        this.camelContext.start();
>> ===============================================================
>>
>> ================ ScrapingComponent.java ==========================
>> public class ScrapingComponent extends DefaultComponent
>> {
>>
>>    @Override
>>    protected Endpoint createEndpoint(final String uri, final String
>> remaining, final Map<String, Object> parameters) throws Exception
>>    {
>>        return new ScrapingEndpoint(uri, ScrapingComponent.this);
>>    }
>> }
>> ==============================================================
>>
>> ================ ScrapingEndpoint.java =============================
>> public class ScrapingEndpoint extends DefaultEndpoint
>> {
>>    public static final String URI = "scraper:hello";
>>
>>    public BondDeskScrapingEndpoint(final String endpointUri, final
>> Component component)
>>    {
>>        super(endpointUri, component);
>>    }
>>
>>    public ScrapingEndpoint(final String endpointUri)
>>    {
>>        super(endpointUri);
>>    }
>>
>>    public Producer createProducer() throws Exception
>>    {
>>        return new ScrapingProducer(this);
>>    }
>>
>>    public Consumer createConsumer(final Processor processor) throws
>> Exception
>>    {
>>        return new ScrapingConsumer(this, processor);
>>    }
>>
>>    public boolean isSingleton()
>>    {
>>        return true;
>>    }
>>
>>    @Override
>>    protected String createEndpointUri()
>>    {
>>        return URI;
>>    }
>>
>>    @Override
>>    public boolean isLenientProperties()
>>    {
>>        return true;
>>    }
>> }
>> ===============================================================
>>
>> ================= ScrapingProducer ================================
>> public class ScrapingProducer extends DefaultProducer
>> {
>>    private MyScraper scraper;
>>
>>    public BondDeskScrapingProducer(Endpoint endpoint)
>>    {
>>        super(endpoint);
>>        this.scaper = new MyScraper();
>>        System.out.println("=== creating producer ===");
>>    }
>>
>>    public void process(final Exchange exchange) throws Exception
>>    {
>>        System.out.println("=== processing ===");
>>        final List<Item> items = bondDeskScraper.scrape();
>>        exchange.getIn().setBody(items.get(0).toString());
>>    }
>> ==============================================================
>>
>> =================== ScrapingConsumer.java =========================
>> public class ScrapingConsumer extends DefaultConsumer
>> {
>>    public ScrapingConsumer(Endpoint endpoint, Processor processor)
>>    {
>>        super(endpoint, processor);
>>    }
>> }
>> ==============================================================
>> --
>> View this message in context:
>> http://old.nabble.com/Writing-customer-component%2C-endpoint-and-producer-tp27846283p27846283.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://old.nabble.com/Writing-customer-component%2C-endpoint-and-producer-tp27846283p27846351.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message