This example demonstrates a Spring Boot example running a Camel REST route connecting to a PostgreSQL database.
The application utilizes the Spring @ImportResource
annotation to load a Camel Context definition via a camel-context.xml file on the classpath.
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
~/Projects/git/beer-api on master*
$ oc login -u developer -p developer
Login successful.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
$ oc new-project beer
Now using project "beer" on server "https://192.168.64.29:8443".
You can add applications to this project with the 'new-app' command. For example, try:
oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git
to build a new example application in Ruby.
-
Go to the OpenShift Web Console
-
Select the beer project previously created
-
Add a PostgreSQL database with the following settings:
- Database service name: postgresql
- PostgreSQL Connection Username: beeruser
- PostgreSQL Connection Password: beerpw
- PostgreSQL Database Name: beerdb
Grep the running postgresql pod with:
$ oc get pods | grep postgresql
postgresql-1-qjq75 1/1 Running 0 1m
- Copy data files into the pod
To create the tables and load data into the table use the following steps:
$ oc cp postgres/breweries.csv postgresql-1-qjq75:/tmp/
$ oc cp postgres/beers.csv postgresql-1-qjq75:/tmp/
$ oc cp postgres/*.sql postgresql-1-qjq75:/tmp/
$ oc rsh postgresql-1-qjq75
sh-4.2$ ls /tmp
beers.csv breweries.csv ks-script-hE5IPf openbeer-psql.sql yum.log
sh-4.2$ psql -d beerdb -f /tmp/openbeer-psql.sql -W
Password: postgres
CREATE TABLE
COPY 1414
CREATE TABLE
COPY 5901
sh-4.2$ psql -d beerdb
beerdb=# grant all privileges on all tables in schema public to beeruser;
GRANT
beerdb=# \q
sh-4.2$ exit
The example can be built and run on OpenShift using a single goal:
mvn -s settings.xml fabric8:deploy
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.
You can use the following URLs (replace api-route with the correct URL as mentioned in the OpenShift Web Console) to test out the API we just implemented and is running on Red Hat OpenShift and waiting to be consumed.
-
Get all the beers
-
Get beer information by id
-
Get beer information by name
-
Get beer by alcolhol percentage