3

Based on the Netflix Hystrix circuit-breaker design pattern i was trying to do the following:

const circuitBreaker = require('opossum');
import * as request from 'request-promise';

const circuit = circuitBreaker(request.get);

circuit.fallback(() => Promise.resolve({result:[]}));

I have 3 node js services deployed . They use a circuit-breaker(opossum) to make REST Calls in between them. I have a fallback method which handles the scenario when a service goes down. I was wondering if something like request-caching can be used alongside the circuit breaker to return cached response whenever the fallback is invoked. If yes, how can i achieve this ?

P.S : request is my client to make REST calls

Jeson Dias
  • 883
  • 2
  • 11
  • 26

2 Answers2

1

As far I know opossum does not provide a out of the box solution for your problem. You have to implement some mechanism to cache the latest successful call. In my point of view probably the best way to do it, is having some distributed cache like Redis and cache the latest successful response but make sure to have a temporary entry in Redis you don't want to return old deprecated data.

Marco Talento
  • 2,335
  • 2
  • 19
  • 31
  • 1
    Actually, opossum has had caching since v0.6.0 https://github.com/nodeshift/opossum/releases/tag/v0.6.0 – lanceball Mar 14 '19 at 17:26
0

I'm not sure if this can help but you can try:

circuitBreaker(request.get, { cache: true });

You can see a bit more details on this test file

Helio Frota
  • 26
  • 1
  • 3
  • welcome! Please try to answer the questions thoroughly by quoting what your solution does, along with providing links to the relevant documentation. – Abhishek Menon Feb 13 '19 at 17:38