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] [Event Hubs] Update websocket options shape #7368

Merged
merged 8 commits into from
Feb 14, 2020
3 changes: 1 addition & 2 deletions sdk/core/core-amqp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.2 (Unreleased)

- Exports `WebSocketOptions` interface to configure the channelling of the AMQP connection over Web Sockets. [PR 7368](https://github.com/Azure/azure-sdk-for-js/pull/7368)

## 1.0.1 (2020-02-06)

Expand All @@ -24,8 +25,6 @@

- Treat ETIMEOUT error from dns.resolve as network disconnected.

- Treat ETIMEOUT error from dns.resolve as network disconnected.

## 1.0.0-preview.5 (2019-10-29)

- Updated to use the latest version of the `@azure/abort-controller` and `@azure/core-auth` packages.
Expand Down
3 changes: 2 additions & 1 deletion sdk/core/core-amqp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export {
isIotHubConnectionString,
randomNumberFromInterval,
AsyncLock,
isNode
isNode,
WebSocketOptions
} from "./util/utils";
export { logger } from "./log";
24 changes: 24 additions & 0 deletions sdk/core/core-amqp/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import AsyncLock from "async-lock";
import { AbortSignalLike, AbortError } from "@azure/abort-controller";
import { WebSocketImpl } from "rhea-promise";

export { AsyncLock };
/**
Expand All @@ -28,6 +29,29 @@ export interface AsyncLockOptions {
*/
Promise?: any;
}

/**
* Options to configure the channelling of the AMQP connection over Web Sockets.
*/
export interface WebSocketOptions {
/**
* @property
* The WebSocket constructor used to create an AMQP connection over a WebSocket.
* This option should be provided in the below scenarios:
* - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is now in core-amqp, "Event Hubs" should not be mentioned.
Skip it altogether

cc @HarshaNalluru, @chradek

Copy link
Member

Choose a reason for hiding this comment

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

Welcome back @ramya-rao-a !

* - Your application needs to be run behind a proxy server.
* - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation
* instead of the built-in WebSocket in the browser.
*/
webSocket?: WebSocketImpl;
/**
* @property
* Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates
* the WebSocket.
*/
webSocketConstructorOptions?: any;
}

/**
* A constant that indicates whether the environment is node.js or browser based.
*/
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-hubs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-amqp": "^1.0.1",
"@azure/core-amqp": "^1.0.2",
"@azure/core-asynciterator-polyfill": "^1.0.0",
"@azure/core-tracing": "1.0.0-preview.7",
"@azure/identity": "^1.0.0",
Expand Down
7 changes: 2 additions & 5 deletions sdk/eventhub/event-hubs/review/event-hubs.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SpanContext } from '@opentelemetry/types';
import { SpanOptions } from '@opentelemetry/types';
import { TokenCredential } from '@azure/core-amqp';
import { WebSocketImpl } from 'rhea-promise';
import { WebSocketOptions } from '@azure/core-amqp';

// @public
export interface Checkpoint {
Expand Down Expand Up @@ -266,11 +267,7 @@ export interface TryAddOptions {

export { WebSocketImpl }

// @public
export interface WebSocketOptions {
webSocket?: WebSocketImpl;
webSocketConstructorOptions?: any;
}
export { WebSocketOptions }


// (No @packageDocumentation comment for this package)
Expand Down
5 changes: 2 additions & 3 deletions sdk/eventhub/event-hubs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export {
CreateBatchOptions,
GetPartitionIdsOptions,
GetPartitionPropertiesOptions,
GetEventHubPropertiesOptions,
WebSocketOptions
GetEventHubPropertiesOptions
} from "./models/public";
export { EventHubConsumerClient } from "./eventHubConsumerClient";
export { EventHubProducerClient } from "./eventHubProducerClient";
Expand All @@ -34,5 +33,5 @@ export { EventDataBatch, TryAddOptions } from "./eventDataBatch";
export { Checkpoint } from "./partitionProcessor";
export { CheckpointStore, PartitionOwnership } from "./eventProcessor";
export { CloseReason } from "./models/public";
export { MessagingError, RetryOptions, TokenCredential } from "@azure/core-amqp";
export { MessagingError, RetryOptions, TokenCredential, WebSocketOptions } from "@azure/core-amqp";
chradek marked this conversation as resolved.
Show resolved Hide resolved
export { logger } from "./log";
25 changes: 1 addition & 24 deletions sdk/eventhub/event-hubs/src/models/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the MIT License.

import { OperationOptions } from "../util/operationOptions";
import { RetryOptions } from "@azure/core-amqp";
import { WebSocketImpl } from "rhea-promise";
import { RetryOptions, WebSocketOptions } from "@azure/core-amqp";

/**
* The set of options to configure the behavior of `getEventHubProperties`.
Expand Down Expand Up @@ -114,28 +113,6 @@ export interface EventHubClientOptions {
userAgent?: string;
}

/**
* Options to configure the channelling of the AMQP connection over Web Sockets.
*/
export interface WebSocketOptions {
/**
* @property
* The WebSocket constructor used to create an AMQP connection over a WebSocket.
* This option should be provided in the below scenarios:
* - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.
* - Your application needs to be run behind a proxy server
* - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation
* instead of the built-in WebSocket in the browser.
*/
webSocket?: WebSocketImpl;
/**
* @property
* Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates
* the WebSocket.
*/
webSocketConstructorOptions?: any;
}

/**
* Options to configure the `createBatch` method on the `EventHubProducerClient`.
* - `partitionKey` : A value that is hashed to produce a partition assignment.
Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/service-bus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
]
},
"dependencies": {
"@azure/core-amqp": "^1.0.1",
"@azure/core-amqp": "^1.0.2",
"@azure/core-http": "^1.0.0",
"@opentelemetry/types": "^0.2.0",
"@types/is-buffer": "^2.0.0",
Expand Down
6 changes: 4 additions & 2 deletions sdk/servicebus/service-bus/review/service-bus.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { RetryOptions } from '@azure/core-amqp';
import { TokenCredential } from '@azure/core-amqp';
import { TokenType } from '@azure/core-amqp';
import { WebSocketImpl } from 'rhea-promise';
import { WebSocketOptions } from '@azure/core-amqp';

// @public
export type AuthorizationRule = {
Expand Down Expand Up @@ -259,8 +260,7 @@ export class ServiceBusClient {
// @public
export interface ServiceBusClientOptions {
dataTransformer?: DataTransformer;
webSocket?: WebSocketImpl;
webSocketConstructorOptions?: any;
webSocketOptions?: WebSocketOptions;
}

// Warning: (ae-forgotten-export) The symbol "ReceivedMessage" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -476,6 +476,8 @@ export interface TopicOptions {

export { WebSocketImpl }

export { WebSocketOptions }


// (No @packageDocumentation comment for this package)

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 @@ -12,7 +12,8 @@ export {
DataTransformer,
delay,
MessagingError,
RetryOptions
RetryOptions,
WebSocketOptions
} from "@azure/core-amqp";

export { QueueClient } from "./queueClient";
Expand Down
18 changes: 6 additions & 12 deletions sdk/servicebus/service-bus/src/serviceBusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.

import * as log from "./log";

import { WebSocketImpl } from "rhea-promise";
import { ConnectionContext } from "./connectionContext";
import { QueueClient } from "./queueClient";
import { TopicClient } from "./topicClient";
Expand All @@ -15,6 +13,7 @@ import {
isTokenCredential
} from "@azure/core-amqp";
import { SubscriptionClient } from "./subscriptionClient";
import { WebSocketOptions } from "@azure/core-amqp";
chradek marked this conversation as resolved.
Show resolved Hide resolved

/**
* Describes the options that can be provided while creating the ServiceBusClient.
Expand All @@ -29,15 +28,10 @@ export interface ServiceBusClientOptions {
*/
dataTransformer?: DataTransformer;
/**
* @property The WebSocket constructor used to create an AMQP connection
* over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a
* TCP socket will be used if a WebSocket constructor is not provided.
*/
webSocket?: WebSocketImpl;
/**
* @property Options to be passed to the WebSocket constructor
* @property
* Options to configure the channelling of the AMQP connection over Web Sockets.
*/
webSocketConstructorOptions?: any;
webSocketOptions?: WebSocketOptions;
}

/**
Expand Down Expand Up @@ -93,9 +87,9 @@ export class ServiceBusClient {
config = ConnectionConfig.create(hostOrConnectionString);

options = credentialOrServiceBusClientOptions as ServiceBusClientOptions;
config.webSocket = options && options.webSocket;
config.webSocket = options?.webSocketOptions?.webSocket;
config.webSocketEndpointPath = "$servicebus/websocket";
config.webSocketConstructorOptions = options && options.webSocketConstructorOptions;
config.webSocketConstructorOptions = options?.webSocketOptions?.webSocketConstructorOptions;

// Since connectionstring was passed, create a SharedKeyCredential
credential = new SharedKeyCredential(config.sharedAccessKeyName, config.sharedAccessKey);
Expand Down