@azure/service-bus
Version:
Azure Service Bus SDK for JavaScript
845 lines • 92.4 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { Constants as AMQPConstants, parseConnectionString } from "@azure/core-amqp";
import { isTokenCredential, isNamedKeyCredential, } from "@azure/core-auth";
import { ServiceClient, } from "@azure/core-client";
import { bearerTokenAuthenticationPolicy, RestError, createPipelineFromOptions, createPipelineRequest, } from "@azure/core-rest-pipeline";
import { administrationLogger as logger } from "./log";
import { buildNamespace, NamespaceResourceSerializer, } from "./serializers/namespaceResourceSerializer";
import { buildQueue, buildQueueOptions, buildQueueRuntimeProperties, QueueResourceSerializer, } from "./serializers/queueResourceSerializer";
import { buildRule, isSqlRuleAction, RuleResourceSerializer, } from "./serializers/ruleResourceSerializer";
import { buildSubscription, buildSubscriptionOptions, buildSubscriptionRuntimeProperties, SubscriptionResourceSerializer, } from "./serializers/subscriptionResourceSerializer";
import { buildTopic, buildTopicOptions, buildTopicRuntimeProperties, TopicResourceSerializer, } from "./serializers/topicResourceSerializer";
import { executeAtomXmlOperation } from "./util/atomXmlHelper";
import * as Constants from "./util/constants";
import { parseURL } from "./util/parseUrl";
import { SasServiceClientCredentials } from "./util/sasServiceClientCredentials";
import { tracingClient } from "./diagnostics/tracing";
import { isDefined } from "@azure/core-util";
import { formatUserAgentPrefix, getHttpResponseOnly, isAbsoluteUrl, isJSONLikeObject, } from "./util/utils";
function signingPolicy(credentials) {
return {
name: "signingPolicy",
async sendRequest(request, next) {
const signed = await credentials.signRequest(request);
return next(signed);
},
};
}
/**
* All operations return promises that resolve to an object that has the relevant output.
* These objects also have a property called `_response` that you can use if you want to
* access the direct response from the service.
*/
export class ServiceBusAdministrationClient extends ServiceClient {
constructor(fullyQualifiedNamespaceOrConnectionString1, credentialOrOptions2,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options3) {
let options;
let fullyQualifiedNamespace;
let credentials;
let authPolicy;
if (isTokenCredential(credentialOrOptions2)) {
fullyQualifiedNamespace = fullyQualifiedNamespaceOrConnectionString1;
options = options3 || {};
credentials = credentialOrOptions2;
authPolicy = bearerTokenAuthenticationPolicy({
credential: credentials,
scopes: AMQPConstants.aadServiceBusScope,
});
}
else if (isNamedKeyCredential(credentialOrOptions2)) {
fullyQualifiedNamespace = fullyQualifiedNamespaceOrConnectionString1;
credentials = new SasServiceClientCredentials(credentialOrOptions2);
options = options3 || {};
authPolicy = signingPolicy(credentials);
}
else {
const connectionString = fullyQualifiedNamespaceOrConnectionString1;
options = credentialOrOptions2 || {};
const connectionStringObj = parseConnectionString(connectionString);
if (connectionStringObj.Endpoint === undefined) {
throw new Error("Missing Endpoint in connection string.");
}
try {
fullyQualifiedNamespace = connectionStringObj.Endpoint.match(".*://([^/]*)")[1];
}
catch (error) {
throw new Error("Endpoint in the connection string is not valid.");
}
credentials = new SasServiceClientCredentials({
key: connectionStringObj.SharedAccessKey,
name: connectionStringObj.SharedAccessKeyName,
});
authPolicy = signingPolicy(credentials);
}
const userAgentPrefix = formatUserAgentPrefix(options.userAgentOptions?.userAgentPrefix);
const serviceClientOptions = createPipelineFromOptions({
...options,
userAgentOptions: {
userAgentPrefix,
},
});
serviceClientOptions.addPolicy(authPolicy);
super({ pipeline: serviceClientOptions });
this.endpoint = fullyQualifiedNamespace;
this.endpointWithProtocol = fullyQualifiedNamespace.endsWith("/")
? "sb://" + fullyQualifiedNamespace
: "sb://" + fullyQualifiedNamespace + "/";
this.serviceVersion = options.serviceVersion ?? Constants.CURRENT_API_VERSION;
this.credentials = credentials;
this.namespaceResourceSerializer = new NamespaceResourceSerializer();
this.queueResourceSerializer = new QueueResourceSerializer();
this.topicResourceSerializer = new TopicResourceSerializer();
this.subscriptionResourceSerializer = new SubscriptionResourceSerializer();
this.ruleResourceSerializer = new RuleResourceSerializer();
}
/**
* Returns an object representing the metadata related to a service bus namespace.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
*/
async getNamespaceProperties(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
logger.verbose(`Performing management operation - getNamespaceProperties()`);
return tracingClient.withSpan("ServiceBusAdministrationClient.getNamespaceProperties", operationOptions, async (updatedOptions) => {
const response = await this.getResource("$namespaceinfo", this.namespaceResourceSerializer, updatedOptions);
return this.buildNamespacePropertiesResponse(response);
});
}
/**
* Creates a queue with given name, configured using the given options
* @param options - Options to configure the Queue being created(For example, you can configure a queue to support partitions or sessions)
* and the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async createQueue(queueName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.createQueue", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - createQueue() for "${queueName}" with options: %j`, options);
const response = await this.putResource(queueName, buildQueueOptions(options || {}), this.queueResourceSerializer, false, updatedOptions);
return this.buildQueueResponse(response);
});
}
/**
* Returns an object representing the Queue and its properties.
* If you want to get the Queue runtime info like message count details, use `getQueueRuntimeProperties` API.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getQueue(queueName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getQueue", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getQueue() for "${queueName}"`);
const response = await this.getResource(queueName, this.queueResourceSerializer, updatedOptions);
return this.buildQueueResponse(response);
});
}
/**
* Returns an object representing the Queue runtime info like message count details.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getQueueRuntimeProperties(queueName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getQueueRuntimeProperties", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getQueueRuntimeProperties() for "${queueName}"`);
const response = await this.getResource(queueName, this.queueResourceSerializer, updatedOptions);
return this.buildQueueRuntimePropertiesResponse(response);
});
}
/**
* Returns a list of objects, each representing a Queue along with its properties.
* If you want to get the runtime info of the queues like message count, use `getQueuesRuntimeProperties` API instead.
* @param options - The options include the maxCount and the count of entities to skip, the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getQueues(options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getQueues", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - getQueues() with options: %j`, options);
const response = await this.listResources("$Resources/Queues", updatedOptions, this.queueResourceSerializer);
return this.buildListQueuesResponse(response);
});
}
async *listQueuesPage(marker, options = {}) {
let listResponse;
do {
listResponse = await this.getQueues({
skip: Number(marker),
maxCount: options.maxPageSize,
...options,
});
marker = listResponse.continuationToken;
yield listResponse;
} while (marker);
}
async *listQueuesAll(options = {}) {
let marker;
for await (const segment of this.listQueuesPage(marker, options)) {
yield* segment;
}
}
/**
* Returns an async iterable iterator to list all the queues.
*
* .byPage() returns an async iterable iterator to list the queues in pages.
*
* @returns An asyncIterableIterator that supports paging.
*/
listQueues(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options) {
logger.verbose(`Performing management operation - listQueues() with options: %j`, options);
const iter = this.listQueuesAll(options);
return {
/**
*/
next() {
return iter.next();
},
/**
*/
[Symbol.asyncIterator]() {
return this;
},
/**
*/
byPage: (settings = {}) => {
this.throwIfInvalidContinuationToken(settings.continuationToken);
return this.listQueuesPage(settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...options,
});
},
};
}
/**
* Returns a list of objects, each representing a Queue's runtime info like message count details.
* @param options - The options include the maxCount and the count of entities to skip, the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getQueuesRuntimeProperties(options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getQueuesRuntimeProperties", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - getQueuesRuntimeProperties() with options: %j`, options);
const response = await this.listResources("$Resources/Queues", updatedOptions, this.queueResourceSerializer);
return this.buildListQueuesRuntimePropertiesResponse(response);
});
}
async *listQueuesRuntimePropertiesPage(marker, options = {}) {
let listResponse;
do {
listResponse = await this.getQueuesRuntimeProperties({
skip: Number(marker),
maxCount: options.maxPageSize,
...options,
});
marker = listResponse.continuationToken;
yield listResponse;
} while (marker);
}
async *listQueuesRuntimePropertiesAll(options = {}) {
let marker;
for await (const segment of this.listQueuesRuntimePropertiesPage(marker, options)) {
yield* segment;
}
}
/**
* Returns an async iterable iterator to list runtime info of the queues.
*
* .byPage() returns an async iterable iterator to list runtime info of the queues in pages.
*
*
* @returns An asyncIterableIterator that supports paging.
*/
listQueuesRuntimeProperties(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options) {
logger.verbose(`Performing management operation - listQueuesRuntimeProperties() with options: %j`, options);
const iter = this.listQueuesRuntimePropertiesAll(options);
return {
/**
*/
next() {
return iter.next();
},
/**
*/
[Symbol.asyncIterator]() {
return this;
},
/**
*/
byPage: (settings = {}) => {
this.throwIfInvalidContinuationToken(settings.continuationToken);
return this.listQueuesRuntimePropertiesPage(settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...options,
});
},
};
}
/**
* Updates the queue based on the queue properties provided.
* All queue properties must be set even though only a subset of them are actually updatable.
* Therefore, the suggested flow is to use the output from `getQueue()`, update the desired properties in it, and then pass the modified object to `updateQueue()`.
*
* The properties that cannot be updated are marked as readonly in the `QueueProperties` interface.
*
* @param queue - Object representing the properties of the queue and the raw response.
* `requiresSession`, `requiresDuplicateDetection`, `enablePartitioning`, and `name` can't be updated after creating the queue.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async updateQueue(queue,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.updateQueue", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - updateQueue() for "${queue.name}" with options: %j`, queue);
if (!isJSONLikeObject(queue) || queue == null) {
throw new TypeError(`Parameter "queue" must be an object of type "QueueDescription" and cannot be undefined or null.`);
}
if (!queue.name) {
throw new TypeError(`"name" attribute of the parameter "queue" cannot be undefined.`);
}
const response = await this.putResource(queue.name, buildQueueOptions(queue), this.queueResourceSerializer, true, updatedOptions);
return this.buildQueueResponse(response);
});
}
/**
* Deletes a queue.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async deleteQueue(queueName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.deleteQueue", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - deleteQueue() for "${queueName}"`);
const response = await this.deleteResource(queueName, this.queueResourceSerializer, updatedOptions);
return { _response: getHttpResponseOnly(response) };
});
}
/**
* Checks whether a given queue exists or not.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
async queueExists(queueName, operationOptions = {}) {
logger.verbose(`Performing management operation - queueExists() for "${queueName}"`);
const { span, updatedOptions } = tracingClient.startSpan("ServiceBusAdministrationClient.queueExists", operationOptions);
try {
await this.getQueue(queueName, updatedOptions);
span.setStatus({ status: "success" });
return true;
}
catch (e) {
span.setStatus({ status: "error", error: e });
return false;
}
finally {
span.end();
}
}
/**
* Creates a topic with given name, configured using the given options
* @param options - Options to configure the Topic being created(For example, you can configure a topic to support partitions)
* and the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async createTopic(topicName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.createTopic", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - createTopic() for "${topicName}" with options: %j`, options);
const response = await this.putResource(topicName, buildTopicOptions(options || {}), this.topicResourceSerializer, false, updatedOptions);
return this.buildTopicResponse(response);
});
}
/**
* Returns an object representing the Topic and its properties.
* If you want to get the Topic runtime info like subscription count details, use `getTopicRuntimeProperties` API.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getTopic(topicName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getTopic", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getTopic() for "${topicName}"`);
const response = await this.getResource(topicName, this.topicResourceSerializer, updatedOptions);
return this.buildTopicResponse(response);
});
}
/**
* Returns an object representing the Topic runtime info like subscription count.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getTopicRuntimeProperties(topicName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getTopicRuntimeProperties", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getTopicRuntimeProperties() for "${topicName}"`);
const response = await this.getResource(topicName, this.topicResourceSerializer, updatedOptions);
return this.buildTopicRuntimePropertiesResponse(response);
});
}
/**
* Returns a list of objects, each representing a Topic along with its properties.
* If you want to get the runtime info of the topics like subscription count, use `getTopicsRuntimeProperties` API instead.
* @param options - The options include the maxCount and the count of entities to skip, the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getTopics(options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getTopics", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - getTopics() with options: %j`, options);
const response = await this.listResources("$Resources/Topics", updatedOptions, this.topicResourceSerializer);
return this.buildListTopicsResponse(response);
});
}
async *listTopicsPage(marker, options = {}) {
let listResponse;
do {
listResponse = await this.getTopics({
skip: Number(marker),
maxCount: options.maxPageSize,
...options,
});
marker = listResponse.continuationToken;
yield listResponse;
} while (marker);
}
async *listTopicsAll(options = {}) {
let marker;
for await (const segment of this.listTopicsPage(marker, options)) {
yield* segment;
}
}
/**
* Returns an async iterable iterator to list all the topics.
*
* .byPage() returns an async iterable iterator to list the topics in pages.
*
*
* @returns An asyncIterableIterator that supports paging.
*/
listTopics(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options) {
logger.verbose(`Performing management operation - listTopics() with options: %j`, options);
const iter = this.listTopicsAll(options);
return {
/**
*/
next() {
return iter.next();
},
/**
*/
[Symbol.asyncIterator]() {
return this;
},
/**
*/
byPage: (settings = {}) => {
this.throwIfInvalidContinuationToken(settings.continuationToken);
return this.listTopicsPage(settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...options,
});
},
};
}
/**
* Returns a list of objects, each representing a Topic's runtime info like subscription count.
* @param options - The options include the maxCount and the count of entities to skip, the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getTopicsRuntimeProperties(options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getTopicsRuntimeProperties", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - getTopicsRuntimeProperties() with options: %j`, options);
const response = await this.listResources("$Resources/Topics", updatedOptions, this.topicResourceSerializer);
return this.buildListTopicsRuntimePropertiesResponse(response);
});
}
async *listTopicsRuntimePropertiesPage(marker, options = {}) {
let listResponse;
do {
listResponse = await this.getTopicsRuntimeProperties({
skip: Number(marker),
maxCount: options.maxPageSize,
...options,
});
marker = listResponse.continuationToken;
yield listResponse;
} while (marker);
}
async *listTopicsRuntimePropertiesAll(options = {}) {
let marker;
for await (const segment of this.listTopicsRuntimePropertiesPage(marker, options)) {
yield* segment;
}
}
/**
* Returns an async iterable iterator to list runtime info of the topics.
*
* .byPage() returns an async iterable iterator to list runtime info of the topics in pages.
*
*
* @returns An asyncIterableIterator that supports paging.
*/
listTopicsRuntimeProperties(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options) {
logger.verbose(`Performing management operation - listTopicsRuntimeProperties() with options: %j`, options);
const iter = this.listTopicsRuntimePropertiesAll(options);
return {
/**
* The next method, part of the iteration protocol
*/
next() {
return iter.next();
},
/**
* The connection to the async iterator, part of the iteration protocol
*/
[Symbol.asyncIterator]() {
return this;
},
/**
* Return an AsyncIterableIterator that works a page at a time
*/
byPage: (settings = {}) => {
this.throwIfInvalidContinuationToken(settings.continuationToken);
return this.listTopicsRuntimePropertiesPage(settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...options,
});
},
};
}
/**
* Updates the topic based on the topic properties provided.
* All topic properties must be set even though only a subset of them are actually updatable.
* Therefore, the suggested flow is to use the output from `getTopic()`, update the desired properties in it, and then pass the modified object to `updateTopic()`.
*
* The properties that cannot be updated are marked as readonly in the `TopicProperties` interface.
*
* @param topic - Object representing the properties of the topic and the raw response.
* `requiresDuplicateDetection`, `enablePartitioning`, and `name` can't be updated after creating the topic.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async updateTopic(topic,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.updateTopic", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - updateTopic() for "${topic.name}" with options: %j`, topic);
if (!isJSONLikeObject(topic) || topic == null) {
throw new TypeError(`Parameter "topic" must be an object of type "TopicDescription" and cannot be undefined or null.`);
}
if (!topic.name) {
throw new TypeError(`"name" attribute of the parameter "topic" cannot be undefined.`);
}
const response = await this.putResource(topic.name, buildTopicOptions(topic), this.topicResourceSerializer, true, updatedOptions);
return this.buildTopicResponse(response);
});
}
/**
* Deletes a topic.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async deleteTopic(topicName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.deleteTopic", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - deleteTopic() for "${topicName}"`);
const response = await this.deleteResource(topicName, this.topicResourceSerializer, updatedOptions);
return { _response: getHttpResponseOnly(response) };
});
}
/**
* Checks whether a given topic exists or not.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
async topicExists(topicName, operationOptions) {
logger.verbose(`Performing management operation - topicExists() for "${topicName}"`);
const { span, updatedOptions } = tracingClient.startSpan("ServiceBusAdministrationClient.topicExists", operationOptions);
try {
span.setStatus({ status: "success" });
await this.getTopic(topicName, updatedOptions);
return true;
}
catch (e) {
span.setStatus({ status: "error", error: e });
return false;
}
finally {
span.end();
}
}
/**
* Creates a subscription with given name, configured using the given options
* @param options - Options to configure the Subscription being created(For example, you can configure a Subscription to support partitions or sessions)
* and the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async createSubscription(topicName, subscriptionName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.createSubscription", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - createSubscription() for "${subscriptionName}" with options: %j`, options);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response = await this.putResource(fullPath, buildSubscriptionOptions(options || {}), this.subscriptionResourceSerializer, false, updatedOptions);
return this.buildSubscriptionResponse(response);
});
}
/**
* Returns an object representing the Subscription and its properties.
* If you want to get the Subscription runtime info like message count details, use `getSubscriptionRuntimeProperties` API.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getSubscription(topicName, subscriptionName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getSubscription", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getSubscription() for "${subscriptionName}"`);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response = await this.getResource(fullPath, this.subscriptionResourceSerializer, updatedOptions);
return this.buildSubscriptionResponse(response);
});
}
/**
* Returns an object representing the Subscription runtime info like message count details.
* @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getSubscriptionRuntimeProperties(topicName, subscriptionName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
operationOptions = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getSubscriptionRuntimeProperties", operationOptions, async (updatedOptions) => {
logger.verbose(`Performing management operation - getSubscriptionRuntimeProperties() for "${subscriptionName}"`);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response = await this.getResource(fullPath, this.subscriptionResourceSerializer, updatedOptions);
return this.buildSubscriptionRuntimePropertiesResponse(response);
});
}
/**
* Returns a list of objects, each representing a Subscription along with its properties.
* If you want to get the runtime info of the subscriptions like message count, use `getSubscriptionsRuntimeProperties` API instead.
* @param options - The options include the maxCount and the count of entities to skip, the operation options that can be used to abort, trace and control other configurations on the HTTP request.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code and statusCode representing the standard set of REST API errors.
*/
async getSubscriptions(topicName, options = {}) {
return tracingClient.withSpan("ServiceBusAdministrationClient.getSubscriptions", options, async (updatedOptions) => {
logger.verbose(`Performing management operation - getSubscriptions() with options: %j`, options);
const response = await this.listResources(topicName + "/Subscriptions/", updatedOptions, this.subscriptionResourceSerializer);
return this.buildListSubscriptionsResponse(response);
});
}
async *listSubscriptionsPage(topicName, marker, options = {}) {
let listResponse;
do {
listResponse = await this.getSubscriptions(topicName, {
skip: Number(marker),
maxCount: options.maxPageSize,
...options,
});
marker = listResponse.continuationToken;
yield listResponse;
} while (marker);
}
async *listSubscriptionsAll(topicName, options = {}) {
let marker;
for await (const segment of this.listSubscriptionsPage(topicName, marker, options)) {
yield* segment;
}
}
/**
*
* Returns an async iterable iterator to list all the subscriptions
* under the specified topic.
*
* .byPage() returns an async iterable iterator to list the subscriptions in pages.
*
* @returns An asyncIterableIterator that supports paging.
*/
listSubscriptions(topicName,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options) {
logger.verbose(`Performing management operation - listSubscriptions() with options: %j`, options);
const iter = this.listSubscriptionsAll(topicName, options);
return {
/**
*/
next() {
return iter.next();
},
/**
*/
[Symbol.asyncIterator]() {
return this;
},
/**
*/
byPage: (settings = {}) => {
this.throwIfInvalidContinuationToken(settings.continuationToken);
return this.listSubscriptionsPage(topicName, settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...options,
});
},
};
}
/**
* Returns a list of objects, each representing a Subscription's runtime info like message count details.
* @param options - The options include the maxCount and t