api

command
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Gateway with a circuit breaker

This recipe is a gateway with a service protected by a circuit breaker.

Installation

  • Install Go

Setup

git clone https://github.com/project-flogo/microgateway
cd microgateway/activity/circuitbreaker/examples/api

Testing

Start the gateway:

go run main.go

and test below scenario.

Circuit breaker gets tripped

Start the gateway target service in a new terminal:

go run server/main.go -server

Now run the following in a new terminal:

curl http://localhost:9096/pets/1

You should see the following response:

{
 "pet": {
  "category": {
   "id": 0,
   "name": "string"
  },
  "id": 1,
  "name": "sally",
  "photoUrls": [
   "string"
  ],
  "status": "available",
  "tags": [
   {
    "id": 0,
    "name": "string"
   }
  ]
 },
 "status": "available"
}

The target service is in a working state.

Now simulate a service failure by stopping the target service, and then run the following command 3 times:

curl http://localhost:9096/pets/1

You should see the below response 2 times:

{
 "error": "connection failure"
}

Followed by:

{
 "error": "circuit breaker tripped"
}

The circuit breaker is now in the tripped state.

Start the gateway target service back up and wait at least one minute. After waiting at least one minute run the following command:

curl http://localhost:9096/pets/1

You should see the following response:

{
 "pet": {
  "category": {
   "id": 0,
   "name": "string"
  },
  "id": 1,
  "name": "sally",
  "photoUrls": [
   "string"
  ],
  "status": "available",
  "tags": [
   {
    "id": 0,
    "name": "string"
   }
  ]
 },
 "status": "available"
}

The circuit breaker is no longer in the tripped state, and the target service is working.

Documentation

The Go Gopher

There is no documentation for this package.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL