Giter VIP home page Giter VIP logo

spring-boot-camel-rest-sql's Introduction

Spring Boot Camel REST / SQL QuickStart

This example demonstrates how to use SQL via JDBC along with Camel's REST DSL to expose a RESTful API.

This example relies on the Fabric8 Maven plugin for its build configuration and uses the fabric8 Java base image.

Building

The example can be built with:

$ mvn install

This automatically generates the application resource descriptors and builds the Docker image, so it requires access to a Docker daemon, relying on the DOCKER_HOST environment variable by default.

Running the example locally

The example can be run locally using the following Maven goal:

$ mvn spring-boot:run

Alternatively, you can run the application locally using the executable JAR produced:

$ java -jar -Dspring.profiles.active=dev target/spring-boot-camel-rest-sql-1.0-SNAPSHOT.jar

This uses an embedded in-memory HSQLDB database. You can use the default Spring Boot profile in case you have a MySQL server available for you to test.

You can then access the REST API directly from your Web browser, e.g.:

Running the example in Kubernetes / OpenShift

It is assumed a Kubernetes / OpenShift platform is already running. If not, you can find details how to get started.

Besides, it is assumed that a MySQL service is already running on the platform. You can deploy it using the provided deployment by executing in Kubernetes:

$ kubectl create -f mysql-deployment.yml

or in OpenShift:

$ oc create -f https://raw.githubusercontent.com/openshift/origin/master/examples/db-templates/mysql-ephemeral-template.json
$ oc new-app --template=mysql-ephemeral

More information can be found in using the MySQL database image. You may need to pass MYSQL_RANDOM_ROOT_PASSWORD=true as environment variable to the deployment.

The example can then be built and deployed using a single goal:

$ mvn fabric8:run -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.

You can use the Kubernetes or OpenShift client tool to inspect the status, e.g.:

  • To list all the running pods:

    $ kubectl get pods
    
  • or on OpenShift:

    $ oc get pods
    
  • Then find the name of the pod that runs this example, and output the logs from the running pod with:

    $ kubectl logs <pod_name>
    
  • or on OpenShift:

    $ oc logs <pod_name>
    

You can also use the Fabric8 Web console to manage the running pods, view logs and much more.

Accessing the REST service

When the example is running, a REST service is available to list the books that can be ordered, and as well the order statuses.

If you run the example on a local Fabric8 installation using Vagrant, then the REST service is exposed at http://qs-camel-rest-sql.vagrant.f8.

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 order id.

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

Swagger API

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.vagrant.f8/camel-rest-sql/api-doc.

More details

You can find more details about running this quickstart on the website. This also includes instructions how to change the Docker image user and registry.

spring-boot-camel-rest-sql's People

Contributors

fusesource-ci avatar astefanutti avatar chirino avatar lburgazzoli avatar nicolaferraro avatar dhirajsb avatar valdar avatar bparry02 avatar jamesnetherton avatar cunningt avatar

Watchers

769249234@qq.com avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.