Deploy custom Camel code on Apache Karaf

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Deploy custom Camel code on Apache Karaf

Kirti Arora
Hi,

I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
camel code bundle to deploy directory of Karaf but not able to find routes
available in the code, also not able to request the endpoints.

Can someone please guide me, how can I deploy camel code on Apache Karaf?
It would be very helpful if someone can provide me an example.

Thanks,
Kirti Arora
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

Francois Papon
Hi,

You have some examples here:

https://github.com/apache/karaf/tree/master/examples/karaf-camel-example

regards,

François
[hidden email]

Le 04/10/2019 à 14:22, Kirti Arora a écrit :

> Hi,
>
> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
> camel code bundle to deploy directory of Karaf but not able to find routes
> available in the code, also not able to request the endpoints.
>
> Can someone please guide me, how can I deploy camel code on Apache Karaf?
> It would be very helpful if someone can provide me an example.
>
> Thanks,
> Kirti Arora
>
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

jbonofre
In reply to this post by Kirti Arora
Hi,

you can take a look on the examples here:

https://github.com/apache/karaf/tree/master/examples/karaf-camel-example

You have an example using blueprint DSL, an example using Java DSL. I'm
adding SCR package.

If you have any question, please let me know.

Regards
JB

On 04/10/2019 14:22, Kirti Arora wrote:

> Hi,
>
> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
> camel code bundle to deploy directory of Karaf but not able to find routes
> available in the code, also not able to request the endpoints.
>
> Can someone please guide me, how can I deploy camel code on Apache Karaf?
> It would be very helpful if someone can provide me an example.
>
> Thanks,
> Kirti Arora
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

Kirti Arora
Hi Jean and Francois,

Thanks for the reply :)

I have already seen the examples and successfully execute the one given in
/apache-karaf/examples/karaf-camel-example/karaf-camel-example-java
 directory.

But when I'm trying to put my own camel code, I'm not able to call the
route endpoint.

For eg. I want to hit the below mentioned URL

from("direct:start")
    .setHeader(Exchange.HTTP_METHOD, simple("GET"))
    .to("http://dummy.restapiexample.com/api/v1/employees");

How can I do this?
Thanks,
Kirti Arora


On Sat, Oct 5, 2019 at 5:11 PM Jean-Baptiste Onofré <[hidden email]> wrote:

> Hi,
>
> you can take a look on the examples here:
>
> https://github.com/apache/karaf/tree/master/examples/karaf-camel-example
>
> You have an example using blueprint DSL, an example using Java DSL. I'm
> adding SCR package.
>
> If you have any question, please let me know.
>
> Regards
> JB
>
> On 04/10/2019 14:22, Kirti Arora wrote:
> > Hi,
> >
> > I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
> > camel code bundle to deploy directory of Karaf but not able to find
> routes
> > available in the code, also not able to request the endpoints.
> >
> > Can someone please guide me, how can I deploy camel code on Apache Karaf?
> > It would be very helpful if someone can provide me an example.
> >
> > Thanks,
> > Kirti Arora
> >
>
> --
> Jean-Baptiste Onofré
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

jbonofre
Hi,

Your route looks weird to me.

What's the direct:start trigger ?
What do you do with the reply ?

For instance, a valid testing route would be:

from("timer:foo?period=5000").to("...").log("Received ${body}")

Or at least expose an endpoint as a bridge (as we do in the Karaf example).

Regards
JB

On 07/10/2019 07:49, Kirti Arora wrote:

> Hi Jean and Francois,
>
> Thanks for the reply :)
>
> I have already seen the examples and successfully execute the one given in
> /apache-karaf/examples/karaf-camel-example/karaf-camel-example-java
>  directory.
>
> But when I'm trying to put my own camel code, I'm not able to call the
> route endpoint.
>
> For eg. I want to hit the below mentioned URL
>
> from("direct:start")
>     .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>     .to("http://dummy.restapiexample.com/api/v1/employees");
>
> How can I do this?
> Thanks,
> Kirti Arora
>
>
> On Sat, Oct 5, 2019 at 5:11 PM Jean-Baptiste Onofré <[hidden email]> wrote:
>
>> Hi,
>>
>> you can take a look on the examples here:
>>
>> https://github.com/apache/karaf/tree/master/examples/karaf-camel-example
>>
>> You have an example using blueprint DSL, an example using Java DSL. I'm
>> adding SCR package.
>>
>> If you have any question, please let me know.
>>
>> Regards
>> JB
>>
>> On 04/10/2019 14:22, Kirti Arora wrote:
>>> Hi,
>>>
>>> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
>>> camel code bundle to deploy directory of Karaf but not able to find
>> routes
>>> available in the code, also not able to request the endpoints.
>>>
>>> Can someone please guide me, how can I deploy camel code on Apache Karaf?
>>> It would be very helpful if someone can provide me an example.
>>>
>>> Thanks,
>>> Kirti Arora
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> [hidden email]
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

Kirti Arora
Hi,

I'm trying to expose endpoint from the main() method using
producerTemplate.requestBody().

I have two classes; one is main from which I'm requesting an endpoint and
another one(SimpleRouteBuilder) to configure
the route.

public class MainClass {

    public static void main(String args[]) {
        SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
        CamelContext ctx = new DefaultCamelContext();
        try {
            ctx.addRoutes(routeBuilder);
            ctx.start();

            ProducerTemplate producerTemplate = ctx.createProducerTemplate();
            String response =
producerTemplate.requestBody("direct:start", "", String.class);
            System.out.println(response);
            Thread.sleep(5 * 1000);
            ctx.stop();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}



public class SimpleRouteBuilder extends RouteBuilder {

    @Override
    public void configure() {
        from("direct:start").setHeader(Exchange.HTTP_METHOD, simple("GET"))
            .to("http://dummy.restapiexample.com/api/v1/employees");
    }
}

Thanks, Kirti Arora


On Mon, Oct 7, 2019 at 11:43 AM Jean-Baptiste Onofré <[hidden email]>
wrote:

> Hi,
>
> Your route looks weird to me.
>
> What's the direct:start trigger ?
> What do you do with the reply ?
>
> For instance, a valid testing route would be:
>
> from("timer:foo?period=5000").to("...").log("Received ${body}")
>
> Or at least expose an endpoint as a bridge (as we do in the Karaf example).
>
> Regards
> JB
>
> On 07/10/2019 07:49, Kirti Arora wrote:
> > Hi Jean and Francois,
> >
> > Thanks for the reply :)
> >
> > I have already seen the examples and successfully execute the one given
> in
> > /apache-karaf/examples/karaf-camel-example/karaf-camel-example-java
> >  directory.
> >
> > But when I'm trying to put my own camel code, I'm not able to call the
> > route endpoint.
> >
> > For eg. I want to hit the below mentioned URL
> >
> > from("direct:start")
> >     .setHeader(Exchange.HTTP_METHOD, simple("GET"))
> >     .to("http://dummy.restapiexample.com/api/v1/employees");
> >
> > How can I do this?
> > Thanks,
> > Kirti Arora
> >
> >
> > On Sat, Oct 5, 2019 at 5:11 PM Jean-Baptiste Onofré <[hidden email]>
> wrote:
> >
> >> Hi,
> >>
> >> you can take a look on the examples here:
> >>
> >>
> https://github.com/apache/karaf/tree/master/examples/karaf-camel-example
> >>
> >> You have an example using blueprint DSL, an example using Java DSL. I'm
> >> adding SCR package.
> >>
> >> If you have any question, please let me know.
> >>
> >> Regards
> >> JB
> >>
> >> On 04/10/2019 14:22, Kirti Arora wrote:
> >>> Hi,
> >>>
> >>> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
> >>> camel code bundle to deploy directory of Karaf but not able to find
> >> routes
> >>> available in the code, also not able to request the endpoints.
> >>>
> >>> Can someone please guide me, how can I deploy camel code on Apache
> Karaf?
> >>> It would be very helpful if someone can provide me an example.
> >>>
> >>> Thanks,
> >>> Kirti Arora
> >>>
> >>
> >> --
> >> Jean-Baptiste Onofré
> >> [hidden email]
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
> >>
> >
>
> --
> Jean-Baptiste Onofré
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

jbonofre
Hi,

If you don't run in Karaf, that won't work because you are in two
different JVM: the one executing your Main, the one for Karaf.

direct endpoints are visible only in the same JVM and for direct it's in
the same CamelContext ! If you want to communicate between two routes
from different camel context (still in the same JVM), you have to use
direct-vm.

If you try to execute your Main in Karaf (by dropping the jar in deploy
folder), it's what I understood, that won't work.
To do that, you have to use exec in Karaf or create a bundle with a
activator (acting as kind of main).

It would be easier to actually expose a concrete endpoint (as we do in
example with jetty for instance).

Regards
JB

On 07/10/2019 09:14, Kirti Arora wrote:

> Hi,
>
> I'm trying to expose endpoint from the main() method using
> producerTemplate.requestBody().
>
> I have two classes; one is main from which I'm requesting an endpoint and
> another one(SimpleRouteBuilder) to configure
> the route.
>
> public class MainClass {
>
>     public static void main(String args[]) {
>         SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
>         CamelContext ctx = new DefaultCamelContext();
>         try {
>             ctx.addRoutes(routeBuilder);
>             ctx.start();
>
>             ProducerTemplate producerTemplate = ctx.createProducerTemplate();
>             String response =
> producerTemplate.requestBody("direct:start", "", String.class);
>             System.out.println(response);
>             Thread.sleep(5 * 1000);
>             ctx.stop();
>         }
>         catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
>
>
>
> public class SimpleRouteBuilder extends RouteBuilder {
>
>     @Override
>     public void configure() {
>         from("direct:start").setHeader(Exchange.HTTP_METHOD, simple("GET"))
>             .to("http://dummy.restapiexample.com/api/v1/employees");
>     }
> }
>
> Thanks, Kirti Arora
>
>
> On Mon, Oct 7, 2019 at 11:43 AM Jean-Baptiste Onofré <[hidden email]>
> wrote:
>
>> Hi,
>>
>> Your route looks weird to me.
>>
>> What's the direct:start trigger ?
>> What do you do with the reply ?
>>
>> For instance, a valid testing route would be:
>>
>> from("timer:foo?period=5000").to("...").log("Received ${body}")
>>
>> Or at least expose an endpoint as a bridge (as we do in the Karaf example).
>>
>> Regards
>> JB
>>
>> On 07/10/2019 07:49, Kirti Arora wrote:
>>> Hi Jean and Francois,
>>>
>>> Thanks for the reply :)
>>>
>>> I have already seen the examples and successfully execute the one given
>> in
>>> /apache-karaf/examples/karaf-camel-example/karaf-camel-example-java
>>>  directory.
>>>
>>> But when I'm trying to put my own camel code, I'm not able to call the
>>> route endpoint.
>>>
>>> For eg. I want to hit the below mentioned URL
>>>
>>> from("direct:start")
>>>     .setHeader(Exchange.HTTP_METHOD, simple("GET"))
>>>     .to("http://dummy.restapiexample.com/api/v1/employees");
>>>
>>> How can I do this?
>>> Thanks,
>>> Kirti Arora
>>>
>>>
>>> On Sat, Oct 5, 2019 at 5:11 PM Jean-Baptiste Onofré <[hidden email]>
>> wrote:
>>>
>>>> Hi,
>>>>
>>>> you can take a look on the examples here:
>>>>
>>>>
>> https://github.com/apache/karaf/tree/master/examples/karaf-camel-example
>>>>
>>>> You have an example using blueprint DSL, an example using Java DSL. I'm
>>>> adding SCR package.
>>>>
>>>> If you have any question, please let me know.
>>>>
>>>> Regards
>>>> JB
>>>>
>>>> On 04/10/2019 14:22, Kirti Arora wrote:
>>>>> Hi,
>>>>>
>>>>> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
>>>>> camel code bundle to deploy directory of Karaf but not able to find
>>>> routes
>>>>> available in the code, also not able to request the endpoints.
>>>>>
>>>>> Can someone please guide me, how can I deploy camel code on Apache
>> Karaf?
>>>>> It would be very helpful if someone can provide me an example.
>>>>>
>>>>> Thanks,
>>>>> Kirti Arora
>>>>>
>>>>
>>>> --
>>>> Jean-Baptiste Onofré
>>>> [hidden email]
>>>> http://blog.nanthrax.net
>>>> Talend - http://www.talend.com
>>>>
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> [hidden email]
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

Kirti Arora
Hi Jean,

Thanks a lot, It worked with Activator Bundle.

Regards,
kirti Arora
Reply | Threaded
Open this post in threaded view
|

Re: Deploy custom Camel code on Apache Karaf

jbonofre
Cool ! Thanks for the update.

Don't hesitate to ping if you need help.

Regards
JB

On 14/10/2019 08:43, Kirti Arora wrote:
> Hi Jean,
>
> Thanks a lot, It worked with Activator Bundle.
>
> Regards,
> kirti Arora
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com