The Fabric8 project comes with an HTTP-Gateway to create a single entry point to all Micro Services hosted by a particular Fabric8 deployment, making it easier to route all service traffic through an external firewall. It also allows you do create URL mappings using a template. On top of the regular gateway features the Fabric8 HTTP-Gateway offers API Management features. This article is an introduction into how to use these. Both the HTTP-Gateway as well as the API Management capabilities are fully asynchronous.
It is assumed that you are already familiar with fabric8 version 2. If you are not please take a look at the fabric8 docs first.
API Management
The Fabric8 HTTP Gateway leverages the apiman.io project, which 'brings an open source development methodology to API Management, coupling a rich API design & configuration layer with a blazingly fast runtime'. A popular trend in enterprise software development these days is to design applications to be very decoupled and use API’s to connect them. This approach provides an excellent way to reuse functionality across various applications and business units. Another great benefit of API usage in enterprises is the ability to create those API’s using a variety of disparate technologies. However, this approach also introduces its own pitfalls and disadvantages. Some of those disadvantages include things like:- Difficulty discovering or sharing existing API’s
- Difficulty sharing common functionality across API implementations
- Tracking of API usage/consumption
- Centralized governance policy configuration
- Tracking of API’s and consumers of those API’s
- Easy sharing and discovery of API’s
- Leveraging common policy configuration across different API’s
Common Use Cases
Some common use cases most developers encounter are:
Throttling/Quotas - Limit the number of requests consumers of your APIs can make within a given time period (per service contract or per end-user).
Throttling/Quotas - Limit the number of requests consumers of your APIs can make within a given time period (per service contract or per end-user).
Centralized Security - Add authentication and IP filtering capabilities in
a central location, freeing your back-end services to focus on
functionality.
Billing and Metrics - Easily get metrics for all your APIs so you can see what's popular or charge your consumers for their usage.
The Fabric8 HTTP-Gateway contains this runtime 'embedded API manager engine'. As can be seen in Figure 1, the HTTP-Gateway opens a port at 9000 on xUbe. xUbe refers to either Kube (Kubernetes, OpenShift 3 and Docker) or Jube. By default the HTTP-Gateway has API Management turned on. This means that you will have to configure services in apiman and then 'Publish' them before they are live on the Gateway. When a service is published, an external request to this service on the gateway is routed through the apiman engine where policies are applied before the xUbe Service is called. An example of such a service is the CxfCdi Quickstart example which runs as Java Main processes. xUbe relays the request to one or more pods. When running Kube, the pod will typically open the same port number on the container as the service is running under. For Jube everything runs on the same machine so this would result in a port conflict and in this case an open port is chosen by Jube. In Figure 1, the port number is marked as 'xxxxx' as this port is not predetermined in this case. APIMan in Fabric8
Figure 1. Fabric8 API Management |
APIMan Console
The apiman console is shipped with fabric8 as a default application that can be run. The apiman application is deployed onto a wildly-8.1 container. From the console a service can be published to the Fabric8 HTTP-Gateway using REST management that run on port 8999 on the gateway. The console itself runs on http://Setup a rate limiting policy on the CxfCdi service in 5 minutes
From the Hawtio console (Kube: http://localhost:8484, Jube: http://localhost:8585) and under "Runtime > Apps" click on the green "Run..." button. Note that in this example I am using Jube, which means that myFigure 2. Hawtio Console, with running Gateway. |
Now open the apiman console by navigating to: http://127.0.0.1:9092/apiman-manager/, and you can login using admin/admin123! You should change the password in the keycloak console at http://127.0.0.1:9092/auth/.
Figure 3. Login into the apiman console. |
Figure 4. The apiman console home screen. |
Figure 5. Create a new Fabric8Gateway. |
Figure 6. Service Implementation. |
Figure 7. Add Rate Limiting Policy. |
Figure 8. Publish Service to the Fabric8Gateway. |
{"/quickstart-java-cxf-cdi":["http://localhost:9002/quickstart-java-cxf-cdi"]}
Figure 9. Rate policy triggered. |
Cheers!
--Kurt