Giter Club home page Giter Club logo

Comments (8)

tomas-fp avatar tomas-fp commented on July 22, 2024 1

The current, pretty simple, balancer implementation relies on object mutability. This is not good. In order to fix it from package consumer perspective, you can do:

proxy.all('/XYZ/api1/*') .balance(Array.from(serverList))
proxy.all('/XYZ/api2/*') .balance(Array.from(serverList))

from rocky.

tomas-fp avatar tomas-fp commented on July 22, 2024 1

Yes, you can change whatever you want via middleware. See:
https://github.com/h2non/rocky#request

from rocky.

MrSpark2591 avatar MrSpark2591 commented on July 22, 2024 1

woha , i am your fan now. Thank you so much 💃
implemented manual round robin on server array using middleware. 💯

from rocky.

tomas-fp avatar tomas-fp commented on July 22, 2024
  • You can't combine multiple routes with different behaviours at rocky API level (you can achieve that, however, writing your own middleware function).
  • You must declare the specific route first.
  • Then declare the generic one with the wildcard.

You code might look like:

proxy.get('/XYZ/api1/*') .balance(serverList).useForward(middleware)
// GET /XYZ/api1/* HTTP requests won't never reach the route below:
proxy.all('/XYZ/*') .balance(serverList)

from rocky.

MrSpark2591 avatar MrSpark2591 commented on July 22, 2024

but here if we define balance at individual API, Case will be:
take a scenario I have app. XYZ which has two API api1, api2.
whenever I receive request for any of these I have to load balance on application level not API level.
example: (suppose XYZ has two instances running xyz1 , xyz2)
in case of proxy.all('/XYZ/*') .balance(serverList)
request sequence:
api1 -> hits xyz1
api2 -> hits xyz2
api1 -> hits xyz1
api2 -> hits xyz2
in the case of individual load balance:
api1 -> hits xyz1
api2 -> hits xyz1
api1 -> hits xyz2
api2 -> hits xyz2

i want 1st case not second

from rocky.

tomas-fp avatar tomas-fp commented on July 22, 2024

The just register multiple routes that you want to balance independently:

proxy.all('/XYZ/api1/*') .balance(serverList)
proxy.all('/XYZ/api2/*') .balance(serverList2)

from rocky.

MrSpark2591 avatar MrSpark2591 commented on July 22, 2024

this is what i am doing right now which leads

//here server list is xyz1.com, xyz2.com
proxy.all('/XYZ/api1/*') .balance(serverList)
proxy.all('/XYZ/api2/*') .balance(serverList)

which leads :
api1 -> xyz1
api2 -> again xyz1 but i want it to go on xyz2 because it should load balace on application level
api1 -> xyz2 // even if this is 3rd hit to same application because of api level balancing it will go to xyz2
and so on.

from rocky.

MrSpark2591 avatar MrSpark2591 commented on July 22, 2024

thank you, I tried that but not working as well. can we change target URL in middleware ?

from rocky.

Related Issues (20)

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.