Object built-in object

ObjectHttpRepeater

HttpRepeater is an HTTP request forwarder that can forward HTTP requests to the specified backend server and obtain a response. It is often used in complex systems that need to interact with multiple servers on the front end, or for load balancing

Using HttpRepeater is very simple. You only need to provide the URL of the backend server or the load balancing URL array when creating the instance.

Here's an example using a single backend:

1 2 3 4 5 6
var http = require('http'); var serverUrl = 'http://localhost:' + actualPort + '/example' var repeater = new http.Repeater(serverUrl) var server = new http.Server(8081, repeater); server.start();

Here is an example of using an array of URLs for load balancing:

1 2 3 4 5 6 7 8 9
var serverURLs = [ 'http://server1.example.com', 'http://server2.example.com', 'http://server3.example.com' ] var repeater = new http.Repeater(serverURLs) var server = new http.Server(8081, repeater); server.start();

inheritance relationship

Constructor

HttpRepeater

HttpRepeater constructor, creates a new HttpRepeater object

1
new HttpRepeater(String url);

Call parameters:

  • url: String, specify a backend serverurl

HttpRepeater constructor, creates a new HttpRepeater object

1
new HttpRepeater(Array urls);

Call parameters:

  • urls: Array, specifies a set of backend serversurl

member properties

urls

NArray, query the current backend serverurllist

1
readonly NArray HttpRepeater.urls;

client

HttpClient, used internally by the request forwarding processorHttpClientobject

1
readonly HttpClient HttpRepeater.client;

member function

load

Load a new set of backendsurl

1
HttpRepeater.load(Array urls);

Call parameters:

  • urls: Array, specifies a set of backend serversurl

invoke

Process a message or object

1
Handler HttpRepeater.invoke(object v) async;

Call parameters:

  • v:object, specify the message or object to be processed

Return results:

  • Handler, return to the next processor

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String HttpRepeater.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value HttpRepeater.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable