flesh out implementation of client#close
This commit is contained in:
Родитель
4058e4d766
Коммит
1e1ec44560
|
@ -20,7 +20,11 @@ function EventHubClient(config) {
|
|||
if (!config[prop]) throw makeError(prop);
|
||||
});
|
||||
|
||||
this._config = config;
|
||||
this._uri = 'amqps://' +
|
||||
encodeURIComponent(config.keyName) + ':' +
|
||||
encodeURIComponent(config.key) + '@' +
|
||||
config.host;
|
||||
this._eventHubPath = config.path;
|
||||
this._amqp = new amqp10.Client(amqp10.Policy.EventHub);
|
||||
this._connectPromise = null;
|
||||
}
|
||||
|
@ -39,20 +43,16 @@ EventHubClient.fromConnectionString = function (connectionString, path) {
|
|||
};
|
||||
|
||||
EventHubClient.prototype.open = function () {
|
||||
var uri = 'amqps://' +
|
||||
encodeURIComponent(this._config.keyName) + ':' +
|
||||
encodeURIComponent(this._config.key) + '@' +
|
||||
this._config.host;
|
||||
|
||||
if (!this._connectPromise) {
|
||||
this._connectPromise = this._amqp.connect(uri);
|
||||
this._connectPromise = this._amqp.connect(this._uri);
|
||||
}
|
||||
|
||||
return this._connectPromise;
|
||||
};
|
||||
|
||||
EventHubClient.prototype.close = function () {
|
||||
return Promise.resolve();
|
||||
this._connectPromise = null;
|
||||
return this._amqp.disconnect();
|
||||
};
|
||||
|
||||
EventHubClient.prototype.getPartitionIds = function () {
|
||||
|
@ -68,7 +68,7 @@ EventHubClient.prototype.getPartitionIds = function () {
|
|||
},
|
||||
applicationProperties: {
|
||||
operation: "READ",
|
||||
name: this._config.path,
|
||||
name: this._eventHubPath,
|
||||
type: "com.microsoft:eventhub"
|
||||
}
|
||||
};
|
||||
|
@ -105,7 +105,7 @@ EventHubClient.prototype.getPartitionIds = function () {
|
|||
EventHubClient.prototype.createReceiver = function createReceiver(consumerGroup, partitionId) {
|
||||
return this.open()
|
||||
.then(function () {
|
||||
var endpoint = '/' + this._config.path +
|
||||
var endpoint = '/' + this._eventHubPath +
|
||||
'/ConsumerGroups/' + consumerGroup +
|
||||
'/Partitions/' + partitionId;
|
||||
return this._amqp.createReceiver(endpoint);
|
||||
|
|
3
tasks
3
tasks
|
@ -16,4 +16,5 @@ azure-eventhubs
|
|||
* implement/test close (amqp disconnect on close--change .once() to .on() in "receiving events" tests, make sure done() not called twice for any test)
|
||||
* grouping tests (and naming files) by scenario, doesn't help if tests themselves are still organized by class and method. Evaluate whether I should rename tests/suites, or rename files.
|
||||
* in tests, should it be describe('.method', ...) instead of '#method' for static methods of a class? If so, be consistent...
|
||||
* file an issue in amqp10: AMQPError (and AMQPSymbol) should be promoted to the public interface since they are returned from public functions (like the 'errorReceived' event)
|
||||
* file an issue in amqp10: AMQPError (and AMQPSymbol) should be promoted to the public interface since they are returned from public functions (like the 'errorReceived' event)
|
||||
* client#open/close tests don't really confirm that the connection is opened or closed...
|
|
@ -26,5 +26,13 @@ describe('EventHubClient', function () {
|
|||
var client = EventHubClient.fromConnectionString(process.env.EVENT_HUB_CONNECTION_STRING, process.env.EVENT_HUB_PATH);
|
||||
return client.close().should.be.fulfilled;
|
||||
});
|
||||
|
||||
it('closes an open connection', function () {
|
||||
var client = EventHubClient.fromConnectionString(process.env.EVENT_HUB_CONNECTION_STRING, process.env.EVENT_HUB_PATH);
|
||||
return client.open()
|
||||
.then(function () {
|
||||
return client.close().should.be.fulfilled;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче