Git Product home page Git Product logo

spring-boot-camel-rest-3scale's Introduction

Spring Boot Camel REST 3scale QuickStart

This example demonstrates how to use Camel’s REST DSL to expose a RESTful API and expose it to 3scale.

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

The Openshift Maven Plugin discovers service metadata from Camel XML Context’s service definition and exposes the following:

Service Label

  • discovery.3scale.net: Allows 3scale to select Services that are to be automatically exposed.

Service Annotations

  • discovery.3scale.net/discovery-version: the version of the 3scale discovery process.

  • discovery.3scale.net/scheme: this can be http or https

  • discovery.3scale.net/path: (optional) the contextPath of the service if it’s not at the root.

  • discovery.3scale.net/description-path: (optional) the path to the service description document (OpenAPI/Swagger). The path is either relative or an external full URL.

The application utilizes the Spring @ImportResource annotation to load a Camel Context definition via a src/main/resources/spring/camel-context.xml file on the classpath.

Important
This quickstart can run in 2 modes: standalone on your machine and on Kubernetes / OpenShift Cluster. Quickstart requires Java 8 or Java 11 (fuse-java-openshift-jdk11-rhel8 image is used to build in Java 11).

Deployment options

You can run this quickstart in the following modes:

  • Kubernetes / Single-node OpenShift cluster

  • Standalone on your machine

The most effective way to run this quickstart is to deploy and run the project on OpenShift.

For more details about running this quickstart on a single-node OpenShift cluster, CI/CD deployments, as well as the rest of the runtime, see the Spring Boot Runtime Guide.

Running the Quickstart on a single-node Kubernetes/OpenShift cluster

Important
You need to run this example on Container Development Kit 3.3 or OpenShift 3.7. Both of these products have suitable Fuse images pre-installed. If you run it in an environment where those images are not preinstalled follow the steps described in Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images.

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-rest-3scale) :

    or

    $ cd my_openshift/spring-boot-camel-rest-3scale
  4. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift
  5. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-rest-3scale has started up.

  6. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-rest-3scale application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/pods/spring-boot-camel-rest-3scale-NUMBER_OF_DEPLOYMENT?tab=details.

  7. Switch to tab Logs and then see the log from Camel.

Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Configure Red Hat Container Registry authentication (if it is not configured). Follow documentation.

  4. Import base images in your newly created project (MY_PROJECT_NAME):

    $ oc import-image fuse-java-openshift:1.13 --from=registry.redhat.io/fuse7/fuse-java-openshift:1.13 --confirm
  5. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-rest-3scale) :

    or

    $ cd my_openshift/spring-boot-camel-rest-3scale
  6. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift  -Djkube.generator.fromMode=istag -Djkube.generator.from=MY_PROJECT_NAME/fuse-java-openshift:1.13
  7. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-rest-3scale has started up.

  8. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-rest-3scale application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/pods/spring-boot-camel-rest-3scale-NUMBER_OF_DEPLOYMENT?tab=details.

  9. Switch to tab Logs and then see the log from Camel.

Accessing the REST service

When the example is running, a REST service is available to list users that have called this service. The user information comes from 3scale extensions to autofill API keys.

  • "x-data-threescale-name": "app_ids" for the parameter that represents the application ID.

  • "x-data-threescale-name": "app_keys" or "x-data-threescale-name": "user_keys" for the parameter that represents the application or user key.

Notice: As it depends on your OpenShift setup, the hostname (route) might vary. Verify with oc get routes which hostname is valid for you.

The actual endpoint is using the context-path camel-rest-3scale/users and the REST service provides two services:

  • users/greet: to use 3scale API keys to add a user to this service’s list of calling users

  • users/list: to list all users that have called the service

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-3scale/api-doc. You can access the API documentation from your Web browser at http://spring-boot-camel-rest-3scale-MY_PROJECT_NAME.OPENSHIFT_IP_ADDR.nip.io/camel-rest-3scale/api-doc.

Running the quickstart standalone on your machine

To run this quickstart as a standalone project on your local machine:

  1. Download the project and extract the archive on your local filesystem.

  2. Build the project:

    $ cd PROJECT_DIR
    $ mvn clean package
  3. Run the service:

    $ 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-3scale-1.0-SNAPSHOT.jar
  4. You can then access the REST API directly from your Web browser, e.g.:

spring-boot-camel-rest-3scale's People

Contributors

grgrzybek avatar jiriondrusek avatar cunningt avatar rnetuka avatar ffang avatar oscerd avatar luigidemasi avatar valdar avatar dhirajsb avatar johnpoth avatar aldettinger avatar janstey avatar mmelko avatar

Stargazers

a. turan avatar Rakhmad Azhari avatar  avatar

Watchers

 avatar Tadayoshi Sato avatar  avatar Rakhmad Azhari avatar  avatar Claus Ibsen avatar  avatar James Cloos avatar FuseSource CI avatar Zheng Feng avatar Jonathan Christison avatar  avatar  avatar  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.