DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Deploying a Scala API on OpenShift With OpenShift Pipelines
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Unlock AI Power: Generate JSON With GPT-4 and Node.js for Ultimate App Integration
  • Instant App Backends With API and Logic Automation

Trending

  • Monitoring Spring Boot Applications with Prometheus and Grafana
  • Implementing Observability in Distributed Systems Using OpenTelemetry
  • Document Generation API: How to Automate Personalized Document Creation at Scale
  • 5 Common Security Pitfalls in Serverless Architectures
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Implement a Circuit Breaker for an Unavailable API Service Running in App Connect on CP4I Using Red Hat Service Mesh

Implement a Circuit Breaker for an Unavailable API Service Running in App Connect on CP4I Using Red Hat Service Mesh

Learn how to implement the Circuit Breaker pattern using Red Hat OpenShift Service Mesh and IBM App Connect to prevent app outages.

By 
Abhinav Priyadarshi user avatar
Abhinav Priyadarshi
·
Oct. 02, 25 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
2.4K Views

Join the DZone community and get the full member experience.

Join For Free

Some applications may not respond during heavy load. These outages are due to out of memory and high CPU utilization when many requests are piled up at the application entry point since the back end is not available. In this article, we will solve this problem using Red Hat OpenShift Service Mesh, which provides a way to stop sending requests to the application or API if it is unhealthy.

This article shows how to implement the Circuit Breaker pattern when an application is not responding using Red Hat OpenShift Service Mesh and IBM Cloud Pak for integration — the App Connect API service.

Red Hat OpenShift Service Mesh Operator

Red Hat OpenShift Service Mesh, based on the open-source Istio project, adds a transparent layer on existing distributed applications without requiring any changes to the service code. You add Red Hat OpenShift Service Mesh support to services by deploying a special sidecar proxy throughout your environment that intercepts all network communication between microservices. You configure and manage the service mesh using the control plane features.

Red Hat OpenShift Service Mesh provides an easy way to create a network of deployed services that provide discovery, load balancing, service-to-service authentication, failure recovery, metrics, and monitoring. A service mesh also provides more complex operational functionality, including A/B testing, canary releases, rate limiting, access control, and end-to-end authentication.

Kiali Operator

Kiali works with OpenShift Service Mesh to visualize the service mesh topology and to provide visibility into features like circuit breakers, request rates, and more. It offers insights about the mesh components at different levels, from abstract applications to services and workloads.

Circuit Breaker Pattern

A circuit breaker is implemented using the following architecture. The Red Hat service mesh allows you to create an isolated network of microservices. The traffic to these microservices can be controlled, monitored, load balanced, rate-limited, and secured using the configuration applied in the service mesh.

Implementing the Circuit Breaker Pattern

Follow the steps below to implement a circuit breaker using the OpenShift Service Mesh and IBM App Connect service.

Step 1: Log in to the OpenShift console > go to OperatorHub and install Red Hat OpenShift Service Mesh Operator and Kiali Operator in the istio-system namespace. Optionally, install the OpenShift ElasticSearch Operator to monitor the network utilization.

Install Red Hat OpenShift Service Mesh Operator

Install Kiali Operator


Step 2: In the istio-system project, go to Operators > click Installed Operators in the left sidebar > select Red Hat OpenShift Service Mesh:

Select Red Hat OpenShift Service Mesh


Step 3: Go to the Istio Service Mesh Control Plane tab > click the Create ServiceMeshControlPlane button:

Click Create ServiceMeshControlPlane


The control plane basic service will be created:

Control plane basic service will be created


Step 4: Create a service member roll file, service-member-roll.yaml, using the below code:

YAML
 
apiVersion: maistra.io/v1
kind: ServiceMeshMemberRoll
metadata:
  finalizers:
    - maistra.io/istio-operator
  generation: 12
  name: default
  namespace: istio-system
spec:
  members:
    - service-mesh-demo


Then, run:

Shell
 
$oc apply -f service-member-roll.yaml


Step 5: Select Kiali Operator from the Installed Operators page > go to the Kiali tab > click the Create Kiali button:

Click Create Kiali


Step 6: Go to the OpenShift Service Mesh Console tab > click on OSSMConsoles:

Click on OSSMConsoles


Step 7: Develop a sample message flow to send an HTTP request to a back-end URL using the IBM App Connect Toolkit:

Send an HTTP request to a back-end URL


Step 8: Develop an app with a back-end flow:

Develop an app with a back-end flow


Step 9: Create the BAR file, backend.bar, of the back-end flow separately:

Create the BAR file


Step 10: Log in to the Cloud Pak for Integration App Connect Dashboard and deploy the backend.bar file to the new integration server, backendservice.

Step 11: In the left sidebar, go to Networking > Services and get the internal container IP of the backend-is service, which is 172.30.76.254, port 7800:

Get the internal container IP of the backend-is service


Step 12: Update the message httpinputflow of the test_circuitbreaker app with the back-end endpoint (IP: 172.30.76.254, port 7800).

Update the message httpinputflow of the test_circuitbreaker app


Step 13: Create the BAR file of the httpInputFlow message flow app with the name test_circuitbreaker.bar.

Create the BAR file of the httpInputFlow message flow app


Step 14: Log in to the Cloud Pak for Integration App Connect Dashboard and deploy the BAR file test_circuitbreaker.bar to the new integration server httpservice.

Deploy the BAR file test_circuitbreaker.bar to the new integration server httpservice


Toggle on Advanced settings:

Toggle on Advanced settings


Under the License tab on the left, add Advanced Annotations > apply custom annotations to the deployment > use sidecar.istio.io/inject for the Name field and set the Value to true:

Set the Value to true


Then, click the Create button.

Now, let us configure the Gateway, VirtualServer, DestinationRule, and sidecar proxy in the existing microservice.

Step 15: From the admin console, get the oc login console token by clicking on Copy login command:

Get the oc login console token


Step 16: Create project service-mesh:

Shell
 
$ oc project service-mesh


Then, create the Gateway.yaml file:

YAML
 
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: service-mesh-gateway
  namespace: service-mesh-demo
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"


Now, run:

Shell
 
$ oc apply -f Gateway.yaml


Step 17: Create the virtualservice.yaml file using the following content to create a wrapper virtual service to route your request to the microservice. Here, httpservice-is is the container name of the microservice, and 7800 is the HTTP server port listening for the App Connect service:

YAML
 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtual-service-httpservice
  namespace: service-mesh-demo
spec:
  hosts:
  - "*"
  gateways:
  - service-mesh-gateway
  http:
  - match:
    - uri:
        exact: /input
    route:
    - destination:
        host: httpservice-is
        port:
          number: 7800


Step 18: Create a DestinationRule service named destination-rule.yaml. Here, we are rejecting the request after three retries using the parameter consecutive5xxErrors: 3.

YAML
 
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpservice
  namespace: service-mesh-demo
spec:
  host: httpservice-is
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        httpMaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutive5xxErrors: 3
      interval: 5s
      baseEjectionTime: 3m
      maxEjectionPercent: 100


The sidecar is injected into the httpservice integration server pod while deploying the BAR file. If you have already deployed the BAR file, you can edit the integration server and add the Advanced: Annotations — apply custom annotations to the deployment:

  • Name: sidecar.istio.io/inject
  • Value: true

We are ready to test the flow.

Step 19: From the OpenShift console, select the istio-system project, then go to Networking > Routes and get the gateway route location of the istio-ingressgateway route. Here, it is http://istio-ingressgateway-istio-system.apps.s-ocp.cp.fyre.ibm.com:

Get the gateway route location of the istio-ingressgateway route


Step 20: Test the httpinputflow service using any HTTP client application by sending a request to http://istio-ingressgateway-istio-system.apps.s-ocp.cp.fyre.ibm.com.

Test the httpinputflow service using any HTTP client app


You will get a successful response:

A successful response!


Now, let's edit the back-end service to be unavailable.

Step 21: Click the options for backend-is > select Edit Service:

Select Edit Service


Then, change the back-end service internal port to 7801:

Change the back-end service internal port to 7801


Click the Save button. The back-end service is now running on port 7801.

Step 22: Now, test the HTTP client again. 

You will get a socket operation timeout because the back-end port 7800 is not listening:

You will get a socket operation timeout


Remember in the destination-rule.yaml file for httpservice-is, we set consecutive5xxErrors: 3. This parameter allows three retries to httpservice-is, after which the circuit breaker is enforced, the request will not hit the httpservice-is service, and it gives the output, "no healthy upstream."

"No healthy upstream"


Conclusion

This article showed how to implement a circuit breaker using Red Hat OpenShift Service Mesh for an App Connect service. The same steps can be used for any other pod service that is hosting an HTTP service on a URL. There are many other use cases for service meshes, which include load balancing, content-based routing, routing services to different versions of API endpoints, rate limiting the API request, controlling the API request, etc. The high-level steps will remain the same for all these use cases, only the destination-rule.yaml will change based on each use case.

Reference: "A practical example of the Istio service mesh and IBM App Connect Enterprise in IBM Cloud Pak for Integration"

API OpenShift app Circuit Breaker Pattern

Opinions expressed by DZone contributors are their own.

Related

  • Deploying a Scala API on OpenShift With OpenShift Pipelines
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Unlock AI Power: Generate JSON With GPT-4 and Node.js for Ultimate App Integration
  • Instant App Backends With API and Logic Automation

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook