Skip to content

Latest commit

 

History

History
 
 

http-log

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

HTTP with vanilla JAX-RS or with Camel platform-http component: A Camel Quarkus example

{cq-description}

The Quarkus REST service ExampleResource.java and the Camel route CamelRoute.java are independent and are present in this example to demonstrate how you can build microservices with both Quarkus and Camel separated.

You can of course also combine Quarkus REST services with Camel (see further below).

Tip
Check the Camel Quarkus User guide for prerequisites and other general information.

This example was used in a 10 minute video recording to demonstrate how to quickly run 100 Camels with Apache Camel, Quarkus and GraalVM:

Start in the Development mode

$ mvn clean compile quarkus:dev

The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application.

Tip
Please refer to the Development mode section of Camel Quarkus User guide for more details.

From a web browser, you can call the two services via

There is also health check and metrics available from the following urls:

Package and run the application

Once you are done with developing you may want to package and run the application.

Tip
Find more details about the JVM mode and Native mode in the Package and run section of Camel Quarkus User guide

JVM mode

$ mvn clean package
$ java -jar target/quarkus-app/quarkus-run.jar
...
[io.quarkus] (main) camel-quarkus-examples-... started in 1.163s. Listening on: http://0.0.0.0:8080

Native mode

Important
Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section of Camel Quarkus User guide.

To prepare a native executable using GraalVM, run the following command:

$ mvn clean package -Pnative
$ ./target/*-runner
...
[io.quarkus] (main) camel-quarkus-examples-... started in 0.013s. Listening on: http://0.0.0.0:8080
...

Using Camel from Quarkus JAX-RS

The ExampleResource.java is a pure JAX-RS REST service without using Camel. Suppose you wanted to add a HTTP POST that sends the HTTP body to a Kafka topic, via the camel-kafka component. You can then integrate Quarkus with Camel by dependency injecting Camels FluentProducerTemplate that allows to send the message in one line of code to Kafka. What’s left is to configure the URL to the Kafka brokers, which can be done in the application.properties file.

import org.apache.camel.FluentProducerTemplate;
import org.jboss.resteasy.annotations.Body;
import javax.inject.Inject;
import javax.ws.rs.Consumes;

@Path("/hello")
public class ExampleResource {

    @Inject
    FluentProducerTemplate producer;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "hello";
    }

    @POST
    @Consumes(MediaType.TEXT_PLAIN)
    public void foo(@Body String payload) {
        producer.to("kafka:foo").send(payload);
    }
}

Feedback

Please report bugs and propose improvements via GitHub issues of Camel Quarkus project.