This example demonstrates how to use SQL via JDBC along with Camel's REST DSL to expose a RESTful API.
The example can be built with
mvn clean install
It is assumed that:
- OpenShift platform is already running, if not you can find details how to Install OpenShift at your site.
- Your system is configured for Fabric8 Maven Workflow, if not you can find a Get Started Guide
- The OpenShift MySQL container image should already be installed and running on your OpenShift installation, one simple way to run a MySQL service is following the documentation of the Openshift MySQL container image related to the
mysql-ephemeral
template.
The example can then be built and deployed using a single goal:
$ mvn fabric8:deploy -Dmysql-service-username=<username> -Dmysql-service-password=<password>
The username
and password
system properties correspond to the credentials
used when deploying the MySQL database service.
To list all the running pods:
oc get pods
Then find the name of the pod that runs this quickstart, and output the logs from the running pods with:
oc logs <name of pod>
You can also use the OpenShift web console to manage the running pods, and view logs and much more.
Application templates allow you deploy applications to OpenShift by filling out a form in the OpenShift console that allows you to adjust deployment parameters. This template uses an S2I source build so that it handle building and deploying the application for you.
First, import the Fuse image streams:
oc create -f https://raw.githubusercontent.com/jboss-fuse/application-templates/GA/fis-image-streams.json
Then create the quickstart template:
oc create -f https://raw.githubusercontent.com/jboss-fuse/application-templates/GA/quickstarts/spring-boot-camel-rest-sql-template.json
Now when you use "Add to Project" button in the OpenShift console, you should see a template for this quickstart.
When the example is running, a REST service is available to list the books that can be ordered, and as well the order statuses.
Notice: As it depends on your OpenShift setup, the hostname (route) might vary. Verify with oc get routes
which hostname is valid for you. Add the -Dfabric8.deploy.createExternalUrls=true
option to your Maven commands if you want it to deploy a Route configuration for the service.
The actual endpoint is using the context-path camel-rest-sql/books
and the REST service provides two services:
books
: to list all the available books that can be ordered,books/order/{id}
: to output order status for the given orderid
.
The example automatically creates new orders with a running order id
starting from 1.
You can then access these services from your Web browser, e.g.:
- http://qs-camel-rest-sql.example.com/camel-rest-sql/books
- http://qs-camel-rest-sql.example.com/camel-rest-sql/books/order/1
The example provides API documentation of the service using Swagger using the context-path camel-rest-sql/api-doc
. You can access the API documentation from your Web browser at http://qs-camel-rest-sql.example.com/camel-rest-sql/api-doc.