You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by DaHoopster <hw...@structuralinvest.com> on 2010/03/10 08:13:40 UTC

Writing customer component, endpoint and producer

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.


Re: Writing customer component, endpoint and producer

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 10, 2010 at 8:40 AM, DaHoopster <hw...@structuralinvest.com> wrote:
>
> Thanks for the resources.
>
> But coming back to my scraper example, the scraper is trying to produce
> messages for other downstream systems. How should I set up the route then?
>

from("timer:foo?period=5000").to("scrapter:xxxx").to("log:foo");

Will call your scraper producer every 5th second and send the output to log:foo


>
> Claus Ibsen-2 wrote:
>>
>> On Wed, Mar 10, 2010 at 8:24 AM, DaHoopster <hw...@structuralinvest.com>
>> wrote:
>>>
>>> I find this concept rather unintuitive. I'd perceive it as
>>> from (producer) to (consumer). Why is it from (consumer) to (producer) ?
>>>
>>
>> I suggest to read chapter 1 in the Camel in Action book to get
>> familiar with the Camel concepts and integration concepts in general.
>> http://www.manning.com/ibsen
>>
>> produce = create a new message to be send to another source
>> consume = receive an existing message from another source
>>
>>
>>
>> There is also some info here, but its a bit old
>> http://camel.apache.org/book-getting-started.html
>>
>> And the EIP book is also a good source of concepts
>> http://www.enterpriseintegrationpatterns.com/toc.html
>>
>>
>>
>>> Thanks,
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> from = consumer
>>>> to = producer
>>>>
>>>>
>>>>
>>>> On Wed, Mar 10, 2010 at 8:13 AM, DaHoopster <hw...@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.
>>>
>>>
>>
>>
>>
>> --
>> 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-tp27846283p27846442.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

Re: Writing customer component, endpoint and producer

Posted by DaHoopster <hw...@structuralinvest.com>.
Thanks for the resources.

But coming back to my scraper example, the scraper is trying to produce
messages for other downstream systems. How should I set up the route then?


Claus Ibsen-2 wrote:
> 
> On Wed, Mar 10, 2010 at 8:24 AM, DaHoopster <hw...@structuralinvest.com>
> wrote:
>>
>> I find this concept rather unintuitive. I'd perceive it as
>> from (producer) to (consumer). Why is it from (consumer) to (producer) ?
>>
> 
> I suggest to read chapter 1 in the Camel in Action book to get
> familiar with the Camel concepts and integration concepts in general.
> http://www.manning.com/ibsen
> 
> produce = create a new message to be send to another source
> consume = receive an existing message from another source
> 
> 
> 
> There is also some info here, but its a bit old
> http://camel.apache.org/book-getting-started.html
> 
> And the EIP book is also a good source of concepts
> http://www.enterpriseintegrationpatterns.com/toc.html
> 
> 
> 
>> Thanks,
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> from = consumer
>>> to = producer
>>>
>>>
>>>
>>> On Wed, Mar 10, 2010 at 8:13 AM, DaHoopster <hw...@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.
>>
>>
> 
> 
> 
> -- 
> 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-tp27846283p27846442.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Writing customer component, endpoint and producer

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 10, 2010 at 8:24 AM, DaHoopster <hw...@structuralinvest.com> wrote:
>
> I find this concept rather unintuitive. I'd perceive it as
> from (producer) to (consumer). Why is it from (consumer) to (producer) ?
>

I suggest to read chapter 1 in the Camel in Action book to get
familiar with the Camel concepts and integration concepts in general.
http://www.manning.com/ibsen

produce = create a new message to be send to another source
consume = receive an existing message from another source



There is also some info here, but its a bit old
http://camel.apache.org/book-getting-started.html

And the EIP book is also a good source of concepts
http://www.enterpriseintegrationpatterns.com/toc.html



> Thanks,
>
>
> Claus Ibsen-2 wrote:
>>
>> from = consumer
>> to = producer
>>
>>
>>
>> On Wed, Mar 10, 2010 at 8:13 AM, DaHoopster <hw...@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.
>
>



-- 
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

Re: Writing customer component, endpoint and producer

Posted by DaHoopster <hw...@structuralinvest.com>.
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 <hw...@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.


Re: Writing customer component, endpoint and producer

Posted by Claus Ibsen <cl...@gmail.com>.
from = consumer
to = producer



On Wed, Mar 10, 2010 at 8:13 AM, DaHoopster <hw...@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