Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] ATOM API - Make service version configurable #18254

Merged
merged 14 commits into from
Oct 22, 2021
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
16 changes: 12 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,14 @@ export class ServiceBusAdministrationClient extends ServiceClient {
updateTopic(topic: WithResponse<TopicProperties>, operationOptions?: OperationOptions): Promise<WithResponse<TopicProperties>>;
}

// @public
export interface ServiceBusAdministrationClientOptions extends PipelineOptions {
serviceVersion?: ServiceBusAtomAPIVersion;
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
}

// @public
export type ServiceBusAtomAPIVersion = "2021-05" | "2017-04";

// @public
export class ServiceBusClient {
constructor(connectionString: string, options?: ServiceBusClientOptions);
Expand Down Expand Up @@ -554,7 +562,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
4 changes: 3 additions & 1 deletion sdk/servicebus/service-bus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export {
export {
EntitiesResponse,
ServiceBusAdministrationClient,
WithResponse
WithResponse,
ServiceBusAdministrationClientOptions
} from "./serviceBusAtomManagementClient";
export { ServiceBusAtomAPIVersion } from "./util/utils";
export { ServiceBusClient } from "./serviceBusClient";
export { isServiceBusError, ServiceBusError, ServiceBusErrorCode } from "./serviceBusError";
export {
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.
*
* "2021-05" API version(set by default) populates this value, whereas "2017-04" doesn't.
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
*/
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;
ramya-rao-a marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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.
*
* "2021-05" API version(set by default) populates this value, whereas "2017-04" doesn't.
*/
maxMessageSizeInKilobytes: number;
maxMessageSizeInKilobytes?: number;

/**
* If enabled, the topic will detect duplicate messages within the time span
Expand Down
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?: ServiceBusAtomAPIVersion;
}

/**
* 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
5 changes: 5 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,8 @@ export const getHttpResponseOnly = ({
status,
headers
});

/**
* Type with the service versions for the ATOM API.
*/
export type ServiceBusAtomAPIVersion = "2021-05" | "2017-04";
18 changes: 12 additions & 6 deletions sdk/servicebus/service-bus/test/public/atomManagement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { recreateQueue, recreateSubscription, recreateTopic } from "./utils/mana
import { EntityNames, TestClientType } from "./utils/testUtils";
import { TestConstants } from "./fakeTestSecrets";
import { AzureNamedKeyCredential } from "@azure/core-auth";
import { createServiceBusClientForTests, ServiceBusClientForTests } from "./utils/testutils2";
import {
createServiceBusClientForTests,
getRandomServiceVersion,
ServiceBusClientForTests
} from "./utils/testutils2";

chai.use(chaiAsPromised);
chai.use(chaiExclude);
Expand All @@ -31,10 +35,6 @@ dotenv.config();

const env = getEnvVars();

const serviceBusAtomManagementClient: ServiceBusAdministrationClient = new ServiceBusAdministrationClient(
env[EnvVarNames.SERVICEBUS_CONNECTION_STRING]
);

const endpointWithProtocol = parseServiceBusConnectionString(
env[EnvVarNames.SERVICEBUS_CONNECTION_STRING]
).endpoint;
Expand All @@ -61,7 +61,13 @@ const newManagementEntity2 = EntityNames.MANAGEMENT_NEW_ENTITY_2;
type AccessRights = ("Manage" | "Send" | "Listen")[];
const randomDate = new Date();

describe("ATOM APIs", () => {
const serviceVersion = getRandomServiceVersion();
const serviceBusAtomManagementClient = new ServiceBusAdministrationClient(
env[EnvVarNames.SERVICEBUS_CONNECTION_STRING],
{ serviceVersion }
);

describe(`ATOM APIs - version ${serviceVersion}`, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause problem if the recording file name depends on the title?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have recordings now. Let's look at that when we add them?

/**
* These tests are just a sanity check that our updates are actually
* _doing_ something. We've run into some bugs where we've done things like
Expand Down
8 changes: 7 additions & 1 deletion sdk/servicebus/service-bus/test/public/utils/testutils2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ServiceBusReceiver,
ServiceBusSessionReceiver,
ServiceBusClientOptions,
ServiceBusSender
ServiceBusSender,
ServiceBusAtomAPIVersion
} from "../../../src";

import { TestClientType, TestMessage } from "./testUtils";
Expand Down Expand Up @@ -616,3 +617,8 @@ export function addServiceBusClientForLiveTesting(
entityNames: () => entityNames
};
}

export function getRandomServiceVersion(): ServiceBusAtomAPIVersion {
const serviceApiVersions: ServiceBusAtomAPIVersion[] = ["2021-05", "2017-04"];
return serviceApiVersions[Math.floor(Math.random() * 2)];
}