Skip to content

Commit

Permalink
[Service Bus] ATOM API - Make service version configurable (#18254)
Browse files Browse the repository at this point in the history
* ServiceBusAtomAPIVersion

* older API Version is broken

* tests

* rename

* changelog

* getRandomServiceVersion

* remove .only

* address Jeremy's feedback

* serviceVersion comments

* docs

* test with both the api versions

* Donot expose ServiceBusAtomAPIVersion

* test

* doc update
  • Loading branch information
HarshaNalluru authored Oct 22, 2021
1 parent 88791cd commit 4cc59c0
Show file tree
Hide file tree
Showing 8 changed files with 2,614 additions and 2,534 deletions.
4 changes: 4 additions & 0 deletions sdk/servicebus/service-bus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Features Added

- Allowing the service API version to be configurable when using `ServiceBusAdministrationClient` as part of the constructor client options.
Supported versions being "2021-05" and "2017-04".
[#18254](https://github.com/Azure/azure-sdk-for-js/pull/18254)

### Breaking Changes

### Bugs Fixed
Expand Down
13 changes: 9 additions & 4 deletions sdk/servicebus/service-bus/review/service-bus.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export interface QueueProperties {
forwardTo?: string;
lockDuration: string;
maxDeliveryCount: number;
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;
maxSizeInMegabytes: number;
readonly name: string;
readonly requiresDuplicateDetection: boolean;
Expand Down Expand Up @@ -243,8 +243,8 @@ export interface RuleProperties {

// @public
export class ServiceBusAdministrationClient extends ServiceClient {
constructor(connectionString: string, options?: PipelineOptions);
constructor(fullyQualifiedNamespace: string, credential: TokenCredential | NamedKeyCredential, options?: PipelineOptions);
constructor(connectionString: string, options?: ServiceBusAdministrationClientOptions);
constructor(fullyQualifiedNamespace: string, credential: TokenCredential | NamedKeyCredential, options?: ServiceBusAdministrationClientOptions);
createQueue(queueName: string, options?: CreateQueueOptions): Promise<WithResponse<QueueProperties>>;
createRule(topicName: string, subscriptionName: string, ruleName: string, ruleFilter: SqlRuleFilter | CorrelationRuleFilter, operationOptions?: OperationOptions): Promise<WithResponse<RuleProperties>>;
createRule(topicName: string, subscriptionName: string, ruleName: string, ruleFilter: SqlRuleFilter | CorrelationRuleFilter, ruleAction: SqlRuleAction, operationOptions?: OperationOptions): Promise<WithResponse<RuleProperties>>;
Expand Down Expand Up @@ -279,6 +279,11 @@ export class ServiceBusAdministrationClient extends ServiceClient {
updateTopic(topic: WithResponse<TopicProperties>, operationOptions?: OperationOptions): Promise<WithResponse<TopicProperties>>;
}

// @public
export interface ServiceBusAdministrationClientOptions extends PipelineOptions {
serviceVersion?: "2021-05" | "2017-04";
}

// @public
export class ServiceBusClient {
constructor(connectionString: string, options?: ServiceBusClientOptions);
Expand Down Expand Up @@ -554,7 +559,7 @@ export interface TopicProperties {
enableBatchedOperations: boolean;
readonly enableExpress: boolean;
readonly enablePartitioning: boolean;
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;
maxSizeInMegabytes: number;
readonly name: string;
readonly requiresDuplicateDetection: boolean;
Expand Down
3 changes: 2 additions & 1 deletion sdk/servicebus/service-bus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export {
export {
EntitiesResponse,
ServiceBusAdministrationClient,
WithResponse
WithResponse,
ServiceBusAdministrationClientOptions
} from "./serviceBusAtomManagementClient";
export { ServiceBusClient } from "./serviceBusClient";
export { isServiceBusError, ServiceBusError, ServiceBusErrorCode } from "./serviceBusError";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ export function buildQueue(rawQueue: Record<string, any>): QueueProperties {

availabilityStatus: rawQueue[Constants.ENTITY_AVAILABILITY_STATUS],

maxMessageSizeInKilobytes: getInteger(
rawQueue[Constants.MAX_MESSAGE_SIZE_IN_KILOBYTES],
"maxMessageSizeInKilobytes"
maxMessageSizeInKilobytes: getIntegerOrUndefined(
rawQueue[Constants.MAX_MESSAGE_SIZE_IN_KILOBYTES]
)
};
}
Expand Down Expand Up @@ -314,8 +313,10 @@ export interface QueueProperties {

/**
* The maximum message size in kilobytes for messages sent to this queue.
*
* Not applicable if service version "2017-04" is chosen when creating the `ServiceBusAdministrationClient`.
*/
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;

/**
* If enabled, the topic will detect duplicate messages within the time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ export function buildTopic(rawTopic: Record<string, any>): TopicProperties {

availabilityStatus: rawTopic[Constants.ENTITY_AVAILABILITY_STATUS],

maxMessageSizeInKilobytes: getInteger(
rawTopic[Constants.MAX_MESSAGE_SIZE_IN_KILOBYTES],
"maxMessageSizeInKilobytes"
maxMessageSizeInKilobytes: getIntegerOrUndefined(
rawTopic[Constants.MAX_MESSAGE_SIZE_IN_KILOBYTES]
)
};
}
Expand Down Expand Up @@ -258,8 +257,10 @@ export interface TopicProperties {

/**
* The maximum message size in kilobytes for messages sent to this queue/topic.
*
* Not applicable if service version "2017-04" is chosen when creating the `ServiceBusAdministrationClient`.
*/
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;

/**
* If enabled, the topic will detect duplicate messages within the time span
Expand Down
35 changes: 28 additions & 7 deletions sdk/servicebus/service-bus/src/serviceBusAtomManagementClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ import {
formatUserAgentPrefix,
getHttpResponseOnly,
isAbsoluteUrl,
isJSONLikeObject
isJSONLikeObject,
ServiceBusAtomAPIVersion
} from "./util/utils";
import { SpanStatusCode } from "@azure/core-tracing";

Expand Down Expand Up @@ -110,6 +111,20 @@ export type WithResponse<T extends object> = T & {
_response: HttpResponse;
};

/**
* Represents the client options of the `ServiceBusAdministrationClient`.
*/
export interface ServiceBusAdministrationClientOptions extends PipelineOptions {
/**
* Service version of the ATOM API.
*
* Currently supported = "2021-05" | "2017-04"
*
* Defaults to "2021-05".
*/
serviceVersion?: "2021-05" | "2017-04";
}

/**
* Represents the result of list operation on entities which also contains the `continuationToken` to start iterating over from.
*/
Expand All @@ -132,6 +147,8 @@ export class ServiceBusAdministrationClient extends ServiceClient {
*/
private endpointWithProtocol: string;

private serviceVersion: ServiceBusAtomAPIVersion;

/**
* Singleton instances of serializers used across the various operations.
*/
Expand All @@ -152,7 +169,7 @@ export class ServiceBusAdministrationClient extends ServiceClient {
* @param options - PipelineOptions
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
constructor(connectionString: string, options?: PipelineOptions);
constructor(connectionString: string, options?: ServiceBusAdministrationClientOptions);
/**
*
* @param fullyQualifiedNamespace - The fully qualified namespace of your Service Bus instance which is
Expand All @@ -170,15 +187,18 @@ export class ServiceBusAdministrationClient extends ServiceClient {
fullyQualifiedNamespace: string,
credential: TokenCredential | NamedKeyCredential,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options?: PipelineOptions
options?: ServiceBusAdministrationClientOptions
);
constructor(
fullyQualifiedNamespaceOrConnectionString1: string,
credentialOrOptions2?: TokenCredential | NamedKeyCredential | PipelineOptions,
credentialOrOptions2?:
| TokenCredential
| NamedKeyCredential
| ServiceBusAdministrationClientOptions,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options3?: PipelineOptions
options3?: ServiceBusAdministrationClientOptions
) {
let options: PipelineOptions;
let options: ServiceBusAdministrationClientOptions;
let fullyQualifiedNamespace: string;
let credentials: SasServiceClientCredentials | TokenCredential;
let authPolicy: RequestPolicyFactory;
Expand Down Expand Up @@ -226,6 +246,7 @@ export class ServiceBusAdministrationClient extends ServiceClient {
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();
Expand Down Expand Up @@ -2343,7 +2364,7 @@ export class ServiceBusAdministrationClient extends ServiceClient {
const baseUri = `https://${this.endpoint}/${path}`;

const requestUrl: URLBuilder = URLBuilder.parse(baseUri);
requestUrl.setQueryParameter(Constants.API_VERSION_QUERY_KEY, Constants.CURRENT_API_VERSION);
requestUrl.setQueryParameter(Constants.API_VERSION_QUERY_KEY, this.serviceVersion);

if (queryParams) {
for (const key of Object.keys(queryParams)) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/servicebus/service-bus/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,9 @@ export const getHttpResponseOnly = ({
status,
headers
});

/**
* @internal
* Type with the service versions for the ATOM API.
*/
export type ServiceBusAtomAPIVersion = "2021-05" | "2017-04";
Loading

0 comments on commit 4cc59c0

Please sign in to comment.