Merge pull request #329 from spalger/implement/createNodeAgent
Implement createNodeAgent config
This commit is contained in:
@ -242,6 +242,27 @@ see https://github.com/elasticsearch/elasticsearch-js/blob/master/src/lib/nodes_
|
||||
|
||||
|
||||
|
||||
|
||||
`createNodeAgent`[[config-create-node-agent]]:: `Function` -- Override the way that the client creates node.js `Agent`[https://nodejs.org/api/http.html#http_class_http_agent] objects. The value of this property will be executed every time a new Node is added to the client (either from the initial seed or from sniffing) and can return any value that node's http(s) module accepts as `agent:` configuration.
|
||||
+
|
||||
The function is called with two arguments, first an `HttpConnector`[http://github.com/spalger/elasticsearch-js/blob/master/src/lib/connectors/http.js] object and the second the config object initially passed when creating the client.
|
||||
|
||||
Default::: `HttpConnector#createAgent()`
|
||||
|
||||
Disable Agent creation:::
|
||||
+
|
||||
[source,js]
|
||||
-----
|
||||
var client = new elasticsearch.Client({
|
||||
createNodeAgent: function () {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
-----
|
||||
|
||||
|
||||
|
||||
|
||||
=== Examples
|
||||
|
||||
Connect to just a single seed node, and use sniffing to find the rest of the cluster.
|
||||
|
||||
@ -233,6 +233,27 @@ see https://github.com/elasticsearch/elasticsearch-js/blob/master/src/lib/nodes_
|
||||
|
||||
|
||||
|
||||
|
||||
`createNodeAgent`[[config-create-node-agent]]:: `Function` -- Override the way that the client creates node.js `Agent`[https://nodejs.org/api/http.html#http_class_http_agent] objects. The value of this property will be executed every time a new Node is added to the client (either from the initial seed or from sniffing) and can return any value that node's http(s) module accepts as `agent:` configuration.
|
||||
+
|
||||
The function is called with two arguments, first an `HttpConnector`[http://github.com/spalger/elasticsearch-js/blob/master/src/lib/connectors/http.js] object and the second the config object initially passed when creating the client.
|
||||
|
||||
Default::: `HttpConnector#createAgent()`
|
||||
|
||||
Disable Agent creation:::
|
||||
+
|
||||
[source,js]
|
||||
-----
|
||||
var client = new elasticsearch.Client({
|
||||
createNodeAgent: function () {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
-----
|
||||
|
||||
|
||||
|
||||
|
||||
=== Examples
|
||||
|
||||
Connect to just a single seed node, and use sniffing to find the rest of the cluster.
|
||||
|
||||
@ -44,7 +44,7 @@ function HttpConnector(host, config) {
|
||||
maxSockets: 11
|
||||
});
|
||||
|
||||
this.agent = this.createAgent(config);
|
||||
this.agent = config.createNodeAgent ? config.createNodeAgent(this, config) : this.createAgent(config);
|
||||
}
|
||||
_.inherits(HttpConnector, ConnectionAbstract);
|
||||
|
||||
|
||||
@ -64,6 +64,17 @@ describe('Http Connector', function () {
|
||||
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
|
||||
}).to.throwError(/invalid protocol/i);
|
||||
});
|
||||
|
||||
it('allows defining a custom agent', function () {
|
||||
var football = {};
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(football) });
|
||||
expect(con.agent).to.be(football);
|
||||
});
|
||||
|
||||
it('allows setting agent to false', function () {
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(false) });
|
||||
expect(con.agent).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#makeReqParams', function () {
|
||||
|
||||
Reference in New Issue
Block a user