Skip to content

Commit 0555acb

Browse files
authored
[ServiceBus] Migrate REST-based client to core-rest-pipeline (Azure#19587)
* Move to depend on core v2 libraries. * Previously WebResourceLike.body is of type any so we were able to assign an object to it, then relies on the internal logic in `executeAtomXmlOperation()` to stringify it to XML before sending the request. Now that `PipelineRequest.body` is strongly typed, `executeAtomXmlOperation()` is updated to optionally take the strongly typed request objects for PUT operations. * Add a compatibility layer to transform PipelineResponse to HttpResponse like by copying most relevant properties of `WebResourceLike` and add copy of `HttpResponse` * Bump version * Stop verifying AbortError error message. It turns out that we now have a different error message after switching to Fetch http client for browser. Previously we were catching the one from xhrHttpClient but now we get a DOMException from browser. As error message isn't part of public Api surface, the verification of error message is removed.
1 parent 18aa785 commit 0555acb

31 files changed

+1033
-359
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 34 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/servicebus/service-bus/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Release History
22

3+
## 7.6.0-beta.1 (Unreleased)
4+
5+
### Features Added
6+
7+
### Breaking Changes
8+
9+
### Bugs Fixed
10+
11+
### Other Changes
12+
13+
- Migrate to depend on newer version of Core libraries core-client and core-rest-pipeline which bring better maintainability and performance. [PR #19587](https://github.com/Azure/azure-sdk-for-js/pull/19587)
14+
315
## 7.5.1 (2022-03-08)
416

517
### Bugs Fixed

sdk/servicebus/service-bus/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@azure/service-bus",
33
"sdk-type": "client",
44
"author": "Microsoft Corporation",
5-
"version": "7.5.1",
5+
"version": "7.6.0-beta.1",
66
"license": "MIT",
77
"description": "Azure Service Bus SDK for JavaScript",
88
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/",
@@ -107,11 +107,14 @@
107107
"dependencies": {
108108
"@azure/abort-controller": "^1.0.0",
109109
"@azure/core-amqp": "^3.1.0",
110+
"@azure/core-auth": "^1.3.0",
110111
"@azure/core-asynciterator-polyfill": "^1.0.0",
111-
"@azure/core-http": "^2.0.0",
112+
"@azure/core-client": "^1.0.0",
113+
"@azure/core-rest-pipeline": "^1.1.0",
112114
"@azure/core-tracing": "1.0.0-preview.13",
113115
"@azure/core-paging": "^1.1.1",
114-
"@azure/core-auth": "^1.3.0",
116+
"@azure/core-util": "^1.0.0-beta.1",
117+
"@azure/core-xml": "^1.0.0",
115118
"@azure/logger": "^1.0.0",
116119
"@types/is-buffer": "^2.0.0",
117120
"@types/long": "^4.0.1",
@@ -136,6 +139,7 @@
136139
"@types/glob": "^7.1.1",
137140
"@types/mocha": "^7.0.2",
138141
"@types/node": "^12.0.0",
142+
"@types/uuid": "^8.0.0",
139143
"@types/ws": "^7.2.4",
140144
"chai": "^4.2.0",
141145
"chai-as-promised": "^7.1.1",
@@ -170,6 +174,7 @@
170174
"rollup": "^2.0.0",
171175
"ts-node": "^10.0.0",
172176
"typescript": "~4.2.0",
177+
"uuid": "^8.3.0",
173178
"ws": "^8.0.0",
174179
"sinon": "^9.0.2",
175180
"@types/sinon": "^9.0.4",

sdk/servicebus/service-bus/review/service-bus.api.md

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
66

77
/// <reference types="node" />
88

9+
import { AbortSignalLike } from '@azure/abort-controller';
910
import { AmqpAnnotatedMessage } from '@azure/core-amqp';
11+
import { CommonClientOptions } from '@azure/core-client';
1012
import { delay } from '@azure/core-amqp';
1113
import { Delivery } from 'rhea-promise';
12-
import { HttpResponse } from '@azure/core-http';
14+
import { HttpMethods } from '@azure/core-rest-pipeline';
1315
import { default as Long_2 } from 'long';
1416
import { MessagingError } from '@azure/core-amqp';
1517
import { NamedKeyCredential } from '@azure/core-auth';
16-
import { OperationOptions } from '@azure/core-http';
18+
import { OperationOptions } from '@azure/core-client';
1719
import { OperationTracingOptions } from '@azure/core-tracing';
1820
import { PagedAsyncIterableIterator } from '@azure/core-paging';
1921
import { PageSettings } from '@azure/core-paging';
20-
import { PipelineOptions } from '@azure/core-http';
22+
import { ProxySettings } from '@azure/core-rest-pipeline';
2123
import { RetryMode } from '@azure/core-amqp';
2224
import { RetryOptions } from '@azure/core-amqp';
2325
import { SASCredential } from '@azure/core-auth';
24-
import { ServiceClient } from '@azure/core-http';
26+
import { ServiceClient } from '@azure/core-client';
2527
import { Span } from '@azure/core-tracing';
2628
import { SpanContext } from '@azure/core-tracing';
2729
import { TokenCredential } from '@azure/core-auth';
2830
import { TokenType } from '@azure/core-amqp';
29-
import { UserAgentOptions } from '@azure/core-http';
31+
import { UserAgentPolicyOptions } from '@azure/core-rest-pipeline';
3032
import { WebSocketImpl } from 'rhea-promise';
3133
import { WebSocketOptions } from '@azure/core-amqp';
3234

@@ -145,6 +147,35 @@ export type EntityStatus = "Active" | "Creating" | "Deleting" | "ReceiveDisabled
145147
export interface GetMessageIteratorOptions extends OperationOptionsBase {
146148
}
147149

150+
// @public
151+
export interface HttpHeader {
152+
name: string;
153+
value: string;
154+
}
155+
156+
// @public
157+
export interface HttpHeadersLike {
158+
clone(): HttpHeadersLike;
159+
contains(headerName: string): boolean;
160+
get(headerName: string): string | undefined;
161+
headerNames(): string[];
162+
headersArray(): HttpHeader[];
163+
headerValues(): string[];
164+
rawHeaders(): RawHttpHeaders;
165+
remove(headerName: string): boolean;
166+
set(headerName: string, headerValue: string | number): void;
167+
toJson(options?: {
168+
preserveCase?: boolean;
169+
}): RawHttpHeaders;
170+
}
171+
172+
// @public
173+
export interface HttpResponse {
174+
headers: HttpHeadersLike;
175+
request: WebResourceLike;
176+
status: number;
177+
}
178+
148179
// @public
149180
export function isServiceBusError(err: unknown): err is ServiceBusError;
150181

@@ -225,6 +256,11 @@ export interface QueueRuntimeProperties {
225256
transferMessageCount: number;
226257
}
227258

259+
// @public
260+
export type RawHttpHeaders = {
261+
[headerName: string]: string;
262+
};
263+
228264
// @public
229265
export interface ReceiveMessagesOptions extends OperationOptionsBase {
230266
maxWaitTimeInMs?: number;
@@ -280,7 +316,7 @@ export class ServiceBusAdministrationClient extends ServiceClient {
280316
}
281317

282318
// @public
283-
export interface ServiceBusAdministrationClientOptions extends PipelineOptions {
319+
export interface ServiceBusAdministrationClientOptions extends CommonClientOptions {
284320
serviceVersion?: "2021-05" | "2017-04";
285321
}
286322

@@ -302,7 +338,7 @@ export class ServiceBusClient {
302338
// @public
303339
export interface ServiceBusClientOptions {
304340
retryOptions?: RetryOptions;
305-
userAgentOptions?: UserAgentOptions;
341+
userAgentOptions?: UserAgentPolicyOptions;
306342
webSocketOptions?: WebSocketOptions;
307343
}
308344

@@ -582,13 +618,42 @@ export interface TopicRuntimeProperties {
582618
subscriptionCount?: number;
583619
}
584620

621+
// @public
622+
export type TransferProgressEvent = {
623+
loadedBytes: number;
624+
};
625+
585626
// @public
586627
export interface TryAddOptions {
587628
// @deprecated (undocumented)
588629
parentSpan?: Span | SpanContext | null;
589630
tracingOptions?: OperationTracingOptions;
590631
}
591632

633+
// @public
634+
export interface WebResourceLike {
635+
abortSignal?: AbortSignalLike;
636+
body?: any;
637+
decompressResponse?: boolean;
638+
formData?: any;
639+
headers: HttpHeadersLike;
640+
keepAlive?: boolean;
641+
method: HttpMethods;
642+
onDownloadProgress?: (progress: TransferProgressEvent) => void;
643+
onUploadProgress?: (progress: TransferProgressEvent) => void;
644+
proxySettings?: ProxySettings;
645+
query?: {
646+
[key: string]: any;
647+
};
648+
requestId: string;
649+
// @deprecated
650+
streamResponseBody?: boolean;
651+
streamResponseStatusCodes?: Set<number>;
652+
timeout: number;
653+
url: string;
654+
withCredentials: boolean;
655+
}
656+
592657
export { WebSocketImpl }
593658

594659
export { WebSocketOptions }

sdk/servicebus/service-bus/src/constructorHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
TokenCredential,
1717
} from "@azure/core-auth";
1818
import { ConnectionContext } from "./connectionContext";
19-
import { UserAgentOptions } from "@azure/core-http";
19+
import { UserAgentPolicyOptions } from "@azure/core-rest-pipeline";
2020
import {
2121
parseServiceBusConnectionString,
2222
ServiceBusConnectionStringProperties,
@@ -51,7 +51,7 @@ export interface ServiceBusClientOptions {
5151
/**
5252
* Options for adding user agent details to outgoing requests.
5353
*/
54-
userAgentOptions?: UserAgentOptions;
54+
userAgentOptions?: UserAgentPolicyOptions;
5555
}
5656

5757
/**

sdk/servicebus/service-bus/src/core/messageReceiver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DispositionType, ServiceBusMessageImpl } from "../serviceBusMessage";
1515
import { getUniqueName } from "../util/utils";
1616
import { ProcessErrorArgs, ReceiveMode, SubscribeOptions } from "../models";
1717
import { DispositionStatusOptions } from "./managementClient";
18-
import { AbortSignalLike } from "@azure/core-http";
18+
import { AbortSignalLike } from "@azure/abort-controller";
1919
import {
2020
onMessageSettled,
2121
DeferredPromiseAndTimer,

sdk/servicebus/service-bus/src/diagnostics/tracing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { OperationOptions } from "@azure/core-http";
4+
import { OperationOptions } from "@azure/core-client";
55
import {
66
createSpanFunction,
77
extractSpanContextFromTraceParentHeader,
@@ -192,8 +192,8 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption
192192
}
193193
194194
function takeSomeOptionsFromSomewhere(someOptionsPassedIntoTheirFunction) {
195-
196-
batch.tryAddMessage(message, {
195+
196+
batch.tryAddMessage(message, {
197197
// "runtime" blend of options from some other part of their app
198198
...someOptionsPassedIntoTheirFunction, // parentSpan comes along for the ride...
199199
@@ -208,9 +208,9 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption
208208
209209
And now they've accidentally been opted into the legacy code path even though they think
210210
they're using the modern code path.
211-
211+
212212
This does kick the can down the road a bit - at some point we will be putting them in this
213-
situation where things looked okay but their spans are becoming unparented but we can
213+
situation where things looked okay but their spans are becoming unparented but we can
214214
try to announce this (and other changes related to tracing) in our next big rev.
215215
*/
216216

sdk/servicebus/service-bus/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {
1313
WebSocketOptions,
1414
} from "@azure/core-amqp";
1515
export { TokenCredential } from "@azure/core-auth";
16-
export { OperationOptions } from "@azure/core-http";
16+
export { OperationOptions } from "@azure/core-client";
1717
export { Delivery, WebSocketImpl } from "rhea-promise";
1818
export { ServiceBusClientOptions } from "./constructorHelpers";
1919
export { CorrelationRuleFilter } from "./core/managementClient";
@@ -68,3 +68,11 @@ export {
6868
ServiceBusConnectionStringProperties,
6969
} from "./util/connectionStringUtils";
7070
export { AuthorizationRule, EntityAvailabilityStatus, EntityStatus } from "./util/utils";
71+
export {
72+
HttpResponse,
73+
HttpHeader,
74+
RawHttpHeaders,
75+
HttpHeadersLike,
76+
TransferProgressEvent,
77+
WebResourceLike,
78+
} from "./util/compat";

sdk/servicebus/service-bus/src/modelsToBeSharedWithEventHubs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// TODO: this code is a straight-copy from EventHubs. Need to merge.
55

66
import { OperationTracingOptions, SpanStatusCode, Span, SpanContext } from "@azure/core-tracing";
7-
import { OperationOptions } from "@azure/core-http";
7+
import { OperationOptions } from "@azure/core-client";
88

99
/**
10-
* NOTE: This type is intended to mirror the relevant fields and structure from `@azure/core-http` OperationOptions
10+
* NOTE: This type is intended to mirror the relevant fields and structure from `@azure/core-client` OperationOptions
1111
*
1212
* Options for configuring tracing and the abortSignal.
1313
*/

0 commit comments

Comments
 (0)