diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/README.md b/sdk/eventgrid/Azure.Messaging.EventGrid/README.md index 01478e3761c6..922a62dee981 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/README.md +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/README.md @@ -228,6 +228,27 @@ List eventsList = new List await client.SendEventsAsync(eventsList); ``` +For sending CloudEvents, the CloudEvent source is used as the domain topic: +```C# Snippet:SendCloudEventsToDomain +List eventsList = new List(); + +for (int i = 0; i < 10; i++) +{ + CloudEvent cloudEvent = new CloudEvent( + // the source is mapped to the domain topic + $"Subject-{i}", + "Microsoft.MockPublisher.TestEvent", + "hello") + { + Id = $"event-{i}", + Time = DateTimeOffset.Now + }; + eventsList.Add(cloudEvent); +} + +await client.SendEventsAsync(eventsList); +``` + ### Receiving and Deserializing Events There are several different Azure services that act as [event handlers](https://docs.microsoft.com/azure/event-grid/event-handlers). diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/EventGridClientLiveTests.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/EventGridClientLiveTests.cs index d1dbe04c95b9..c221b20f0cdb 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/EventGridClientLiveTests.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/EventGridClientLiveTests.cs @@ -209,6 +209,42 @@ public async Task CanPublishEventToDomain() await client.SendEventsAsync(eventsList); } + [RecordedTest] + public async Task CanPublishCloudEventToDomain() + { + EventGridPublisherClientOptions options = InstrumentClientOptions(new EventGridPublisherClientOptions()); + EventGridPublisherClient client = InstrumentClient( + new EventGridPublisherClient( + new Uri(TestEnvironment.CloudEventDomainHost), + new AzureKeyCredential(TestEnvironment.CloudEventDomainKey), + options)); + + #region Snippet:SendCloudEventsToDomain + List eventsList = new List(); + + for (int i = 0; i < 10; i++) + { + CloudEvent cloudEvent = new CloudEvent( + // the source is mapped to the domain topic + $"Subject-{i}", + "Microsoft.MockPublisher.TestEvent", + "hello") + { +#if SNIPPET + Id = $"event-{i}", + Time = DateTimeOffset.Now +#else + Id = Recording.Random.NewGuid().ToString(), + Time = Recording.Now +#endif + }; + eventsList.Add(cloudEvent); + } + + await client.SendEventsAsync(eventsList); + #endregion + } + [RecordedTest] public async Task CanPublishEventToDomainAAD() { diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/Infrastructure/EventGridTestEnvironment.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/Infrastructure/EventGridTestEnvironment.cs index 4b28d821400b..68bb90624f31 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/Infrastructure/EventGridTestEnvironment.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/Infrastructure/EventGridTestEnvironment.cs @@ -14,6 +14,9 @@ public class EventGridTestEnvironment : TestEnvironment public const string DomainKeyEnvironmentVariableName = "EVENT_GRID_DOMAIN_KEY"; public const string DomainEndpointEnvironmentVariableName = "EVENT_GRID_DOMAIN_ENDPOINT"; + public const string CloudEventDomainKeyEnvironmentVariableName = "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY"; + public const string CloudEventDomainEndpointEnvironmentVariableName = "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT"; + public const string CloudEventTopicKeyEnvironmentVariableName = "EVENT_GRID_CLOUD_EVENT_TOPIC_KEY"; public const string CloudEventTopicEndpointEnvironmentVariableName = "EVENT_GRID_CLOUD_EVENT_TOPIC_ENDPOINT"; @@ -26,6 +29,9 @@ public class EventGridTestEnvironment : TestEnvironment public string DomainHost => GetRecordedVariable(DomainEndpointEnvironmentVariableName); public string DomainKey => GetRecordedVariable(DomainKeyEnvironmentVariableName, options => options.IsSecret(SanitizedValue.Base64)); + public string CloudEventDomainHost => GetRecordedVariable(CloudEventDomainEndpointEnvironmentVariableName); + public string CloudEventDomainKey => GetRecordedVariable(CloudEventDomainKeyEnvironmentVariableName, options => options.IsSecret(SanitizedValue.Base64)); + public string CloudEventTopicHost => GetRecordedVariable(CloudEventTopicEndpointEnvironmentVariableName); public string CloudEventTopicKey => GetRecordedVariable(CloudEventTopicKeyEnvironmentVariableName, options => options.IsSecret(SanitizedValue.Base64)); diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomain.json b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomain.json new file mode 100644 index 000000000000..59ef272e42c8 --- /dev/null +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomain.json @@ -0,0 +1,37 @@ +{ + "Entries": [ + { + "RequestUri": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events?api-version=2018-01-01", + "RequestMethod": "POST", + "RequestHeaders": { + "aeg-sas-key": "Sanitized", + "Content-Length": "2141", + "Content-Type": "application/cloudevents-batch\u002Bjson; charset=utf-8", + "traceparent": "00-d776a31f86849f498dad6f8d101551b7-a1148c6e2ab5524e-00", + "User-Agent": [ + "azsdk-net-Messaging.EventGrid/4.8.0-alpha.20211123.1", + "(.NET 5.0.12; Microsoft Windows 10.0.22000)" + ], + "x-ms-client-request-id": "00b7b23e3001cf5555199397119ea8f4", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": "[{\u0022id\u0022:\u00220dd3c33a-1edd-48b7-10b0-511a5b1e4063\u0022,\u0022source\u0022:\u0022Subject-0\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u002234bcb436-797b-3f54-d0d9-8f44063c1c80\u0022,\u0022source\u0022:\u0022Subject-1\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022728cbeab-e8d8-6b2b-8c30-bc0bd962223c\u0022,\u0022source\u0022:\u0022Subject-2\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u00229d30cc29-357c-c1aa-6f93-3d038f7242d4\u0022,\u0022source\u0022:\u0022Subject-3\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u00229d6fd193-cd92-4e8b-8950-a74bbc49666d\u0022,\u0022source\u0022:\u0022Subject-4\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022391b52b7-7f0c-7504-13ca-0344ab27dc1a\u0022,\u0022source\u0022:\u0022Subject-5\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u00220877e8ed-84f3-5baa-41e1-142b8d5f0426\u0022,\u0022source\u0022:\u0022Subject-6\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u00223c4ccf2d-0956-13c8-ccfa-89c7ca46a361\u0022,\u0022source\u0022:\u0022Subject-7\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022d45d8d74-5ed1-327a-a8bf-f72a6bd8e7b4\u0022,\u0022source\u0022:\u0022Subject-8\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022db16dcc5-a0db-e4c3-1f64-3bf9fae291fa\u0022,\u0022source\u0022:\u0022Subject-9\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:11.9558168-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022}]", + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-01-01", + "Content-Length": "0", + "Date": "Wed, 24 Nov 2021 04:44:12 GMT", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-request-id": "15d2bb70-97b1-4378-a8be-a886ae145545" + }, + "ResponseBody": [] + } + ], + "Variables": { + "DateTimeOffsetNow": "2021-11-23T20:44:11.9558168-08:00", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY": "Kg==", + "RandomSeed": "1623617748" + } +} \ No newline at end of file diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomainAsync.json b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomainAsync.json new file mode 100644 index 000000000000..6f3be668edac --- /dev/null +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/SessionRecords/EventGridClientLiveTests/CanPublishCloudEventToDomainAsync.json @@ -0,0 +1,37 @@ +{ + "Entries": [ + { + "RequestUri": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events?api-version=2018-01-01", + "RequestMethod": "POST", + "RequestHeaders": { + "aeg-sas-key": "Sanitized", + "Content-Length": "2141", + "Content-Type": "application/cloudevents-batch\u002Bjson; charset=utf-8", + "traceparent": "00-eec88c17fe866647afadc6649bd89ffd-17c60718a3a4d641-00", + "User-Agent": [ + "azsdk-net-Messaging.EventGrid/4.8.0-alpha.20211123.1", + "(.NET 5.0.12; Microsoft Windows 10.0.22000)" + ], + "x-ms-client-request-id": "3f34de5c84285f44b59c1e316da58451", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": "[{\u0022id\u0022:\u002254b956bc-4c84-6038-5f90-73f28cb7cbea\u0022,\u0022source\u0022:\u0022Subject-0\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022b0b3f65d-cd13-d3c6-1c3c-f17aceb49713\u0022,\u0022source\u0022:\u0022Subject-1\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022daddc751-a54b-a211-41d8-4913d51c857f\u0022,\u0022source\u0022:\u0022Subject-2\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022df5e5c1d-990e-ee5a-90e5-37485abe92aa\u0022,\u0022source\u0022:\u0022Subject-3\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022c4a05ff8-f1d9-b79e-e510-6e3b84b3feff\u0022,\u0022source\u0022:\u0022Subject-4\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022715c71b6-b756-b805-6def-4a666dc94783\u0022,\u0022source\u0022:\u0022Subject-5\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022761a9f45-c17c-2ca6-bda7-fafd2a1e6add\u0022,\u0022source\u0022:\u0022Subject-6\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022e99138e7-2061-4154-59e8-57e9a7384a1c\u0022,\u0022source\u0022:\u0022Subject-7\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022e5f6ebc8-8798-f582-ca30-b3aebd088d4e\u0022,\u0022source\u0022:\u0022Subject-8\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022},{\u0022id\u0022:\u0022357f6d85-5e37-2421-4bd8-1c9469bc8485\u0022,\u0022source\u0022:\u0022Subject-9\u0022,\u0022type\u0022:\u0022Microsoft.MockPublisher.TestEvent\u0022,\u0022data\u0022:\u0022hello\u0022,\u0022time\u0022:\u00222021-11-23T20:44:12.9535483-08:00\u0022,\u0022specversion\u0022:\u00221.0\u0022,\u0022traceparent\u0022:\u0022Sanitized\u0022}]", + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-01-01", + "Content-Length": "0", + "Date": "Wed, 24 Nov 2021 04:44:12 GMT", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-request-id": "d146de38-4244-443e-9173-09054071ca96" + }, + "ResponseBody": [] + } + ], + "Variables": { + "DateTimeOffsetNow": "2021-11-23T20:44:12.9535483-08:00", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY": "Kg==", + "RandomSeed": "460836516" + } +} \ No newline at end of file diff --git a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/README.md b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/README.md index 91115f2286af..2f0a557afbc1 100644 --- a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/README.md +++ b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/README.md @@ -48,6 +48,7 @@ For detailed information about the Event Grid client library concepts: [Event Gr ## Examples +### Publish to an Event Grid topic ```C# Snippet:CloudNativePublish EventGridPublisherClient client = new EventGridPublisherClient( new Uri(TestEnvironment.CloudEventTopicHost), @@ -64,6 +65,23 @@ var cloudEvent = await client.SendCloudNativeCloudEventAsync(cloudEvent); ``` +### Publish to an Event Grid Domain +When publishing to an Event Grid Domain with CloudEvents, the CloudEvent `source` is used as the domain topic. The Event Grid service doesn't support using an absolute URI for a domain topic, so you would need to do something like the following to integrate with the CloudNative CloudEvents: +```C# Snippet:CloudNativePublishToDomain +CloudEvent cloudEvent = + new CloudEvent + { + Type = "record", + // Event Grid does not allow absolute URIs as the domain topic + Source = new Uri("test", UriKind.Relative), + Id = "eventId", + Time = DateTimeOffset.Now, + Data = new TestPayload("name", 0) + }; + +await client.SendCloudNativeCloudEventAsync(cloudEvent); +``` + ## Troubleshooting For troubleshooting information, see the [Event Grid Client Library documentation](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/eventgrid/Azure.Messaging.EventGrid#troubleshooting). diff --git a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/CloudNativeLiveTests.cs b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/CloudNativeLiveTests.cs index d873752b4a79..458675996f7d 100644 --- a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/CloudNativeLiveTests.cs +++ b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/CloudNativeLiveTests.cs @@ -70,6 +70,37 @@ public async Task CanPublishSingleCloudEvent() await client.SendCloudNativeCloudEventAsync(cloudEvent); } + [RecordedTest] + public async Task CanPublishCloudEventToDomain() + { + EventGridPublisherClientOptions options = InstrumentClientOptions(new EventGridPublisherClientOptions()); + EventGridPublisherClient client = InstrumentClient( + new EventGridPublisherClient( + new Uri(TestEnvironment.CloudEventDomainHost), + new AzureKeyCredential(TestEnvironment.CloudEventDomainKey), + options)); + + #region Snippet:CloudNativePublishToDomain + CloudEvent cloudEvent = + new CloudEvent + { + Type = "record", + // Event Grid does not allow absolute URIs as the domain topic + Source = new Uri("test", UriKind.Relative), +#if SNIPPET + Id = "eventId", + Time = DateTimeOffset.Now, +#else + Id = Recording.Random.NewGuid().ToString(), + Time = Recording.Now, +#endif + Data = new TestPayload("name", 0) + }; + + await client.SendCloudNativeCloudEventAsync(cloudEvent); + #endregion + } + private class TestPayload { public TestPayload(string name, int age) diff --git a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomain.json b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomain.json new file mode 100644 index 000000000000..fed2bccc8c2b --- /dev/null +++ b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomain.json @@ -0,0 +1,34 @@ +{ + "Entries": [ + { + "RequestUri": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events?api-version=2018-01-01", + "RequestMethod": "POST", + "RequestHeaders": { + "aeg-sas-key": "Sanitized", + "Content-Length": "173", + "Content-Type": "application/cloudevents-batch\u002Bjson; charset=utf-8", + "traceparent": "00-584e2365a4b59e4c8a024715ba4bbacf-c60121d4fb824040-00", + "User-Agent": "azsdk-net-Messaging.EventGrid/4.8.0-alpha.20211123.1 (.NET Framework 4.8.4420.0; Microsoft Windows 10.0.22000 )", + "x-ms-client-request-id": "ffc1682f998586eb0d5e1ca13249247b", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": "[{\u0022specversion\u0022:\u00221.0\u0022,\u0022type\u0022:\u0022record\u0022,\u0022source\u0022:\u0022test\u0022,\u0022id\u0022:\u002292f0cd8f-bf1c-7745-fe6d-a9753328c9ac\u0022,\u0022time\u0022:\u00222021-11-23T20:44:19.2156348-08:00\u0022,\u0022data\u0022:{\u0022Name\u0022:\u0022name\u0022,\u0022Age\u0022:0}}]", + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-01-01", + "Content-Length": "0", + "Date": "Wed, 24 Nov 2021 04:44:20 GMT", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-request-id": "d91b752e-dd47-4a6b-beda-0ecb03930980" + }, + "ResponseBody": [] + } + ], + "Variables": { + "DateTimeOffsetNow": "2021-11-23T20:44:19.2156348-08:00", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY": "Kg==", + "RandomSeed": "529761368" + } +} \ No newline at end of file diff --git a/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomainAsync.json b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomainAsync.json new file mode 100644 index 000000000000..5fee38b4f149 --- /dev/null +++ b/sdk/eventgrid/Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents/tests/SessionRecords/CloudNativeLiveTests/CanPublishCloudEventToDomainAsync.json @@ -0,0 +1,34 @@ +{ + "Entries": [ + { + "RequestUri": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events?api-version=2018-01-01", + "RequestMethod": "POST", + "RequestHeaders": { + "aeg-sas-key": "Sanitized", + "Content-Length": "173", + "Content-Type": "application/cloudevents-batch\u002Bjson; charset=utf-8", + "traceparent": "00-ca512298f4468544b7e03e42a528c1eb-bc5b9e1df4afec4f-00", + "User-Agent": "azsdk-net-Messaging.EventGrid/4.8.0-alpha.20211123.1 (.NET Framework 4.8.4420.0; Microsoft Windows 10.0.22000 )", + "x-ms-client-request-id": "6199b93394980e0a9f470624e9db8405", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": "[{\u0022specversion\u0022:\u00221.0\u0022,\u0022type\u0022:\u0022record\u0022,\u0022source\u0022:\u0022test\u0022,\u0022id\u0022:\u0022a53f8543-b400-ecb0-6db7-0e3b776e2fbc\u0022,\u0022time\u0022:\u00222021-11-23T20:44:21.4636148-08:00\u0022,\u0022data\u0022:{\u0022Name\u0022:\u0022name\u0022,\u0022Age\u0022:0}}]", + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-01-01", + "Content-Length": "0", + "Date": "Wed, 24 Nov 2021 04:44:21 GMT", + "Server": "Microsoft-HTTPAPI/2.0", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-request-id": "92dc1206-e069-4700-ad6c-542e53608c1e" + }, + "ResponseBody": [] + } + ], + "Variables": { + "DateTimeOffsetNow": "2021-11-23T20:44:21.4636148-08:00", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT": "https://joloveventgridcloudevent-domain.westus2-1.eventgrid.azure.net/api/events", + "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY": "Kg==", + "RandomSeed": "164543837" + } +} \ No newline at end of file diff --git a/sdk/eventgrid/test-resources.json b/sdk/eventgrid/test-resources.json index 361f537c2219..54d384c0e925 100644 --- a/sdk/eventgrid/test-resources.json +++ b/sdk/eventgrid/test-resources.json @@ -28,6 +28,7 @@ "apiVersion": "2020-04-01-preview", "eventGridTopicName": "[concat(parameters('baseName'), 'topic')]", "eventGridDomainName": "[concat(parameters('baseName'), 'domain')]", + "cloudeventDomainName": "[concat(parameters('baseName'), 'cloudevent-domain')]", "cloudeventTopicName": "[concat(parameters('baseName'), 'cloudevent-topic')]", "customeventTopicName": "[concat(parameters('baseName'), 'customevent-topic')]", "eventGridDataSenderRoleId": "d5a91429-5739-47e2-a06b-3470a27159e7" @@ -46,6 +47,15 @@ "location": "[resourceGroup().location]", "properties": {} }, + { + "name": "[variables('cloudeventDomainName')]", + "type": "Microsoft.EventGrid/domains", + "apiVersion": "[variables('apiVersion')]", + "location": "[resourceGroup().location]", + "properties": { + "inputSchema": "CloudEventSchemaV1_0" + } + }, { "type": "Microsoft.EventGrid/topics", "apiVersion": "[variables('apiVersion')]", @@ -118,6 +128,14 @@ "type": "string", "value": "[listKeys(resourceId('Microsoft.EventGrid/domains', variables('eventGridDomainName')), variables('apiVersion')).key1]" }, + "EVENT_GRID_CLOUD_EVENT_DOMAIN_ENDPOINT": { + "type": "string", + "value": "[reference(variables('cloudeventDomainName')).endpoint]" + }, + "EVENT_GRID_CLOUD_EVENT_DOMAIN_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.EventGrid/domains', variables('cloudeventDomainName')), variables('apiVersion')).key1]" + }, "EVENT_GRID_CLOUD_EVENT_TOPIC_ENDPOINT": { "type": "string", "value": "[reference(variables('cloudeventTopicName')).endpoint]"