[@azure/eventgrid-system-events][@azure/eventgrid-namespaces] Rename eventSubscriptionName to subscriptionName, Remove topicName subscriptionName as optional, Update CI YML (#29977)
### Packages impacted by this PR 1. @azure/eventgrid-system-events 2. @azure/eventgrid-namespaces ### Issues associated with this PR None ### Describe the problem that is addressed by this PR #### @azure/eventgrid-namespaces The 2 clients `EventGridSenderClient` & `EventGridReceiverClient` have the parameters `topicName` and `eventSubscriptionName` as optional. In order to be consistent with all the languages, these 2 parameters must be changed to mandatory. Also, the parameter `eventSubscriptionName` must be changed to `eventSubscriptionName`. #### @azure/eventgrid-system-events The `ci.yml` file must be updated to generate the artifact for release. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? No special design considerations ### Are there test cases added in this PR? _(If not, why?)_ No test cases are required. ### Provide a list of related PRs _(if any)_ None ### Checklists - [X] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) @maorleger @jeremymeng Please review and approve the PR
This commit is contained in:
Родитель
8b5d6ddb7e
Коммит
507c6a1b66
|
@ -36,3 +36,5 @@ extends:
|
|||
safeName: azureeventgrid
|
||||
- name: azure-eventgrid-namespaces
|
||||
safeName: azureeventgridnamespaces
|
||||
- name: azure-eventgrid-system-events
|
||||
safeName: azureeventgridsystemevents
|
||||
|
|
|
@ -96,12 +96,15 @@ const { DefaultAzureCredential } = require("@azure/identity");
|
|||
|
||||
const eventGridSenderClient = new EventGridSenderClient(
|
||||
"<endpoint>",
|
||||
new DefaultAzureCredential()
|
||||
new DefaultAzureCredential(),
|
||||
"<topicName>"
|
||||
);
|
||||
|
||||
const eventGridReceiverClient = new EventGridReceiverClient(
|
||||
"<endpoint>",
|
||||
new DefaultAzureCredential()
|
||||
new DefaultAzureCredential(),
|
||||
"<topicName>",
|
||||
"<subscriptionName>"
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -114,7 +117,8 @@ const eventGridReceiverClient = new EventGridReceiverClient(
|
|||
```js
|
||||
const eventGridSenderClient = new EventGridSenderClient(
|
||||
"<endpoint>",
|
||||
new AzureKeyCredential("<API Key>")
|
||||
new AzureKeyCredential("<API Key>"),
|
||||
"<topicName>"
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -123,7 +127,9 @@ const eventGridSenderClient = new EventGridSenderClient(
|
|||
```js
|
||||
const eventGridReceiverClient = new EventGridReceiverClient(
|
||||
"<endpoint>",
|
||||
new AzureKeyCredential("<API Key>")
|
||||
new AzureKeyCredential("<API Key>"),
|
||||
"<topicName>",
|
||||
"<subscriptionName>"
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -144,7 +150,8 @@ const { EventGridSenderClient, AzureKeyCredential } = require("@azure/eventgrid-
|
|||
|
||||
const client = new EventGridSenderClient(
|
||||
"<endpoint>",
|
||||
new AzureKeyCredential("<API key>")
|
||||
new AzureKeyCredential("<API key>"),
|
||||
"<topicName>"
|
||||
);
|
||||
|
||||
const cloudEvent: CloudEvent = {
|
||||
|
@ -158,7 +165,7 @@ const cloudEvent: CloudEvent = {
|
|||
specversion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await client.sendEvents(cloudEvent, topicName);
|
||||
await client.sendEvents(cloudEvent);
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
|
|
@ -16,8 +16,6 @@ export interface AcknowledgeEventsOptionalParams extends OperationOptions {
|
|||
|
||||
// @public
|
||||
export interface AcknowledgeEventsOptions extends AcknowledgeEventsOptionalParams {
|
||||
eventSubscriptionName?: string;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -61,7 +59,7 @@ export class EventGridDeserializer {
|
|||
|
||||
// @public
|
||||
export class EventGridReceiverClient {
|
||||
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridReceiverClientOptions);
|
||||
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, topicName: string, subscriptionName: string, options?: EventGridReceiverClientOptions);
|
||||
acknowledgeEvents(lockTokens: string[], options?: AcknowledgeEventsOptions): Promise<AcknowledgeResult>;
|
||||
receiveEvents<T>(options?: ReceiveEventsOptions): Promise<ReceiveResult<T>>;
|
||||
rejectEvents(lockTokens: string[], options?: RejectEventsOptions): Promise<RejectResult>;
|
||||
|
@ -71,19 +69,16 @@ export class EventGridReceiverClient {
|
|||
|
||||
// @public
|
||||
export interface EventGridReceiverClientOptions extends EventGridClientOptions {
|
||||
eventSubscriptionName?: string;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export class EventGridSenderClient {
|
||||
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridSenderClientOptions);
|
||||
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, topicName: string, options?: EventGridSenderClientOptions);
|
||||
sendEvents<T>(events: CloudEvent<T>[] | CloudEvent<T>, options?: SendEventsOptions): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface EventGridSenderClientOptions extends EventGridClientOptions {
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -117,8 +112,6 @@ export interface ReceiveEventsOptionalParams extends OperationOptions {
|
|||
|
||||
// @public
|
||||
export interface ReceiveEventsOptions extends ReceiveEventsOptionalParams {
|
||||
eventSubscriptionName?: string;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -132,8 +125,6 @@ export interface RejectEventsOptionalParams extends OperationOptions {
|
|||
|
||||
// @public
|
||||
export interface RejectEventsOptions extends RejectEventsOptionalParams {
|
||||
eventSubscriptionName?: string;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -147,9 +138,7 @@ export type ReleaseDelay = string;
|
|||
|
||||
// @public
|
||||
export interface ReleaseEventsOptions extends OperationOptions {
|
||||
eventSubscriptionName?: string;
|
||||
releaseDelay?: ReleaseDelay;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -164,8 +153,6 @@ export interface RenewEventLocksOptionalParams extends OperationOptions {
|
|||
|
||||
// @public
|
||||
export interface RenewEventLocksOptions extends RenewEventLocksOptionalParams {
|
||||
eventSubscriptionName?: string;
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -186,7 +173,6 @@ export interface SendEventsOptionalParams extends OperationOptions {
|
|||
|
||||
// @public
|
||||
export interface SendEventsOptions extends SendEventOptionalParams {
|
||||
topicName?: string;
|
||||
}
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
|
|
|
@ -26,8 +26,13 @@ const topicName = process.env["TOPIC_NAME"] ?? "testtopic1";
|
|||
|
||||
export async function main(): Promise<void> {
|
||||
// Create the client used to publish events
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key));
|
||||
const receiverClient = new EventGridReceiverClient(endpoint, new AzureKeyCredential(key));
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key), topicName);
|
||||
const receiverClient = new EventGridReceiverClient(
|
||||
endpoint,
|
||||
new AzureKeyCredential(key),
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
);
|
||||
|
||||
// publishes a single cloud event
|
||||
const eventId: string = `singleEventIdV210001`;
|
||||
|
@ -42,12 +47,9 @@ export async function main(): Promise<void> {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
// The Received Cloud Event ID must be equal to the ID of the Event that was published.
|
||||
console.log(`Received Event ID: ${receiveResult.details[0].event.id}`);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,13 @@ const topicName = process.env["TOPIC_NAME"] ?? "testtopic1";
|
|||
|
||||
async function main() {
|
||||
// Create the client used to publish events
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key));
|
||||
const receiverClient = new EventGridReceiverClient(endpoint, new AzureKeyCredential(key));
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key), topicName);
|
||||
const receiverClient = new EventGridReceiverClient(
|
||||
endpoint,
|
||||
new AzureKeyCredential(key),
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
);
|
||||
|
||||
// publishes a single cloud event
|
||||
const eventId = `singleEventIdV210001`;
|
||||
|
@ -36,12 +41,9 @@ async function main() {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult = await receiverClient.receiveEvents();
|
||||
// The Received Cloud Event ID must be equal to the ID of the Event that was published.
|
||||
console.log(`Received Event ID: ${receiveResult.details[0].event.id}`);
|
||||
}
|
||||
|
|
|
@ -25,8 +25,13 @@ const topicName = process.env["TOPIC_NAME"] ?? "testtopic1";
|
|||
|
||||
export async function main(): Promise<void> {
|
||||
// Create the client used to publish events
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key));
|
||||
const receiverClient = new EventGridReceiverClient(endpoint, new AzureKeyCredential(key));
|
||||
const senderClient = new EventGridSenderClient(endpoint, new AzureKeyCredential(key), topicName);
|
||||
const receiverClient = new EventGridReceiverClient(
|
||||
endpoint,
|
||||
new AzureKeyCredential(key),
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
);
|
||||
|
||||
// publishes a single cloud event
|
||||
const eventId: string = `singleEventIdV210001`;
|
||||
|
@ -41,12 +46,9 @@ export async function main(): Promise<void> {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
// The Received Cloud Event ID must be equal to the ID of the Event that was published.
|
||||
console.log(`Received Event ID: ${receiveResult.details[0].event.id}`);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ import { EventGridClient as EventGridClientGenerated } from "./cadl-generated/Ev
|
|||
import {
|
||||
CloudEvent,
|
||||
ReceiveResult,
|
||||
ReceiveEventsOptions,
|
||||
AcknowledgeEventsOptions,
|
||||
ReleaseEventsOptions,
|
||||
RejectEventsOptions,
|
||||
RenewEventLocksOptions,
|
||||
EventGridReceiverClientOptions,
|
||||
ReceiveEventsOptions,
|
||||
} from "./models";
|
||||
import { cloudEventDistributedTracingEnricherPolicy } from "./cloudEventDistrubtedTracingEnricherPolicy";
|
||||
import { tracingPolicyName } from "@azure/core-rest-pipeline";
|
||||
|
@ -28,18 +28,20 @@ import { uint8ArrayToString } from "@azure/core-util";
|
|||
*/
|
||||
export class EventGridReceiverClient {
|
||||
private _client: EventGridClientGenerated;
|
||||
private _topicName: string | undefined;
|
||||
private _eventSubscriptionName: string | undefined;
|
||||
private _topicName: string;
|
||||
private _subscriptionName: string;
|
||||
|
||||
/** Azure Messaging EventGrid Client */
|
||||
constructor(
|
||||
endpoint: string,
|
||||
credential: AzureKeyCredential | TokenCredential,
|
||||
topicName: string,
|
||||
subscriptionName: string,
|
||||
options: EventGridReceiverClientOptions = {},
|
||||
) {
|
||||
this._client = new EventGridClientGenerated(endpoint, credential, options);
|
||||
this._topicName = options?.topicName ?? undefined;
|
||||
this._eventSubscriptionName = options?.eventSubscriptionName ?? undefined;
|
||||
this._topicName = topicName;
|
||||
this._subscriptionName = subscriptionName;
|
||||
this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
|
||||
afterPolicies: [tracingPolicyName],
|
||||
});
|
||||
|
@ -54,19 +56,11 @@ export class EventGridReceiverClient {
|
|||
async receiveEvents<T>(
|
||||
options: ReceiveEventsOptions = { requestOptions: {} },
|
||||
): Promise<ReceiveResult<T>> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
const eventSubscriptionName = options?.eventSubscriptionName ?? this._eventSubscriptionName;
|
||||
|
||||
if (!eventSubscriptionName) {
|
||||
throw new Error("Event Subscription name is required");
|
||||
}
|
||||
|
||||
const result = await this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
|
||||
const result = await this._client.receiveCloudEvents(
|
||||
this._topicName,
|
||||
this._subscriptionName,
|
||||
options,
|
||||
);
|
||||
|
||||
const modifiedResult: ReceiveResult<T> = {
|
||||
details: result.details.map((receiveDetails) => {
|
||||
|
@ -109,21 +103,9 @@ export class EventGridReceiverClient {
|
|||
lockTokens: string[],
|
||||
options: AcknowledgeEventsOptions = { requestOptions: {} },
|
||||
): Promise<AcknowledgeResult> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
const eventSubscriptionName = options?.eventSubscriptionName ?? this._eventSubscriptionName;
|
||||
|
||||
if (!eventSubscriptionName) {
|
||||
throw new Error("Event Subscription name is required");
|
||||
}
|
||||
|
||||
return this._client.acknowledgeCloudEvents(
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
this._topicName,
|
||||
this._subscriptionName,
|
||||
lockTokens,
|
||||
options,
|
||||
);
|
||||
|
@ -142,19 +124,7 @@ export class EventGridReceiverClient {
|
|||
lockTokens: string[],
|
||||
options: ReleaseEventsOptions = { requestOptions: {} },
|
||||
): Promise<ReleaseResult> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
const eventSubscriptionName = options?.eventSubscriptionName ?? this._eventSubscriptionName;
|
||||
|
||||
if (!eventSubscriptionName) {
|
||||
throw new Error("Event Subscription name is required");
|
||||
}
|
||||
|
||||
return this._client.releaseCloudEvents(topicName, eventSubscriptionName, lockTokens, {
|
||||
return this._client.releaseCloudEvents(this._topicName, this._subscriptionName, lockTokens, {
|
||||
...options,
|
||||
releaseDelayInSeconds: options.releaseDelay,
|
||||
});
|
||||
|
@ -171,19 +141,12 @@ export class EventGridReceiverClient {
|
|||
lockTokens: string[],
|
||||
options: RejectEventsOptions = { requestOptions: {} },
|
||||
): Promise<RejectResult> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
const eventSubscriptionName = options?.eventSubscriptionName ?? this._eventSubscriptionName;
|
||||
|
||||
if (!eventSubscriptionName) {
|
||||
throw new Error("Event Subscription name is required");
|
||||
}
|
||||
|
||||
return this._client.rejectCloudEvents(topicName, eventSubscriptionName, lockTokens, options);
|
||||
return this._client.rejectCloudEvents(
|
||||
this._topicName,
|
||||
this._subscriptionName,
|
||||
lockTokens,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,18 +159,11 @@ export class EventGridReceiverClient {
|
|||
lockTokens: string[],
|
||||
options: RenewEventLocksOptions = { requestOptions: {} },
|
||||
): Promise<RenewLocksResult> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
const eventSubscriptionName = options?.eventSubscriptionName ?? this._eventSubscriptionName;
|
||||
|
||||
if (!eventSubscriptionName) {
|
||||
throw new Error("Event Subscription name is required");
|
||||
}
|
||||
|
||||
return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, lockTokens, options);
|
||||
return this._client.renewCloudEventLocks(
|
||||
this._topicName,
|
||||
this._subscriptionName,
|
||||
lockTokens,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,16 +19,17 @@ import { tracingPolicyName } from "@azure/core-rest-pipeline";
|
|||
*/
|
||||
export class EventGridSenderClient {
|
||||
private _client: EventGridClientGenerated;
|
||||
private _topicName: string | undefined;
|
||||
private _topicName: string;
|
||||
|
||||
/** Azure Messaging EventGrid Client */
|
||||
constructor(
|
||||
endpoint: string,
|
||||
credential: AzureKeyCredential | TokenCredential,
|
||||
topicName: string,
|
||||
options: EventGridSenderClientOptions = {},
|
||||
) {
|
||||
this._client = new EventGridClientGenerated(endpoint, credential, options);
|
||||
this._topicName = options?.topicName ?? undefined;
|
||||
this._topicName = topicName;
|
||||
this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
|
||||
afterPolicies: [tracingPolicyName],
|
||||
});
|
||||
|
@ -49,21 +50,15 @@ export class EventGridSenderClient {
|
|||
events: CloudEvent<T>[] | CloudEvent<T>,
|
||||
options: SendEventsOptions = { requestOptions: {} },
|
||||
): Promise<void> {
|
||||
const topicName = options?.topicName ?? this._topicName;
|
||||
|
||||
if (!topicName) {
|
||||
throw new Error("Topic name is required");
|
||||
}
|
||||
|
||||
if (Array.isArray(events)) {
|
||||
const eventsWireModel: Array<CloudEventWireModel> = [];
|
||||
for (const individualevent of events) {
|
||||
eventsWireModel.push(convertCloudEventToModelType(individualevent));
|
||||
}
|
||||
await this._client.publishCloudEvents(topicName, eventsWireModel, options);
|
||||
await this._client.publishCloudEvents(this._topicName, eventsWireModel, options);
|
||||
} else {
|
||||
const cloudEventWireModel: CloudEventWireModel = convertCloudEventToModelType(events);
|
||||
await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
|
||||
await this._client.publishCloudEvent(this._topicName, cloudEventWireModel, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,73 +23,31 @@ export interface SendEventOptions extends OperationOptions {
|
|||
}
|
||||
|
||||
/** Event Grid Sender Client Options */
|
||||
export interface EventGridSenderClientOptions extends EventGridOptions {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
}
|
||||
export interface EventGridSenderClientOptions extends EventGridOptions {}
|
||||
|
||||
/** Event Grid Receiver Client Options */
|
||||
export interface EventGridReceiverClientOptions extends EventGridOptions {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
}
|
||||
export interface EventGridReceiverClientOptions extends EventGridOptions {}
|
||||
|
||||
/** Send Events Options */
|
||||
export interface SendEventsOptions extends PublishCloudEventOptionalParams {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
}
|
||||
export interface SendEventsOptions extends PublishCloudEventOptionalParams {}
|
||||
|
||||
/** Receive Events Options */
|
||||
export interface ReceiveEventsOptions extends ReceiveCloudEventsOptionalParams {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
}
|
||||
export interface ReceiveEventsOptions extends ReceiveCloudEventsOptionalParams {}
|
||||
|
||||
/** Acknowledge Events Options */
|
||||
export interface AcknowledgeEventsOptions extends AcknowledgeCloudEventsOptionalParams {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
}
|
||||
export interface AcknowledgeEventsOptions extends AcknowledgeCloudEventsOptionalParams {}
|
||||
|
||||
/** Release Events Options */
|
||||
export interface ReleaseEventsOptions extends OperationOptions {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
|
||||
/** Release events with the specified delay in seconds. */
|
||||
releaseDelay?: ReleaseDelay;
|
||||
}
|
||||
|
||||
/** Reject Events Options */
|
||||
export interface RejectEventsOptions extends RejectCloudEventsOptionalParams {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
}
|
||||
export interface RejectEventsOptions extends RejectCloudEventsOptionalParams {}
|
||||
|
||||
/** Renew Event Locks Options */
|
||||
export interface RenewEventLocksOptions extends RenewCloudEventLocksOptionalParams {
|
||||
/** Topic name */
|
||||
topicName?: string;
|
||||
|
||||
/** Event Subscription name */
|
||||
eventSubscriptionName?: string;
|
||||
}
|
||||
export interface RenewEventLocksOptions extends RenewCloudEventLocksOptionalParams {}
|
||||
|
||||
/** Known values of {@link ReleaseDelay} that the service accepts. */
|
||||
export const enum KnownReleaseDelay {
|
||||
|
|
|
@ -15,26 +15,13 @@ import {
|
|||
import { createRecordedClient } from "./utils/recordedClient";
|
||||
import { Buffer } from "buffer";
|
||||
/* eslint no-constant-condition: "off" */
|
||||
async function clearMessages(
|
||||
receiverClient: EventGridReceiverClient,
|
||||
topicName: string,
|
||||
eventSubscriptionName: string,
|
||||
): Promise<void> {
|
||||
async function clearMessages(receiverClient: EventGridReceiverClient): Promise<void> {
|
||||
// Clear any messages that may be available in the topic.
|
||||
let receivedResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
let receivedResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
while (receivedResult && receivedResult.details.length > 0) {
|
||||
const lockToken = receivedResult.details[0].brokerProperties.lockToken;
|
||||
await receiverClient.acknowledgeEvents([lockToken], {
|
||||
eventSubscriptionName,
|
||||
topicName,
|
||||
});
|
||||
receivedResult = await receiverClient.receiveEvents({
|
||||
eventSubscriptionName,
|
||||
topicName,
|
||||
});
|
||||
await receiverClient.acknowledgeEvents([lockToken]);
|
||||
receivedResult = await receiverClient.receiveEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,20 +34,23 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
let maxDeliveryCount: number;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
eventSubscriptionName = env["EVENT_SUBSCRIPTION_NAME"] ?? "testsubscription1";
|
||||
topicName = env["TOPIC_NAME"] ?? "testtopic1";
|
||||
maxDeliveryCount = env["MAX_DELIVERY_COUNT"] ? parseInt(env["MAX_DELIVERY_COUNT"]) : 10;
|
||||
|
||||
({ senderClient, receiverClient, recorder } = await createRecordedClient(
|
||||
this.currentTest,
|
||||
"EVENT_GRID_NAMESPACES_ENDPOINT",
|
||||
"EVENT_GRID_NAMESPACES_KEY",
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
));
|
||||
|
||||
eventSubscriptionName = env["EVENT_SUBSCRIPTION_NAME"] ?? "testsubscription1";
|
||||
topicName = env["TOPIC_NAME"] ?? "testtopic1";
|
||||
maxDeliveryCount = env["MAX_DELIVERY_COUNT"] ? parseInt(env["MAX_DELIVERY_COUNT"]) : 10;
|
||||
await clearMessages(receiverClient, topicName, eventSubscriptionName);
|
||||
await clearMessages(receiverClient);
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
await clearMessages(receiverClient, topicName, eventSubscriptionName);
|
||||
await clearMessages(receiverClient);
|
||||
await recorder.stop();
|
||||
});
|
||||
|
||||
|
@ -78,12 +68,9 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
|
||||
const deserializer: EventGridDeserializer = new EventGridDeserializer();
|
||||
const result: CloudEvent<any>[] = await deserializer.deserializeCloudEvents(
|
||||
|
@ -121,12 +108,10 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
},
|
||||
];
|
||||
await senderClient.sendEvents(cloudEvents, { topicName });
|
||||
await senderClient.sendEvents(cloudEvents);
|
||||
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
eventSubscriptionName,
|
||||
maxEvents: 2,
|
||||
topicName,
|
||||
});
|
||||
|
||||
assert.equal(2, receiveResult.details.length);
|
||||
|
@ -155,16 +140,13 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
|
||||
let counter: number = 0;
|
||||
while (true) {
|
||||
// Receive the Published Cloud Event
|
||||
counter++;
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
|
||||
if (
|
||||
(counter > maxDeliveryCount && receiveResult.details.length !== 0) ||
|
||||
|
@ -178,7 +160,7 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
}
|
||||
|
||||
const lockToken = receiveResult.details[0].brokerProperties.lockToken;
|
||||
await receiverClient.releaseEvents([lockToken], { eventSubscriptionName, topicName });
|
||||
await receiverClient.releaseEvents([lockToken]);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -195,24 +177,15 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
let receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
let receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
const lockToken = receiveResult.details[0].brokerProperties.lockToken;
|
||||
const rejectResult: RejectResult = await receiverClient.rejectEvents([lockToken], {
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const rejectResult: RejectResult = await receiverClient.rejectEvents([lockToken]);
|
||||
assert.equal(rejectResult.succeededLockTokens.length, 1);
|
||||
assert.equal(rejectResult.succeededLockTokens[0], lockToken);
|
||||
|
||||
receiveResult = await receiverClient.receiveEvents({
|
||||
eventSubscriptionName,
|
||||
topicName,
|
||||
});
|
||||
receiveResult = await receiverClient.receiveEvents();
|
||||
assert.equal(receiveResult.details.length, 0);
|
||||
});
|
||||
|
||||
|
@ -229,17 +202,11 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, { topicName });
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
const lockToken = receiveResult.details[0].brokerProperties.lockToken;
|
||||
const renewResult: RenewLocksResult = await receiverClient.renewEventLocks([lockToken], {
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const renewResult: RenewLocksResult = await receiverClient.renewEventLocks([lockToken]);
|
||||
assert.equal(renewResult.succeededLockTokens.length, 1);
|
||||
assert.equal(renewResult.succeededLockTokens[0], lockToken);
|
||||
});
|
||||
|
@ -261,14 +228,9 @@ describe("Event Grid Namespace Client", function (this: Suite) {
|
|||
specVersion: "1.0",
|
||||
};
|
||||
// Publish the Cloud Event
|
||||
await senderClient.sendEvents(cloudEvent, {
|
||||
topicName,
|
||||
});
|
||||
await senderClient.sendEvents(cloudEvent);
|
||||
// Receive the Published Cloud Event
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents({
|
||||
topicName,
|
||||
eventSubscriptionName,
|
||||
});
|
||||
const receiveResult: ReceiveResult<any> = await receiverClient.receiveEvents();
|
||||
|
||||
for (const detail of receiveResult.details) {
|
||||
const event = detail.event;
|
||||
|
|
|
@ -38,6 +38,8 @@ export async function createRecordedClient(
|
|||
currentTest: Test | undefined,
|
||||
endpointEnv: string,
|
||||
apiKeyEnv: string,
|
||||
topicName: string,
|
||||
subscriptionName: string,
|
||||
options: {
|
||||
additionalPolicies?: AdditionalPolicyConfig[];
|
||||
} = {},
|
||||
|
@ -49,6 +51,7 @@ export async function createRecordedClient(
|
|||
senderClient: new EventGridSenderClient(
|
||||
assertEnvironmentVariable(endpointEnv),
|
||||
new AzureKeyCredential(assertEnvironmentVariable(apiKeyEnv)),
|
||||
topicName,
|
||||
recorder.configureClientOptions({
|
||||
additionalPolicies: options.additionalPolicies,
|
||||
}),
|
||||
|
@ -56,6 +59,8 @@ export async function createRecordedClient(
|
|||
receiverClient: new EventGridReceiverClient(
|
||||
assertEnvironmentVariable(endpointEnv),
|
||||
new AzureKeyCredential(assertEnvironmentVariable(apiKeyEnv)),
|
||||
topicName,
|
||||
subscriptionName,
|
||||
recorder.configureClientOptions({
|
||||
additionalPolicies: options.additionalPolicies,
|
||||
}),
|
||||
|
|
Загрузка…
Ссылка в новой задаче