[EventGrid] API Updates and Migration Guide (#13664)
* [EventGrid] Adopt `AzureSASCredential` Remove `EventGridSharedAccessSignatureCredential` type in favor of using the common type we have now added in core. Fixes #13054 * [EventGrid] API Updates based on Arch Board review - Instead of having three different `send` methods with suffixes for different input schema types, we now have a single method `send`. When you construct the client, you provide the input schema to be used when sending an event. When using TypeScript, the type signature of `send` depends on the input schema the client was constructed with. - Rename `EventGridConsumer` to `EventGridDeserializer`. - Remove the custom deserializers feature of `EventGridDeserializer`. We have decided to not support custom deserializers for user defined events in EventGridDeserializer for simplicities sake at this time. * [EventGrid] Add MIGRATION.md Fixes #12367 * [EventGrid] Fix linting issues
This commit is contained in:
Родитель
a58d0641d7
Коммит
b6040c5451
|
@ -1,5 +1,14 @@
|
|||
# Release History
|
||||
|
||||
## 3.0.0-beta.4 (Unreleased)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- `EventGridSharedAccessCredential` has been removed, in favor of `AzureSASCredential`. Code which is using `EventGridSharedAccessCredential` should
|
||||
now use `AzureSASCredential` instead.
|
||||
- When constructing the client, you must now include the schema type your topic is configured to expect (one of "EventGrid", "CloudEvent" or "Custom").
|
||||
- The `sendEvents` methods have been collapsed into a single method on the client called `send` which uses the input schema that was configured on the client.
|
||||
|
||||
## 3.0.0-beta.3 (2020-10-06)
|
||||
|
||||
- Added distributed tracing support. `EventGridProducerClient` will now create spans when sending events to Event Grid.
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
# Guide for migrating to `@azure/eventgrid@3` from `@azure/eventgrid@2`
|
||||
|
||||
This guide is intended to assist in the migration to `@azure/eventgrid@3` from `@azure/eventgrid@2`. It will focus on side-by-side comparisons for similar operations between the two packages.
|
||||
|
||||
We assume that you are familiar with `@azure/eventgrid@2`. If not, please refer to the [README for name of new package here](add link to new package readme) rather than this guide.
|
||||
|
||||
## Table of contents
|
||||
|
||||
## Migration benefits
|
||||
|
||||
As Azure has matured and been embraced by a more diverse group of developers, we have been focused on learning the patterns and practices to best support developer productivity and to understand the gaps that the JavaScript client libraries have.
|
||||
|
||||
There were several areas of consistent feedback expressed across the Azure client library ecosystem. One of the most important is that the client libraries for different Azure services have not had a consistent approach to organization, naming, and API structure. Additionally, many developers have felt that the learning curve was difficult, and the APIs did not offer a good, approachable, and consistent onboarding story for those learning Azure or exploring a specific Azure service.
|
||||
|
||||
To improve the development experience across Azure services, a set of uniform [design guidelines](https://azure.github.io/azure-sdk/general_introduction.html) was created for all languages to drive a consistent experience with established API patterns for all services. A set of [JavaScript](https://azure.github.io/azure-sdk/typescript_introduction.html) was also introduced to ensure that JavaScript clients have a natural and idiomatic feel with respect to the JavaScript ecosystem. Version 3 of `@azure/eventgrid` follows these guidelines.
|
||||
|
||||
### Cross Service SDK improvements
|
||||
|
||||
The modern JavaScript client library also provides the ability to share in some of the cross-service improvements made to the Azure development experience, such as
|
||||
|
||||
- Using the new `@azure/identity` library to share a single authentication approach between clients
|
||||
- A unified logging and diagnostics pipeline offering a common view of the activities across each of the client libraries
|
||||
- Use of promises rather than callbacks for a simplified programming experience
|
||||
- Use of async iterators in paging APIs
|
||||
|
||||
### New features
|
||||
|
||||
In addition to the cross service improvements, Version 3 of `@azure/eventgrid` has a few new features specific to Event Grid:
|
||||
|
||||
- Support for publishing events using the [CloudEvent](https://cloudevents.io) format to topics which are configured to use the CloudEvent V1 schema.
|
||||
- A new helper which can be used to construct shared access signatures which can be used to provide time based access to publishing to an Event Grid topic.
|
||||
- Support for authenticating using a shared access signature.
|
||||
- A new `EventGridDeserializer` type which can be used to deserialize events which have been delivered Event Grid service and TypeScript type defintions for events from services in Azure.
|
||||
|
||||
## Important changes
|
||||
|
||||
### Constructing the Client and Publishing Events
|
||||
|
||||
As part of adopting the design guidelines, constructing a client is now slightly different. Before, you simply pass a `TopicCredentials` or `DomainCredentials` instance from `ms-rest-js` when constructing the client. Now we require that you also provide the URL of the endpoint (as displayed in the Azure console) in addition to the credentials. This is done so that you don't need to pass the endpoint on every call when publishing an event. Since the new version of the SDK supports multiple schemas, you now provide the schema you are using when constructing the client. We have also adopted the use `AzureKeyCredential` and use this regardless of if you are publishing to a Event Grid Topic or an Event Grid Domain. Finally, the client has been renamed to `EventGridPublisherClient` from `EventGridClient` to make it clearer that it's use is just for publishing events.
|
||||
|
||||
For example, in V2 of the library, here's how you'd authenticate to the service and publish an event:
|
||||
|
||||
```js
|
||||
const { EventGridClient } = require("@azure/eventgrid");
|
||||
const { TopicCredentials } = require("@azure/ms-rest-js");
|
||||
const { v4: uuidv4 } = require("uuid");
|
||||
|
||||
const client = new EventGridClient(new TopicCredentials("<your-topic-key>"));
|
||||
|
||||
client.publishEvents("<your-topic-host-name-here>", [
|
||||
{
|
||||
id: uuid(),
|
||||
subject: "TestSubject",
|
||||
dataVersion: "1.0",
|
||||
eventType: "Microsoft.MockPublisher.TestEvent",
|
||||
eventTime: new Date(),
|
||||
data: {
|
||||
field1: "value1",
|
||||
filed2: "value2"
|
||||
}
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
And in V3, you would instead do this:
|
||||
|
||||
```js
|
||||
const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
|
||||
|
||||
const client = new EventGridPublisherClient(
|
||||
"<your-topic-host-name-here>",
|
||||
"EventGrid",
|
||||
new AzureKeyCredential("<your-topic-key>")
|
||||
);
|
||||
|
||||
client.send([
|
||||
{
|
||||
subject: "TestSubject",
|
||||
dataVersion: "1.0",
|
||||
eventType: "Microsoft.MockPublisher.TestEvent",
|
||||
data: {
|
||||
field1: "value1",
|
||||
filed2: "value2"
|
||||
}
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
Note that the `id` and `eventTime` properties are no longer required, they default to a new random UUID and the current time. Also, we've changed the method name from `publishEvents` to just `send`.
|
||||
|
||||
## Additional samples
|
||||
|
||||
More examples can be found at [Samples for add @azure/eventgrid](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/eventgrid/eventgrid/samples)
|
|
@ -75,22 +75,24 @@ Once you have an API key and endpoint, you can use the `AzureKeyCredential` clas
|
|||
```js
|
||||
const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
|
||||
|
||||
const client = new EventGridPublisherClient("<endpoint>", new AzureKeyCredential("<Access Key>"));
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"<endpoint schema>",
|
||||
new AzureKeyCredential("<Access Key>")
|
||||
);
|
||||
```
|
||||
|
||||
#### Using a SAS Token
|
||||
|
||||
Like an access key, a SAS token allows access to sending events to an Event Grid topic. Unlike an access key, which can be used until it is regenerated, a SAS token has an experation time, at which point it is no longer valid. To use a SAS token for authentication, use the `EventGridSharedAccesSignatureCredential` as follows:
|
||||
Like an access key, a SAS token allows access to sending events to an Event Grid topic. Unlike an access key, which can be used until it is regenerated, a SAS token has an experation time, at which point it is no longer valid. To use a SAS token for authentication, use the `AzureSASCredential` as follows:
|
||||
|
||||
```js
|
||||
const {
|
||||
EventGridPublisherClient,
|
||||
EventGridSharedAccessSignatureCredential
|
||||
} = require("@azure/eventgrid");
|
||||
const { EventGridPublisherClient, AzureSASCredential } = require("@azure/eventgrid");
|
||||
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
new EventGridSharedAccessSignatureCredential("<SAS Token>")
|
||||
"<endpoint schema>",
|
||||
new AzureSASCredential("<SAS Token>")
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -115,39 +117,73 @@ const token = generateSharedAccessSignature(
|
|||
|
||||
### Event Schemas
|
||||
|
||||
Event Grid supports multiple schemas for encoding events. When a Custom Topic or Domain is created, you specify the schema that will be used when publishing events. While you may configure your topic to use a _custom schema_ it is more common to use the already defined _Event Grid schema_ or _CloudEvents 1.0 schema_. [CloudEvents](https://cloudevents.io/) is a Cloud Native Computing Foundation project which produces a specification for describing event data in a common way. Regardless of what schmea your topic or domain is configured to use, `EventGridPublisherClient` will be used to publish events to it. However, you must use the correct method for publishing:
|
||||
Event Grid supports multiple schemas for encoding events. When a Custom Topic or Domain is created, you specify the schema that will be used when publishing events. While you may configure your topic to use a _custom schema_ it is more common to use the already defined _Event Grid schema_ or _CloudEvents 1.0 schema_. [CloudEvents](https://cloudevents.io/) is a Cloud Native Computing Foundation project which produces a specification for describing event data in a common way. When you construct the EventGridPublisherClient you must specify which schema your topic is configured to use:
|
||||
|
||||
| Schema | Publishing Method |
|
||||
| ------------ | --------------------- |
|
||||
| Event Grid | `publishEvents` |
|
||||
| Cloud Events | `publishCloudEvents` |
|
||||
| Custom | `publishCustomEvents` |
|
||||
If your topic is configured to use the Event Grid Schema, set "EventGrid" as the schema type:
|
||||
|
||||
Using the wrong method will result in an error from the service and your events will not be published.
|
||||
```js
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"EventGrid",
|
||||
new AzureKeyCredential("<API Key>")
|
||||
);
|
||||
```
|
||||
|
||||
### EventGridConsumer
|
||||
If your topic is configured to use the Cloud Event Schema, set "CloudEvent" as the schema type:
|
||||
|
||||
Events delivered to consumers by Event Grid are delivered as JSON. Depending on the type of consumer being delivered to, the Event Grid service may deliver one or more events as part of a single payload. While these events may be deserialized using normal JavaScript methods like `JSON.parse`, this library offers a helper type for deserializing events, called `EventGridConsumer`.
|
||||
```js
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"CloudEvent",
|
||||
new AzureKeyCredential("<API Key>")
|
||||
);
|
||||
```
|
||||
|
||||
Compared with using `JSON.parse` directly, `EventGridConsumer` does some additional conversions while deserializng events:
|
||||
If your topic is configured to use a Custom Event Schema, set "Custom" as the schema type:
|
||||
|
||||
1. `EventGridConsumer` validates that the required properties of an event are present and are the right types.
|
||||
2. `EventGridConsumer` converts the event time property into a JavaScript `Date` object.
|
||||
3. When using Cloud Events, binary data may be used for an event's data property (by using `Uint8Array`). When the event is sent through Event Grid, it is encoded in Base 64. `EventGridConsumer` will decode this data back into an instance of `Uint8Array`.
|
||||
4. When deserilizing a _System Event_ (an event generated by another Azure service), `EventGridConsumer` will do additional conversions so that the `data` object matches the corresponding interface which describes its data. When using TypeScript, these interfaces ensure you have strong typing when access properties of the data object for a system event.
|
||||
```js
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"Custom",
|
||||
new AzureKeyCredential("<API Key>")
|
||||
);
|
||||
```
|
||||
|
||||
When creating an instance of `EventGridConsumer` you may supply custom deserializers that are used to further convert the `data` object.
|
||||
Constructing the client with a different schema than what the topic is configured to expect will result in an error from the service and your events will not be published.
|
||||
|
||||
You can see what input schema has been configured for an Event Grid topic by using the [Azure CLI][azure_cli] snippet below:
|
||||
|
||||
```bash
|
||||
az eventgrid topic show --name <your-resource-name> --resource-group <your-resource-group-name> --query "inputSchema"
|
||||
```
|
||||
|
||||
### EventGridDeserializer
|
||||
|
||||
Events delivered to consumers by Event Grid are delivered as JSON. Depending on the type of consumer being delivered to, the Event Grid service may deliver one or more events as part of a single payload. While these events may be deserialized using normal JavaScript methods like `JSON.parse`, this library offers a helper type for deserializing events, called `EventGridDeserializer`.
|
||||
|
||||
Compared with using `JSON.parse` directly, `EventGridDeserializer` does some additional conversions while deserializng events:
|
||||
|
||||
1. `EventGridDeserializer` validates that the required properties of an event are present and are the right types.
|
||||
2. `EventGridDeserializer` converts the event time property into a JavaScript `Date` object.
|
||||
3. When using Cloud Events, binary data may be used for an event's data property (by using `Uint8Array`). When the event is sent through Event Grid, it is encoded in Base 64. `EventGridDeserializer` will decode this data back into an instance of `Uint8Array`.
|
||||
4. When deserilizing a _System Event_ (an event generated by another Azure service), `EventGridDeserializer` will do additional conversions so that the `data` object matches the corresponding interface which describes its data. When using TypeScript, these interfaces ensure you have strong typing when access properties of the data object for a system event.
|
||||
|
||||
When creating an instance of `EventGridDeserializer` you may supply custom deserializers that are used to further convert the `data` object.
|
||||
|
||||
## Examples
|
||||
|
||||
### Publish a Custom Event to an Event Grid Topic
|
||||
### Publish a Custom Event to an Event Grid Topic using the Event Grid Schema
|
||||
|
||||
```js
|
||||
const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
|
||||
|
||||
const client = new EventGridPublisherClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"EventGrid",
|
||||
new AzureKeyCredential("<API key>")
|
||||
);
|
||||
|
||||
await client.sendEvents([
|
||||
await client.send([
|
||||
{
|
||||
eventType: "Azure.Sdk.SampleEvent",
|
||||
subject: "Event Subject",
|
||||
|
@ -159,16 +195,20 @@ await client.sendEvents([
|
|||
]);
|
||||
```
|
||||
|
||||
### Publish a Custom Event to a Topic in an Event Grid Domain
|
||||
### Publish a Custom Event to a Topic in an Event Grid Domain using the Event Grid Schema
|
||||
|
||||
Publishing events to an Event Grid Domain is similar to publish to an Event Grid Topic, except that when using the Event Grid schema for events, you must include the `topic` property. When publishing events in the Cloud Events 1.0 schema, the required `source` property is used as the name of the topic in the domain to publish to:
|
||||
|
||||
```js
|
||||
const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
|
||||
|
||||
const client = new EventGridPublisherClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
||||
const client = new EventGridPublisherClient(
|
||||
"<endpoint>",
|
||||
"EventGrid",
|
||||
new AzureKeyCredential("<API key>")
|
||||
);
|
||||
|
||||
await client.sendEvents([
|
||||
await client.send([
|
||||
{
|
||||
topic: "my-sample-topic",
|
||||
eventType: "Azure.Sdk.SampleEvent",
|
||||
|
@ -183,18 +223,18 @@ await client.sendEvents([
|
|||
|
||||
### Deserializing an Event
|
||||
|
||||
`EventGridConsumer` can be used to deserialize events delivered by Event Grid. When deserializing an event, you need to know the schema used to deliver the event. In this example we have events being delivered to an Azure Service Bus Topic in the Cloud Events schema. Using the Service Bus SDK we can recieve these events from the Service Bus Topic and then deserialize them using `EventGridConsumer` and use `isSystemEvent` to detect what type of events they are.
|
||||
`EventGridDeserializer` can be used to deserialize events delivered by Event Grid. When deserializing an event, you need to know the schema used to deliver the event. In this example we have events being delivered to an Azure Service Bus Topic in the Cloud Events schema. Using the Service Bus SDK we can recieve these events from the Service Bus Topic and then deserialize them using `EventGridDeserializer` and use `isSystemEvent` to detect what type of events they are.
|
||||
|
||||
```js
|
||||
const { ServiceBusClient } = require("@azure/service-bus");
|
||||
const { DefaultAzureCredential } = require("@azure/identity");
|
||||
const { EventGridConsumer, isSystemEvent } = require("@azure/eventgrid");
|
||||
const { EventGridDeserializer, isSystemEvent } = require("@azure/eventgrid");
|
||||
|
||||
const client = new ServiceBusClient("<service bus hostname>", new DefaultAzureCredential());
|
||||
|
||||
const receiver = client.createReceiver("<queue name>", "peekLock");
|
||||
|
||||
const consumer = new EventGridConsumer();
|
||||
const consumer = new EventGridDeserializer();
|
||||
|
||||
async function processMessage(message) {
|
||||
// When delivering to a Service Bus Queue or Topic, EventGrid delivers a single event per message.
|
||||
|
|
|
@ -6,27 +6,27 @@
|
|||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"cloudTracingEventId161168561609301106\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-01-26T18:26:56.093Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Single with Trace Parent\",\"traceparent\":\"00-1-3-00\"}]",
|
||||
"requestBody": "[{\"id\":\"cloudTracingEventId161257785618904908\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-02-06T02:17:36.189Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Single with Trace Parent\",\"traceparent\":\"00-1-3-00\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "d942cfd6-ecea-42fa-8b9f-1bb6f902807f"
|
||||
"x-ms-request-id": "7421854e-8e9b-4745-ad28-c2d56d492c2b"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"cloudTracingEventId": "cloudTracingEventId161168561609301106"
|
||||
"cloudTracingEventId": "cloudTracingEventId161257785618904908"
|
||||
},
|
||||
"newDate": {
|
||||
"cloudTracingEventDate": "2021-01-26T18:26:56.093Z"
|
||||
"cloudTracingEventDate": "2021-02-06T02:17:36.189Z"
|
||||
}
|
||||
},
|
||||
"hash": "a86111d1b0f8c543eaae49983af5c18d"
|
||||
"hash": "badb37befcede87aad3e487a7d3c68e3"
|
||||
}
|
|
@ -6,27 +6,27 @@
|
|||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"cloudSingleEventId161168561586109228\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-01-26T18:26:55.861Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\"}]",
|
||||
"requestBody": "[{\"id\":\"cloudSingleEventId161257785614303808\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-02-06T02:17:36.143Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "c205280c-2772-4cd9-ac3d-5081a149b607"
|
||||
"x-ms-request-id": "ebdeacef-2d53-43e9-873f-229eb0abf882"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"cloudSingleEventId": "cloudSingleEventId161168561586109228"
|
||||
"cloudSingleEventId": "cloudSingleEventId161257785614303808"
|
||||
},
|
||||
"newDate": {
|
||||
"cloudSingleEventDate": "2021-01-26T18:26:55.861Z"
|
||||
"cloudSingleEventDate": "2021-02-06T02:17:36.143Z"
|
||||
}
|
||||
},
|
||||
"hash": "e9ae659c7a27be413640b9855586a0a7"
|
||||
"hash": "98e0134edb40e57d58fb3287a7b625d9"
|
||||
}
|
|
@ -6,29 +6,29 @@
|
|||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"cloudMultiEventId1161168561604100322\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-01-26T18:26:56.041Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Multiple 1\"},{\"id\":\"cloudMultiEventId2161168561604104763\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-01-26T18:26:56.041Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Multiple 2\"}]",
|
||||
"requestBody": "[{\"id\":\"cloudMultiEventId1161257785616809034\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-02-06T02:17:36.168Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Multiple 1\"},{\"id\":\"cloudMultiEventId2161257785616804005\",\"source\":\"/earth/unitedstates/washington/kirkland/finnhill\",\"data\":{\"hello\":\"world\"},\"type\":\"Azure.Sdk.TestEvent1\",\"time\":\"2021-02-06T02:17:36.168Z\",\"specversion\":\"1.0\",\"datacontenttype\":\"application/json\",\"subject\":\"Multiple 2\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "00ab6c21-ca97-4e37-b865-cc970a56150b"
|
||||
"x-ms-request-id": "798e1ee8-add7-4307-a19c-9f4a97003eef"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"cloudMultiEventId1": "cloudMultiEventId1161168561604100322",
|
||||
"cloudMultiEventId2": "cloudMultiEventId2161168561604104763"
|
||||
"cloudMultiEventId1": "cloudMultiEventId1161257785616809034",
|
||||
"cloudMultiEventId2": "cloudMultiEventId2161257785616804005"
|
||||
},
|
||||
"newDate": {
|
||||
"cloudMultiEventDate1": "2021-01-26T18:26:56.041Z",
|
||||
"cloudMultiEventDate2": "2021-01-26T18:26:56.041Z"
|
||||
"cloudMultiEventDate1": "2021-02-06T02:17:36.168Z",
|
||||
"cloudMultiEventDate2": "2021-02-06T02:17:36.168Z"
|
||||
}
|
||||
},
|
||||
"hash": "90f3347253c0ab36ce2f8788c29f14cf"
|
||||
"hash": "9dde032b79c3bd3d0dd5310f9c67e077"
|
||||
}
|
|
@ -12,11 +12,11 @@
|
|||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "f7b74313-5d60-4ef4-8e96-d578057a083d"
|
||||
"x-ms-request-id": "c11e5eb4-2e64-4504-b83e-d69e222da1ed"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -24,5 +24,5 @@
|
|||
"uniqueName": {},
|
||||
"newDate": {}
|
||||
},
|
||||
"hash": "2bf0e079ba8b532c1cef46c3458d62fb"
|
||||
"hash": "e4745a3421c2bc5a53372fc7006cfcf6"
|
||||
}
|
|
@ -12,11 +12,11 @@
|
|||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "68d97039-694e-4fa4-a79e-c44ca2a546c9"
|
||||
"x-ms-request-id": "86d01155-87fc-4548-9ab8-7882652de8bf"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -24,5 +24,5 @@
|
|||
"uniqueName": {},
|
||||
"newDate": {}
|
||||
},
|
||||
"hash": "addc857213f6786f86c3555fbe3a8b27"
|
||||
"hash": "117ce48d2ad30cfcccd86bd02fc4a692"
|
||||
}
|
|
@ -6,27 +6,27 @@
|
|||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"singleEventId161168561545607277\",\"subject\":\"Single 1\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-01-26T18:26:55.456Z\",\"dataVersion\":\"1.0\"}]",
|
||||
"requestBody": "[{\"id\":\"singleEventId161257785600109818\",\"subject\":\"Single 1\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-02-06T02:17:36.000Z\",\"dataVersion\":\"1.0\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"date": "Sat, 06 Feb 2021 02:17:35 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "94489308-b9e5-4aaa-92db-2cf37a107347"
|
||||
"x-ms-request-id": "ae45c3cc-4020-42f1-be25-207177b27947"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"singleEventId": "singleEventId161168561545607277"
|
||||
"singleEventId": "singleEventId161257785600109818"
|
||||
},
|
||||
"newDate": {
|
||||
"singleEventDate": "2021-01-26T18:26:55.456Z"
|
||||
"singleEventDate": "2021-02-06T02:17:36.000Z"
|
||||
}
|
||||
},
|
||||
"hash": "85c2b7be05b423dcdac7d9214a5cf0cd"
|
||||
"hash": "befd99472d8ea78a2a06de25d27db946"
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"recordings": [
|
||||
{
|
||||
"method": "POST",
|
||||
"url": "https://endpoint/api/events",
|
||||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"multiEventId1161257785612004088\",\"subject\":\"Multiple 1\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-02-06T02:17:36.120Z\",\"dataVersion\":\"1.0\"},{\"id\":\"multiEventId2161257785612000099\",\"subject\":\"Multiple 2\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-02-06T02:17:36.120Z\",\"dataVersion\":\"1.0\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Sat, 06 Feb 2021 02:17:36 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "a674c6ec-5207-4f35-8691-143279514f39"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"multiEventId1": "multiEventId1161257785612004088",
|
||||
"multiEventId2": "multiEventId2161257785612000099"
|
||||
},
|
||||
"newDate": {
|
||||
"multiEventDate1": "2021-02-06T02:17:36.120Z",
|
||||
"multiEventDate2": "2021-02-06T02:17:36.120Z"
|
||||
}
|
||||
},
|
||||
"hash": "097619df99c851c57b3eb6f87bdb8ee2"
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"recordings": [
|
||||
{
|
||||
"method": "POST",
|
||||
"url": "https://endpoint/api/events",
|
||||
"query": {
|
||||
"api-version": "2018-01-01"
|
||||
},
|
||||
"requestBody": "[{\"id\":\"multiEventId1161168561578108616\",\"subject\":\"Multiple 1\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-01-26T18:26:55.781Z\",\"dataVersion\":\"1.0\"},{\"id\":\"multiEventId2161168561578101127\",\"subject\":\"Multiple 2\",\"data\":{\"hello\":\"world\"},\"eventType\":\"Azure.Sdk.TestEvent1\",\"eventTime\":\"2021-01-26T18:26:55.781Z\",\"dataVersion\":\"1.0\"}]",
|
||||
"status": 200,
|
||||
"response": "",
|
||||
"responseHeaders": {
|
||||
"api-supported-versions": "2018-01-01",
|
||||
"content-length": "0",
|
||||
"date": "Tue, 26 Jan 2021 18:26:57 GMT",
|
||||
"server": "Microsoft-HTTPAPI/2.0",
|
||||
"status": "200",
|
||||
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
||||
"x-ms-request-id": "67f3db14-1f7d-4423-99ad-b5ab1f0824f0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniqueTestInfo": {
|
||||
"uniqueName": {
|
||||
"multiEventId1": "multiEventId1161168561578108616",
|
||||
"multiEventId2": "multiEventId2161168561578101127"
|
||||
},
|
||||
"newDate": {
|
||||
"multiEventDate1": "2021-01-26T18:26:55.781Z",
|
||||
"multiEventDate2": "2021-01-26T18:26:55.781Z"
|
||||
}
|
||||
},
|
||||
"hash": "674c21f74c191eb62010e1f031a67e59"
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "357bb46a327afd892edc5a89b1d5c4c3";
|
||||
module.exports.hash = "646c836f51adf53e50b18e93588af60e";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"cloudTracingEventId":"cloudTracingEventId161168561052005009"},"newDate":{"cloudTracingEventDate":"2021-01-26T18:26:50.520Z"}}
|
||||
module.exports.testInfo = {"uniqueName":{"cloudTracingEventId":"cloudTracingEventId161257785276403674"},"newDate":{"cloudTracingEventDate":"2021-02-06T02:17:32.764Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"cloudTracingEventId161168561052005009","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-01-26T18:26:50.520Z","specversion":"1.0","datacontenttype":"application/json","subject":"Single with Trace Parent","traceparent":"00-1-3-00"}])
|
||||
.post('/api/events', [{"id":"cloudTracingEventId161257785276403674","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-02-06T02:17:32.764Z","specversion":"1.0","datacontenttype":"application/json","subject":"Single with Trace Parent","traceparent":"00-1-3-00"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
|
@ -17,7 +17,7 @@ nock('https://endpoint', {"encodedQueryParams":true})
|
|||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'cd6b4b67-a45b-4f2e-9864-a4e5c29d0172',
|
||||
'6adfc374-ded1-46aa-bef9-ba1d8ae660de',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:51 GMT'
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
|
@ -1,11 +1,11 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "f54a8b7d13e4ae34fadeb0393c88eaf4";
|
||||
module.exports.hash = "79c11782e3933cddd2d23967ce582347";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"cloudSingleEventId":"cloudSingleEventId161168561021500558"},"newDate":{"cloudSingleEventDate":"2021-01-26T18:26:50.215Z"}}
|
||||
module.exports.testInfo = {"uniqueName":{"cloudSingleEventId":"cloudSingleEventId161257785260900910"},"newDate":{"cloudSingleEventDate":"2021-02-06T02:17:32.609Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"cloudSingleEventId161168561021500558","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-01-26T18:26:50.215Z","specversion":"1.0","datacontenttype":"application/json"}])
|
||||
.post('/api/events', [{"id":"cloudSingleEventId161257785260900910","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-02-06T02:17:32.609Z","specversion":"1.0","datacontenttype":"application/json"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
|
@ -17,7 +17,7 @@ nock('https://endpoint', {"encodedQueryParams":true})
|
|||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'd5f15325-e97d-4a27-ab57-531dd130301b',
|
||||
'233dfcef-b8c8-4200-aed7-b3e62e05ce18',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:51 GMT'
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
23
sdk/eventgrid/eventgrid/recordings/node/eventgridpublisherclient_send_cloudevent_schema/recording_sends_multiple_events.js
сгенерированный
Normal file
23
sdk/eventgrid/eventgrid/recordings/node/eventgridpublisherclient_send_cloudevent_schema/recording_sends_multiple_events.js
сгенерированный
Normal file
|
@ -0,0 +1,23 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "270107bc3f163d9770cce18126db6e06";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"cloudMultiEventId1":"cloudMultiEventId1161257785274707186","cloudMultiEventId2":"cloudMultiEventId2161257785274703951"},"newDate":{"cloudMultiEventDate1":"2021-02-06T02:17:32.747Z","cloudMultiEventDate2":"2021-02-06T02:17:32.747Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"cloudMultiEventId1161257785274707186","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-02-06T02:17:32.747Z","specversion":"1.0","datacontenttype":"application/json","subject":"Multiple 1"},{"id":"cloudMultiEventId2161257785274703951","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-02-06T02:17:32.747Z","specversion":"1.0","datacontenttype":"application/json","subject":"Multiple 2"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
'0',
|
||||
'Server',
|
||||
'Microsoft-HTTPAPI/2.0',
|
||||
'Strict-Transport-Security',
|
||||
'max-age=31536000; includeSubDomains',
|
||||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'4434f3a2-1c00-420c-bb19-05610c23d0b3',
|
||||
'Date',
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
|
@ -1,6 +1,6 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "6a0323357c112a7fee98ad57d952016e";
|
||||
module.exports.hash = "de073b9387d2406ec308746cbd8ac2a9";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{},"newDate":{}}
|
||||
|
||||
|
@ -17,7 +17,7 @@ nock('https://endpoint', {"encodedQueryParams":true})
|
|||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'9cfbebf2-66c8-48c0-b9b5-deecf52b8dbc',
|
||||
'0e0f76b0-0b18-49a8-9203-bc465960fb83',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:51 GMT'
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
|
@ -1,6 +1,6 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "f4fce400dc651a8acd221ee29b4512ca";
|
||||
module.exports.hash = "5737d9510585b0f121c55d53885b8065";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{},"newDate":{}}
|
||||
|
||||
|
@ -17,7 +17,7 @@ nock('https://endpoint', {"encodedQueryParams":true})
|
|||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'43d477f7-32cd-4b33-8d4d-d0a9b85139d7',
|
||||
'47d57b4f-7f51-47c4-9c89-e21bb4ac9c13',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:51 GMT'
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
|
@ -1,11 +1,11 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "d3836591952c853e63413c6baee86b80";
|
||||
module.exports.hash = "64a276f1f34993ad88cd6f44427e5277";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"singleEventId":"singleEventId161168560981909647"},"newDate":{"singleEventDate":"2021-01-26T18:26:49.819Z"}}
|
||||
module.exports.testInfo = {"uniqueName":{"singleEventId":"singleEventId161257785249607296"},"newDate":{"singleEventDate":"2021-02-06T02:17:32.496Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"singleEventId161168560981909647","subject":"Single 1","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-01-26T18:26:49.819Z","dataVersion":"1.0"}])
|
||||
.post('/api/events', [{"id":"singleEventId161257785249607296","subject":"Single 1","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-02-06T02:17:32.496Z","dataVersion":"1.0"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
|
@ -17,7 +17,7 @@ nock('https://endpoint', {"encodedQueryParams":true})
|
|||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'e0334842-8c3c-4fe1-bc7d-6a97ae11ccb1',
|
||||
'ba6086a7-6b1d-43c4-ab0a-aeb2f4e95eb4',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:50 GMT'
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
23
sdk/eventgrid/eventgrid/recordings/node/eventgridpublisherclient_send_eventgrid_schema/recording_sends_multiple_events.js
сгенерированный
Normal file
23
sdk/eventgrid/eventgrid/recordings/node/eventgridpublisherclient_send_eventgrid_schema/recording_sends_multiple_events.js
сгенерированный
Normal file
|
@ -0,0 +1,23 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "ad571fe06ccea51458a22486b720e15a";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"multiEventId1":"multiEventId1161257785259006866","multiEventId2":"multiEventId2161257785259003349"},"newDate":{"multiEventDate1":"2021-02-06T02:17:32.590Z","multiEventDate2":"2021-02-06T02:17:32.590Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"multiEventId1161257785259006866","subject":"Multiple 1","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-02-06T02:17:32.590Z","dataVersion":"1.0"},{"id":"multiEventId2161257785259003349","subject":"Multiple 2","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-02-06T02:17:32.590Z","dataVersion":"1.0"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
'0',
|
||||
'Server',
|
||||
'Microsoft-HTTPAPI/2.0',
|
||||
'Strict-Transport-Security',
|
||||
'max-age=31536000; includeSubDomains',
|
||||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'2d51c28d-48e0-499d-ac7d-54f569537f73',
|
||||
'Date',
|
||||
'Sat, 06 Feb 2021 02:17:32 GMT'
|
||||
]);
|
|
@ -1,23 +0,0 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "f6fe3d52d717fd3630ba906ade952f7b";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"cloudMultiEventId1":"cloudMultiEventId1161168561047203144","cloudMultiEventId2":"cloudMultiEventId2161168561047204678"},"newDate":{"cloudMultiEventDate1":"2021-01-26T18:26:50.472Z","cloudMultiEventDate2":"2021-01-26T18:26:50.472Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"cloudMultiEventId1161168561047203144","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-01-26T18:26:50.472Z","specversion":"1.0","datacontenttype":"application/json","subject":"Multiple 1"},{"id":"cloudMultiEventId2161168561047204678","source":"/earth/unitedstates/washington/kirkland/finnhill","data":{"hello":"world"},"type":"Azure.Sdk.TestEvent1","time":"2021-01-26T18:26:50.472Z","specversion":"1.0","datacontenttype":"application/json","subject":"Multiple 2"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
'0',
|
||||
'Server',
|
||||
'Microsoft-HTTPAPI/2.0',
|
||||
'Strict-Transport-Security',
|
||||
'max-age=31536000; includeSubDomains',
|
||||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'fae08b75-3f7b-4cff-86f5-d77b1ffe4763',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:51 GMT'
|
||||
]);
|
|
@ -1,23 +0,0 @@
|
|||
let nock = require('nock');
|
||||
|
||||
module.exports.hash = "fdc26a5ca6514dd6a88d88a54394469a";
|
||||
|
||||
module.exports.testInfo = {"uniqueName":{"multiEventId1":"multiEventId1161168561017305186","multiEventId2":"multiEventId2161168561017304614"},"newDate":{"multiEventDate1":"2021-01-26T18:26:50.173Z","multiEventDate2":"2021-01-26T18:26:50.173Z"}}
|
||||
|
||||
nock('https://endpoint', {"encodedQueryParams":true})
|
||||
.post('/api/events', [{"id":"multiEventId1161168561017305186","subject":"Multiple 1","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-01-26T18:26:50.173Z","dataVersion":"1.0"},{"id":"multiEventId2161168561017304614","subject":"Multiple 2","data":{"hello":"world"},"eventType":"Azure.Sdk.TestEvent1","eventTime":"2021-01-26T18:26:50.173Z","dataVersion":"1.0"}])
|
||||
.query(true)
|
||||
.reply(200, "", [
|
||||
'Content-Length',
|
||||
'0',
|
||||
'Server',
|
||||
'Microsoft-HTTPAPI/2.0',
|
||||
'Strict-Transport-Security',
|
||||
'max-age=31536000; includeSubDomains',
|
||||
'api-supported-versions',
|
||||
'2018-01-01',
|
||||
'x-ms-request-id',
|
||||
'50d8a8ab-5c25-464d-b244-48eaa0115199',
|
||||
'Date',
|
||||
'Tue, 26 Jan 2021 18:26:50 GMT'
|
||||
]);
|
|
@ -5,9 +5,11 @@
|
|||
```ts
|
||||
|
||||
import { AzureKeyCredential } from '@azure/core-auth';
|
||||
import { AzureSASCredential } from '@azure/core-auth';
|
||||
import { KeyCredential } from '@azure/core-auth';
|
||||
import { OperationOptions } from '@azure/core-client';
|
||||
import { PipelineOptions } from '@azure/core-https';
|
||||
import { SASCredential } from '@azure/core-auth';
|
||||
|
||||
// @public
|
||||
export interface ACSChatEventBase {
|
||||
|
@ -159,6 +161,8 @@ export type AsyncStatus = string;
|
|||
|
||||
export { AzureKeyCredential }
|
||||
|
||||
export { AzureSASCredential }
|
||||
|
||||
// @public
|
||||
export interface CloudEvent<T> {
|
||||
data?: T;
|
||||
|
@ -245,9 +249,6 @@ export type ContainerRegistryImageDeletedEventData = ContainerRegistryEventData
|
|||
// @public
|
||||
export type ContainerRegistryImagePushedEventData = ContainerRegistryEventData & {};
|
||||
|
||||
// @public
|
||||
export type CustomEventDataDeserializer = (o: any) => Promise<any>;
|
||||
|
||||
// @public
|
||||
export interface DeviceConnectionStateEventInfo {
|
||||
sequenceNumber?: string;
|
||||
|
@ -318,19 +319,11 @@ export interface DeviceTwinProperties {
|
|||
}
|
||||
|
||||
// @public
|
||||
export class EventGridConsumer {
|
||||
constructor(options?: EventGridConsumerOptions);
|
||||
// (undocumented)
|
||||
readonly customDeserializers: Record<string, CustomEventDataDeserializer>;
|
||||
export class EventGridDeserializer {
|
||||
deserializeCloudEvents(encodedEvents: string): Promise<CloudEvent<unknown>[]>;
|
||||
deserializeCloudEvents(encodedEvents: object): Promise<CloudEvent<unknown>[]>;
|
||||
deserializeCloudEvents(encodedEvents: Record<string, unknown>): Promise<CloudEvent<unknown>[]>;
|
||||
deserializeEventGridEvents(encodedEvents: string): Promise<EventGridEvent<unknown>[]>;
|
||||
deserializeEventGridEvents(encodedEvents: object): Promise<EventGridEvent<unknown>[]>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface EventGridConsumerOptions {
|
||||
customDeserializers: Record<string, CustomEventDataDeserializer>;
|
||||
deserializeEventGridEvents(encodedEvents: Record<string, unknown>): Promise<EventGridEvent<unknown>[]>;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -345,25 +338,16 @@ export interface EventGridEvent<T> {
|
|||
}
|
||||
|
||||
// @public
|
||||
export class EventGridPublisherClient {
|
||||
constructor(endpointUrl: string, credential: KeyCredential | SignatureCredential, options?: EventGridPublisherClientOptions);
|
||||
export class EventGridPublisherClient<T extends InputSchema> {
|
||||
constructor(endpointUrl: string, inputSchema: T, credential: KeyCredential | SASCredential, options?: EventGridPublisherClientOptions);
|
||||
readonly apiVersion: string;
|
||||
readonly endpointUrl: string;
|
||||
sendCloudEvents(events: SendCloudEventInput<any>[], options?: SendCloudEventsOptions): Promise<void>;
|
||||
sendCustomSchemaEvents(events: Record<string, any>[], options?: SendCustomSchemaEventsOptions): Promise<void>;
|
||||
sendEvents(events: SendEventGridEventInput<any>[], options?: SendEventsOptions): Promise<void>;
|
||||
send(events: InputSchemaToInputTypeMap[T][], options?: SendOptions): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type EventGridPublisherClientOptions = PipelineOptions;
|
||||
|
||||
// @public
|
||||
export class EventGridSharedAccessSignatureCredential implements SignatureCredential {
|
||||
constructor(signature: string);
|
||||
signature(): string;
|
||||
update(newSignature: string): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface EventHubCaptureFileCreatedEventData {
|
||||
eventCount?: number;
|
||||
|
@ -385,6 +369,16 @@ export interface GenerateSharedAccessSignatureOptions {
|
|||
apiVersion?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type InputSchema = keyof InputSchemaToInputTypeMap;
|
||||
|
||||
// @public
|
||||
export interface InputSchemaToInputTypeMap {
|
||||
CloudEvent: SendCloudEventInput<unknown>;
|
||||
Custom: Record<string, unknown>;
|
||||
EventGrid: SendEventGridEventInput<unknown>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type IotHubDeviceConnectedEventData = DeviceConnectionStateEventProperties & {};
|
||||
|
||||
|
@ -982,12 +976,6 @@ export interface SendCloudEventInput<T> {
|
|||
type: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type SendCloudEventsOptions = OperationOptions;
|
||||
|
||||
// @public
|
||||
export type SendCustomSchemaEventsOptions = OperationOptions;
|
||||
|
||||
// @public
|
||||
export interface SendEventGridEventInput<T> {
|
||||
data: T;
|
||||
|
@ -1000,7 +988,7 @@ export interface SendEventGridEventInput<T> {
|
|||
}
|
||||
|
||||
// @public
|
||||
export type SendEventsOptions = OperationOptions;
|
||||
export type SendOptions = OperationOptions;
|
||||
|
||||
// @public
|
||||
export interface ServiceBusActiveMessagesAvailableWithNoListenersEventData {
|
||||
|
@ -1022,11 +1010,6 @@ export interface ServiceBusDeadletterMessagesAvailableWithNoListenersEventData {
|
|||
topicName?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface SignatureCredential {
|
||||
signature(): string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type StampKind = string;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
const { EventGridConsumer, isSystemEvent } = require("@azure/eventgrid");
|
||||
const { EventGridDeserializer, isSystemEvent } = require("@azure/eventgrid");
|
||||
const { ServiceBusClient } = require("@azure/service-bus");
|
||||
const dotenv = require("dotenv");
|
||||
|
||||
|
@ -23,7 +23,7 @@ const receiver = new ServiceBusClient(serviceBusClientConnectionString).createRe
|
|||
);
|
||||
|
||||
// Create a Event Grid Consumer which will decode the payload of service bus message into an array of EventGridEvent objects.
|
||||
const consumer = new EventGridConsumer();
|
||||
const consumer = new EventGridDeserializer();
|
||||
|
||||
// The handler function which will be run on each message we remove from the Service Bus Queue.
|
||||
async function processMessage(message) {
|
||||
|
|
|
@ -16,11 +16,15 @@ const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";
|
|||
|
||||
async function main() {
|
||||
// Create the client used to publish events to the Event Grid Service
|
||||
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));
|
||||
const client = new EventGridPublisherClient(
|
||||
endpoint,
|
||||
"CloudEvent",
|
||||
new AzureKeyCredential(accessKey)
|
||||
);
|
||||
|
||||
// Send an event to the Event Grid Service, using the Cloud Event schema.
|
||||
// A random ID will be generated for this event, since one is not provided.
|
||||
await client.sendCloudEvents([
|
||||
await client.send([
|
||||
{
|
||||
type: "com.example.cloudevent",
|
||||
source: "/azure/sdk/eventgrid/samples/sendEventSample",
|
||||
|
|
|
@ -7,26 +7,30 @@ const dotenv = require("dotenv");
|
|||
// Load the .env file if it exists
|
||||
dotenv.config();
|
||||
|
||||
// The URL of the endpoint of the Event Grid topic.
|
||||
// The URL of the endpoint of the Event Grid topic.
|
||||
const endpoint = process.env["EVENT_GRID_ENDPOINT"] || "";
|
||||
|
||||
// You can find the access keys in the Azure portal.
|
||||
// Navigate to Settings > Access keys in your Event Grid topic's menu blade to see both access keys (you may use either).
|
||||
const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";
|
||||
|
||||
async function main() {
|
||||
async function main() {
|
||||
// Create the client used to publish events to the Event Grid Service
|
||||
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));
|
||||
const client = new EventGridPublisherClient(
|
||||
endpoint,
|
||||
"EventGrid",
|
||||
new AzureKeyCredential(accessKey)
|
||||
);
|
||||
|
||||
// Send an event to the Event Grid Service, using the Event Grid schema.
|
||||
// A random ID will be generated for this event, since one is not provided.
|
||||
await client.sendEvents([
|
||||
await client.send([
|
||||
{
|
||||
eventType: "Azure.SDK.Samples.CustomEvent",
|
||||
subject: "azure/sdk/eventgrid/samples/sendEventSample",
|
||||
dataVersion: "1.0",
|
||||
data: {
|
||||
message: "this is a sample event",
|
||||
message: "this is a sample event"
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { EventGridConsumer, isSystemEvent } from "@azure/eventgrid";
|
||||
import { EventGridDeserializer, isSystemEvent } from "@azure/eventgrid";
|
||||
import { ServiceBusClient, ServiceBusReceivedMessage } from "@azure/service-bus";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
|
@ -23,7 +23,7 @@ const receiver = new ServiceBusClient(serviceBusClientConnectionString).createRe
|
|||
);
|
||||
|
||||
// Create a Event Grid Consumer which will decode the payload of service bus message into an array of EventGridEvent objects.
|
||||
const consumer = new EventGridConsumer();
|
||||
const consumer = new EventGridDeserializer();
|
||||
|
||||
// The handler function which will be run on each message we remove from the Service Bus Queue.
|
||||
async function processMessage(message: ServiceBusReceivedMessage): Promise<void> {
|
||||
|
|
|
@ -16,11 +16,15 @@ const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";
|
|||
|
||||
export async function main(): Promise<void> {
|
||||
// Create the client used to publish events to the Event Grid Service
|
||||
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));
|
||||
const client = new EventGridPublisherClient(
|
||||
endpoint,
|
||||
"CloudEvent",
|
||||
new AzureKeyCredential(accessKey)
|
||||
);
|
||||
|
||||
// Send an event to the Event Grid Service, using the Cloud Event schema.
|
||||
// A random ID will be generated for this event, since one is not provided.
|
||||
await client.sendCloudEvents([
|
||||
await client.send([
|
||||
{
|
||||
type: "com.example.cloudevent",
|
||||
source: "/azure/sdk/eventgrid/samples/sendEventSample",
|
||||
|
|
|
@ -16,11 +16,15 @@ const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";
|
|||
|
||||
export async function main(): Promise<void> {
|
||||
// Create the client used to publish events to the Event Grid Service
|
||||
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));
|
||||
const client = new EventGridPublisherClient(
|
||||
endpoint,
|
||||
"EventGrid",
|
||||
new AzureKeyCredential(accessKey)
|
||||
);
|
||||
|
||||
// Send an event to the Event Grid Service, using the Event Grid schema.
|
||||
// A random ID will be generated for this event, since one is not provided.
|
||||
await client.sendEvents([
|
||||
await client.send([
|
||||
{
|
||||
eventType: "Azure.SDK.Samples.CustomEvent",
|
||||
subject: "azure/sdk/eventgrid/samples/sendEventSample",
|
||||
|
|
|
@ -3,12 +3,7 @@
|
|||
|
||||
import { createSerializer } from "@azure/core-client";
|
||||
import { CloudEvent as WireCloudEvent } from "./generated/models";
|
||||
import {
|
||||
CustomEventDataDeserializer,
|
||||
CloudEvent,
|
||||
EventGridEvent,
|
||||
cloudEventReservedPropertyNames
|
||||
} from "./models";
|
||||
import { CloudEvent, EventGridEvent, cloudEventReservedPropertyNames } from "./models";
|
||||
import {
|
||||
EventGridEvent as EventGridEventMapper,
|
||||
CloudEvent as CloudEventMapper
|
||||
|
@ -19,38 +14,18 @@ import { systemDeserializers } from "./systemEventDecoders";
|
|||
const serializer = createSerializer();
|
||||
|
||||
/**
|
||||
* Options for the Event Grid Consumer
|
||||
*/
|
||||
export interface EventGridConsumerOptions {
|
||||
/**
|
||||
* Custom deserializers to use when decoding a specific event's data, based on the type
|
||||
* field of the event.
|
||||
*/
|
||||
customDeserializers: Record<string, CustomEventDataDeserializer>;
|
||||
}
|
||||
|
||||
/**
|
||||
* EventGridConsumer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
|
||||
* EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
|
||||
* of either a single event or batch of events as well as be used to convert the result of `JSON.parse` into an
|
||||
* `EventGridEvent` or `CloudEvent` like object.
|
||||
*
|
||||
* Unlike normal JSON deseralization, EventGridConsumer does some additional conversions:
|
||||
* Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
|
||||
*
|
||||
* - The consumer parses the event time property into a `Date` object, for ease of use.
|
||||
* - When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded
|
||||
* and returned as an instance of the `Uint8Array` type.
|
||||
* - The `data` payload from system events is converted to match the interfaces this library defines.
|
||||
*
|
||||
* When constructing an `EventGridConsumer`, a map of event types to custom deserializers may be provided. When
|
||||
* deserializing, if a custom deserializer has been registered for a given event type, it will be called with the
|
||||
* data object. The object this deserializer returns will replace the existing data object.
|
||||
*/
|
||||
export class EventGridConsumer {
|
||||
readonly customDeserializers: Record<string, CustomEventDataDeserializer>;
|
||||
constructor(options?: EventGridConsumerOptions) {
|
||||
this.customDeserializers = options?.customDeserializers ?? {};
|
||||
}
|
||||
|
||||
export class EventGridDeserializer {
|
||||
/**
|
||||
* Deserializes events encoded in the Event Grid schema.
|
||||
*
|
||||
|
@ -67,10 +42,10 @@ export class EventGridConsumer {
|
|||
* @param encodedEvents - an object representing a single event, encoded in the Event Grid schema.
|
||||
*/
|
||||
public async deserializeEventGridEvents(
|
||||
encodedEvents: object
|
||||
encodedEvents: Record<string, unknown>
|
||||
): Promise<EventGridEvent<unknown>[]>;
|
||||
public async deserializeEventGridEvents(
|
||||
encodedEvents: string | object
|
||||
encodedEvents: string | Record<string, unknown>
|
||||
): Promise<EventGridEvent<unknown>[]> {
|
||||
const decodedArray = parseAndWrap(encodedEvents);
|
||||
|
||||
|
@ -83,10 +58,6 @@ export class EventGridConsumer {
|
|||
|
||||
if (systemDeserializers[deserialized.eventType]) {
|
||||
deserialized.data = await systemDeserializers[deserialized.eventType](deserialized.data);
|
||||
} else if (this.customDeserializers[deserialized.eventType]) {
|
||||
deserialized.data = await this.customDeserializers[deserialized.eventType](
|
||||
deserialized.data
|
||||
);
|
||||
}
|
||||
|
||||
events.push(deserialized as EventGridEvent<unknown>);
|
||||
|
@ -108,9 +79,11 @@ export class EventGridConsumer {
|
|||
*
|
||||
* @param encodedEvents - an object representing a single event, encoded in the Cloud Events 1.0 schema.
|
||||
*/
|
||||
public async deserializeCloudEvents(encodedEvents: object): Promise<CloudEvent<unknown>[]>;
|
||||
public async deserializeCloudEvents(
|
||||
encodedEvents: string | object
|
||||
encodedEvents: Record<string, unknown>
|
||||
): Promise<CloudEvent<unknown>[]>;
|
||||
public async deserializeCloudEvents(
|
||||
encodedEvents: string | Record<string, unknown>
|
||||
): Promise<CloudEvent<unknown>[]> {
|
||||
const decodedArray = parseAndWrap(encodedEvents);
|
||||
|
||||
|
@ -166,8 +139,6 @@ export class EventGridConsumer {
|
|||
// If a decoder is registered, apply it to the data.
|
||||
if (systemDeserializers[modelEvent.type]) {
|
||||
modelEvent.data = await systemDeserializers[modelEvent.type](modelEvent.data);
|
||||
} else if (this.customDeserializers[modelEvent.type]) {
|
||||
modelEvent.data = await this.customDeserializers[modelEvent.type](modelEvent.data);
|
||||
}
|
||||
|
||||
// Build the "extensionsAttributes" property bag by removing all known top level properties.
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { KeyCredential } from "@azure/core-auth";
|
||||
import { KeyCredential, SASCredential } from "@azure/core-auth";
|
||||
import { PipelineResponse, PipelineRequest, SendRequest, PipelinePolicy } from "@azure/core-https";
|
||||
|
||||
import { SignatureCredential } from "./sharedAccessSignitureCredential";
|
||||
import { isKeyCredentialLike } from "./util";
|
||||
|
||||
/**
|
||||
|
@ -27,7 +26,7 @@ export const eventGridCredentialPolicyName = "eventGridCredentialPolicy";
|
|||
* using the appropriate header for Event Grid
|
||||
*/
|
||||
export function eventGridCredentialPolicy(
|
||||
credential: KeyCredential | SignatureCredential
|
||||
credential: KeyCredential | SASCredential
|
||||
): PipelinePolicy {
|
||||
return {
|
||||
name: eventGridCredentialPolicyName,
|
||||
|
@ -35,7 +34,7 @@ export function eventGridCredentialPolicy(
|
|||
if (isKeyCredentialLike(credential)) {
|
||||
request.headers.set(API_KEY_HEADER_NAME, credential.key);
|
||||
} else {
|
||||
request.headers.set(SAS_TOKEN_HEADER_NAME, credential.signature());
|
||||
request.headers.set(SAS_TOKEN_HEADER_NAME, credential.signature);
|
||||
}
|
||||
|
||||
return next(request);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { KeyCredential } from "@azure/core-auth";
|
||||
import { KeyCredential, SASCredential } from "@azure/core-auth";
|
||||
import { PipelineOptions } from "@azure/core-https";
|
||||
import { OperationOptions, createClientPipeline } from "@azure/core-client";
|
||||
|
||||
import { eventGridCredentialPolicy } from "./eventGridAuthenticationPolicy";
|
||||
import { SignatureCredential } from "./sharedAccessSignitureCredential";
|
||||
import { SDK_VERSION } from "./constants";
|
||||
import {
|
||||
SendCloudEventInput,
|
||||
|
@ -31,22 +30,36 @@ export type EventGridPublisherClientOptions = PipelineOptions;
|
|||
/**
|
||||
* Options for the send events operation.
|
||||
*/
|
||||
export type SendEventsOptions = OperationOptions;
|
||||
export type SendOptions = OperationOptions;
|
||||
|
||||
/**
|
||||
* Options for the send cloud events operation.
|
||||
* A map of input schema names to shapes of the input for the send method on EventGridPublisherClient.
|
||||
*/
|
||||
export type SendCloudEventsOptions = OperationOptions;
|
||||
export interface InputSchemaToInputTypeMap {
|
||||
/**
|
||||
* The shape of the input to `send` when the client is configured to send events using the Event Grid schema.
|
||||
*/
|
||||
EventGrid: SendEventGridEventInput<unknown>;
|
||||
/**
|
||||
* The shape of the input to `send` when the client is configured to send events using the Cloud Event schema.
|
||||
*/
|
||||
CloudEvent: SendCloudEventInput<unknown>;
|
||||
/**
|
||||
* The shape of the input to `send` when the client is configured to send events using a custom schema.
|
||||
*/
|
||||
|
||||
Custom: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for the send custom schema events operation.
|
||||
* Allowed schema types, to be used when constructing the EventGridPublisherClient.
|
||||
*/
|
||||
export type SendCustomSchemaEventsOptions = OperationOptions;
|
||||
export type InputSchema = keyof InputSchemaToInputTypeMap;
|
||||
|
||||
/**
|
||||
* Client class for publishing events to the Event Grid Service.
|
||||
*/
|
||||
export class EventGridPublisherClient {
|
||||
export class EventGridPublisherClient<T extends InputSchema> {
|
||||
/**
|
||||
* The URL to the Event Grid endpoint.
|
||||
*/
|
||||
|
@ -63,7 +76,12 @@ export class EventGridPublisherClient {
|
|||
private readonly client: GeneratedClient;
|
||||
|
||||
/**
|
||||
* Creates an instance of EventGridPublisherClient.
|
||||
* The schema that will be used when sending events.
|
||||
*/
|
||||
private readonly inputSchema: InputSchema;
|
||||
|
||||
/**
|
||||
* Creates an instance of EventGridPublisherClient which sends events using the Event Grid Schema.
|
||||
*
|
||||
* Example usage:
|
||||
* ```ts
|
||||
|
@ -71,20 +89,24 @@ export class EventGridPublisherClient {
|
|||
*
|
||||
* const client = new EventGridPublisherClient(
|
||||
* "<service endpoint>",
|
||||
* "EventGrid",
|
||||
* new AzureKeyCredential("<api key>")
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @param endpointUrl - The URL to the EventGrid endpoint, e.g. https://eg-topic.westus2-1.eventgrid.azure.net/api/events
|
||||
* @param endpointUrl - The URL to the Event Grid endpoint, e.g. https://eg-topic.westus2-1.eventgrid.azure.net/api/events.
|
||||
* @param inputSchema - The schema that the Event Grid endpoint is configured to accept. One of "EventGrid", "CloudEvent", or "Custom".
|
||||
* @param credential - Used to authenticate requests to the service.
|
||||
* @param options - Used to configure the Event Grid Client
|
||||
* @param options - Used to configure the Event Grid Client.
|
||||
*/
|
||||
constructor(
|
||||
endpointUrl: string,
|
||||
credential: KeyCredential | SignatureCredential,
|
||||
inputSchema: T,
|
||||
credential: KeyCredential | SASCredential,
|
||||
options: EventGridPublisherClientOptions = {}
|
||||
) {
|
||||
this.endpointUrl = endpointUrl;
|
||||
this.inputSchema = inputSchema;
|
||||
|
||||
const libInfo = `azsdk-js-eventgrid/${SDK_VERSION}`;
|
||||
const pipelineOptions = { ...options };
|
||||
|
@ -109,81 +131,43 @@ export class EventGridPublisherClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Publishes events in the Event Grid schema. The topic must be configured to expect events in the Event Grid schema.
|
||||
* Sends events to a topic.
|
||||
*
|
||||
* @param message - One or more events to publish
|
||||
* @param events - The events to send. The events should be in the schema used when constructing the client.
|
||||
* @param options - Options to control the underlying operation.
|
||||
*/
|
||||
async sendEvents(
|
||||
events: SendEventGridEventInput<any>[],
|
||||
options?: SendEventsOptions
|
||||
): Promise<void> {
|
||||
const { span, updatedOptions } = createSpan(
|
||||
"EventGridPublisherClient-sendEvents",
|
||||
options || {}
|
||||
);
|
||||
async send(events: InputSchemaToInputTypeMap[T][], options?: SendOptions): Promise<void> {
|
||||
const { span, updatedOptions } = createSpan("EventGridPublisherClient-send", options || {});
|
||||
|
||||
try {
|
||||
return await this.client.publishEvents(
|
||||
this.endpointUrl,
|
||||
(events || []).map(convertEventGridEventToModelType),
|
||||
updatedOptions
|
||||
);
|
||||
} catch (e) {
|
||||
span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
|
||||
throw e;
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes events in the Cloud Events 1.0 schema. The topic must be configured to expect events in the Cloud Events 1.0 schema.
|
||||
*
|
||||
* @param message - One or more events to publish
|
||||
*/
|
||||
async sendCloudEvents(
|
||||
events: SendCloudEventInput<any>[],
|
||||
options?: SendCloudEventsOptions
|
||||
): Promise<void> {
|
||||
const { span, updatedOptions } = createSpan(
|
||||
"EventGridPublisherClient-sendCloudEvents",
|
||||
options || {}
|
||||
);
|
||||
|
||||
try {
|
||||
return await this.client.publishCloudEventEvents(
|
||||
this.endpointUrl,
|
||||
(events || []).map(convertCloudEventToModelType),
|
||||
updatedOptions
|
||||
);
|
||||
} catch (e) {
|
||||
span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
|
||||
throw e;
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes events written using a custom schema. The topic must be configured to expect events in a custom schema.
|
||||
*
|
||||
* @param message - One or more events to publish
|
||||
*/
|
||||
async sendCustomSchemaEvents(
|
||||
events: Record<string, any>[],
|
||||
options?: SendCustomSchemaEventsOptions
|
||||
): Promise<void> {
|
||||
const { span, updatedOptions } = createSpan(
|
||||
"EventGridPublisherClient-sendCustomSchemaEvents",
|
||||
options || {}
|
||||
);
|
||||
|
||||
try {
|
||||
return await this.client.publishCustomEventEvents(
|
||||
this.endpointUrl,
|
||||
events || [],
|
||||
updatedOptions
|
||||
);
|
||||
switch (this.inputSchema) {
|
||||
case "EventGrid": {
|
||||
return await this.client.publishEvents(
|
||||
this.endpointUrl,
|
||||
(events as InputSchemaToInputTypeMap["EventGrid"][]).map(
|
||||
convertEventGridEventToModelType
|
||||
),
|
||||
updatedOptions
|
||||
);
|
||||
}
|
||||
case "CloudEvent": {
|
||||
return await this.client.publishCloudEventEvents(
|
||||
this.endpointUrl,
|
||||
(events as InputSchemaToInputTypeMap["CloudEvent"][]).map(convertCloudEventToModelType),
|
||||
updatedOptions
|
||||
);
|
||||
}
|
||||
case "Custom": {
|
||||
return await this.client.publishCustomEventEvents(
|
||||
this.endpointUrl,
|
||||
events as InputSchemaToInputTypeMap["Custom"][],
|
||||
updatedOptions
|
||||
);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown input schema type '${this.inputSchema}'`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
|
||||
throw e;
|
||||
|
|
|
@ -1,30 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
export { AzureKeyCredential } from "@azure/core-auth";
|
||||
export { AzureKeyCredential, AzureSASCredential } from "@azure/core-auth";
|
||||
|
||||
export {
|
||||
CloudEvent,
|
||||
CustomEventDataDeserializer,
|
||||
EventGridEvent,
|
||||
SendCloudEventInput,
|
||||
SendEventGridEventInput
|
||||
} from "./models";
|
||||
export { CloudEvent, EventGridEvent, SendCloudEventInput, SendEventGridEventInput } from "./models";
|
||||
|
||||
export {
|
||||
EventGridPublisherClient,
|
||||
EventGridPublisherClientOptions,
|
||||
SendEventsOptions,
|
||||
SendCloudEventsOptions,
|
||||
SendCustomSchemaEventsOptions
|
||||
SendOptions,
|
||||
InputSchema,
|
||||
InputSchemaToInputTypeMap
|
||||
} from "./eventGridClient";
|
||||
|
||||
export {
|
||||
SignatureCredential,
|
||||
EventGridSharedAccessSignatureCredential
|
||||
} from "./sharedAccessSignitureCredential";
|
||||
|
||||
export { EventGridConsumer, EventGridConsumerOptions } from "./consumer";
|
||||
export { EventGridDeserializer } from "./consumer";
|
||||
|
||||
export {
|
||||
generateSharedAccessSignature,
|
||||
|
@ -139,6 +128,7 @@ export {
|
|||
StorageDirectoryCreatedEventData,
|
||||
StorageDirectoryDeletedEventData,
|
||||
StorageDirectoryRenamedEventData,
|
||||
StorageLifecyclePolicyActionSummaryDetail,
|
||||
StorageLifecyclePolicyCompletedEventData,
|
||||
WebAppUpdatedEventData,
|
||||
WebBackupOperationStartedEventData,
|
||||
|
@ -174,6 +164,5 @@ export {
|
|||
DeviceTwinProperties,
|
||||
DeviceTwinMetadata,
|
||||
AppServicePlanAction,
|
||||
KnownAppServicePlanAction,
|
||||
StorageLifecyclePolicyActionSummaryDetail
|
||||
KnownAppServicePlanAction
|
||||
} from "./generated/models";
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
/**
|
||||
* The shape of the input for EventGridProducerClient#sendEvents
|
||||
* The shape of the input for EventGridProducerClient#sendEventGridEvents
|
||||
*/
|
||||
export interface SendEventGridEventInput<T> {
|
||||
/**
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
/**
|
||||
* Represents a credential defined by a shared signature.
|
||||
*/
|
||||
export interface SignatureCredential {
|
||||
/**
|
||||
* The signature to be used in authentication.
|
||||
*/
|
||||
signature(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A credential type which allows using a "shared access signature" to authenticate with EventGrid
|
||||
* when sending events.
|
||||
*
|
||||
* A shared access signiture may be generated by using `EventGridPublisherClient#generateSharedAccessSignature`
|
||||
*/
|
||||
export class EventGridSharedAccessSignatureCredential implements SignatureCredential {
|
||||
private _signature: string;
|
||||
|
||||
/**
|
||||
* The value of the signature to be used in authentication
|
||||
*/
|
||||
public signature(): string {
|
||||
return this._signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of an EventGridSharedAccessSignatureCredential for use
|
||||
* with a service client.
|
||||
*
|
||||
* @param signature - The signature to use in authentication
|
||||
*/
|
||||
constructor(signature: string) {
|
||||
if (!signature) {
|
||||
throw new Error("signature must be a non-empty string");
|
||||
}
|
||||
|
||||
this._signature = signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the value of the signature.
|
||||
*
|
||||
* Updates will take effect upon the next request after
|
||||
* updating the signature value.
|
||||
*
|
||||
* @param newSignature - The new signature value to be used
|
||||
*/
|
||||
public update(newSignature: string): void {
|
||||
this._signature = newSignature;
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ export function isKeyCredentialLike(o: unknown): o is KeyCredential {
|
|||
return castO.key !== undefined;
|
||||
}
|
||||
|
||||
export function parseAndWrap(jsonStringOrObject: string | object): any[] {
|
||||
export function parseAndWrap(jsonStringOrObject: string | Record<string, unknown>): any[] {
|
||||
if (typeof jsonStringOrObject === "string") {
|
||||
const o = JSON.parse(jsonStringOrObject);
|
||||
if (Array.isArray(o)) {
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
import { assert, use as chaiUse } from "chai";
|
||||
import chaiPromises from "chai-as-promised";
|
||||
|
||||
import { EventGridConsumer } from "../src";
|
||||
import { EventGridDeserializer } from "../src";
|
||||
import * as testData from "./utils/testData";
|
||||
|
||||
chaiUse(chaiPromises);
|
||||
|
||||
describe("EventGridConsumer", function() {
|
||||
const consumer = new EventGridConsumer();
|
||||
describe("EventGridDeserializer", function() {
|
||||
const consumer = new EventGridDeserializer();
|
||||
|
||||
describe("#deserializeEventGridEvents", function() {
|
||||
it("deserializes a single event", async () => {
|
||||
|
|
|
@ -20,7 +20,6 @@ import { FullOperationResponse } from "@azure/core-client";
|
|||
|
||||
describe("EventGridPublisherClient", function() {
|
||||
let recorder: Recorder;
|
||||
let client: EventGridPublisherClient;
|
||||
let res: FullOperationResponse | undefined;
|
||||
|
||||
this.timeout(10000);
|
||||
|
@ -29,11 +28,14 @@ describe("EventGridPublisherClient", function() {
|
|||
res = undefined;
|
||||
});
|
||||
|
||||
describe("#sendEvents", function() {
|
||||
describe("#send (EventGrid schema)", function() {
|
||||
let client: EventGridPublisherClient<"EventGrid">;
|
||||
|
||||
beforeEach(function() {
|
||||
({ client, recorder } = createRecordedClient(
|
||||
this,
|
||||
testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT,
|
||||
"EventGrid",
|
||||
new AzureKeyCredential(testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY)
|
||||
));
|
||||
});
|
||||
|
@ -43,7 +45,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends a single event", async () => {
|
||||
await client.sendEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
eventTime: recorder.newDate("singleEventDate"),
|
||||
|
@ -63,7 +65,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends multiple events", async () => {
|
||||
await client.sendEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
eventTime: recorder.newDate("multiEventDate1"),
|
||||
|
@ -93,11 +95,14 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#sendCloudEventSchemaEvents", function() {
|
||||
describe("#send (CloudEvent schema)", function() {
|
||||
let client: EventGridPublisherClient<"CloudEvent">;
|
||||
|
||||
beforeEach(function() {
|
||||
({ client, recorder } = createRecordedClient(
|
||||
this,
|
||||
testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT,
|
||||
"CloudEvent",
|
||||
new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY)
|
||||
));
|
||||
});
|
||||
|
@ -107,7 +112,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends a single event", async () => {
|
||||
await client.sendCloudEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
type: "Azure.Sdk.TestEvent1",
|
||||
|
@ -126,7 +131,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends multiple events", async () => {
|
||||
await client.sendCloudEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
type: "Azure.Sdk.TestEvent1",
|
||||
|
@ -160,7 +165,7 @@ describe("EventGridPublisherClient", function() {
|
|||
setTracer(tracer);
|
||||
const rootSpan = tracer.startSpan("root");
|
||||
|
||||
await client.sendCloudEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
type: "Azure.Sdk.TestEvent1",
|
||||
|
@ -194,16 +199,19 @@ describe("EventGridPublisherClient", function() {
|
|||
|
||||
assert.equal(spans.length, 3);
|
||||
assert.equal(spans[0].name, "root");
|
||||
assert.equal(spans[1].name, "Azure.Data.EventGrid.EventGridPublisherClient-sendCloudEvents");
|
||||
assert.equal(spans[1].name, "Azure.Data.EventGrid.EventGridPublisherClient-send");
|
||||
assert.equal(spans[2].name, "/api/events");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#sendCustomSchemaEvents", function() {
|
||||
describe("#send (Custom Event Schema)", function() {
|
||||
let client: EventGridPublisherClient<"Custom">;
|
||||
|
||||
beforeEach(function() {
|
||||
({ client, recorder } = createRecordedClient(
|
||||
this,
|
||||
testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT,
|
||||
"Custom",
|
||||
new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY)
|
||||
));
|
||||
});
|
||||
|
@ -213,7 +221,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends a single event", async () => {
|
||||
await client.sendCustomSchemaEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
ver: "1.0",
|
||||
|
@ -231,7 +239,7 @@ describe("EventGridPublisherClient", function() {
|
|||
});
|
||||
|
||||
it("sends multiple events", async () => {
|
||||
await client.sendCustomSchemaEvents(
|
||||
await client.send(
|
||||
[
|
||||
{
|
||||
ver: "1.0",
|
||||
|
|
|
@ -7,15 +7,15 @@ import * as dotenv from "dotenv";
|
|||
import { env, Recorder, record, RecorderEnvironmentSetup } from "@azure/test-utils-recorder";
|
||||
import { isNode } from "./testUtils";
|
||||
|
||||
import { EventGridPublisherClient } from "../../src/index";
|
||||
import { EventGridPublisherClient, InputSchema } from "../../src/index";
|
||||
import { KeyCredential } from "@azure/core-auth";
|
||||
|
||||
if (isNode) {
|
||||
dotenv.config();
|
||||
}
|
||||
|
||||
export interface RecordedClient {
|
||||
client: EventGridPublisherClient;
|
||||
export interface RecordedClient<T extends InputSchema> {
|
||||
client: EventGridPublisherClient<T>;
|
||||
recorder: Recorder;
|
||||
}
|
||||
|
||||
|
@ -53,15 +53,16 @@ export const environmentSetup: RecorderEnvironmentSetup = {
|
|||
queryParametersToSkip: []
|
||||
};
|
||||
|
||||
export function createRecordedClient(
|
||||
export function createRecordedClient<T extends InputSchema>(
|
||||
context: Context,
|
||||
endpoint: string,
|
||||
eventSchema: T,
|
||||
credential: KeyCredential
|
||||
): RecordedClient {
|
||||
): RecordedClient<T> {
|
||||
const recorder = record(context, environmentSetup);
|
||||
|
||||
return {
|
||||
client: new EventGridPublisherClient(endpoint, credential),
|
||||
client: new EventGridPublisherClient(endpoint, eventSchema, credential),
|
||||
recorder
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче