Skip to content

EventGrid Beta4#18873

Merged
YijunXieMS merged 66 commits intoAzure:masterfrom
YijunXieMS:eg-beta4
Feb 5, 2021
Merged

EventGrid Beta4#18873
YijunXieMS merged 66 commits intoAzure:masterfrom
YijunXieMS:eg-beta4

Conversation

@YijunXieMS
Copy link
Contributor

@YijunXieMS YijunXieMS commented Jan 29, 2021

This PR mainly has the API changes for EventGrid beta4:

  1. CloudEvent constructor accept a new parameter "data".
  2. CloudEvent.parse and EventGridEvent.parse are renamed to fromString()
  3. getData() of CloudEvent and EventGridEvent return BinaryData. Removed the generic version of getData that deserializes data into a certain type. Instead, users can use BinaryData to deserialize data.
  4. added isSystemEvent / asSystemEventData to CloudEvent and EventGridEvent. (removed later)
  5. Removed getDataAsync
  6. Added EventGridSasGenerator class. Removed EventGridSasCredential
  7. Renamed sendEvents to sendEventGridEvents
  8. Added sample code for the new APIs
  9. Some other changes.

closes #18281
closes #18276
closes #18275
closes #14926
closes #18427

Comment on lines +81 to +86
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-queue</artifactId>
<version>12.8.0</version>
<scope>test</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

This dependency should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is test scope for a sample. The released SDK won't have it.

@check-enforcer
Copy link

check-enforcer bot commented Feb 3, 2021

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run java - [service] - ci

@YijunXieMS YijunXieMS marked this pull request as ready for review February 3, 2021 05:37
* @param data the payload of this event. Set to null if your event doesn't have the data payload.
* It will be serialized as a String if it's a String, or application/json if it's not a String.
*/
public CloudEvent(String source, String type, Object data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can CloudEvent have no data ? If data is optional, why it is provided in constructor ? User can call setData() if they need to. constructor are normally used for required parameters.

Also Add @throws clause , since it will throw IllegalArgumentException. After that you do not need to additionally explain It can't be null or empty .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes a CloudEvent can have no data. This sounds weird but the specification says it's optional.
We still put it in the constructor because we believe 99% of the time a CloudEvent will have data.

*/
public CloudEvent(String source, String type) {
public CloudEvent(String source, String type, byte[] data, String dataContentType) {
this(source, type);
Copy link
Contributor

Choose a reason for hiding this comment

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

null check for data and dataContentType ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both data and dataContentType can be null.

* @param source a URI identifying the origin of the event.
* @param type the type of event, e.g. "Contoso.Items.ItemReceived".
* @param data the payload in bytes of this event. It will be serialized to Base64 format.
* @param dataContentType the type of the data.
Copy link
Contributor

Choose a reason for hiding this comment

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

add @throws clause.

} else if (CoreUtils.isNullOrEmpty(type)) {
}
if (CoreUtils.isNullOrEmpty(type)) {
throw logger.logExceptionAsError(new IllegalArgumentException("type cannot be null or empty"));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: casing, t in type should be capitol Type can not be null or empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to 'type' because the param name is type.

return Flux.fromIterable(events)
.map(EventGridEvent::toImpl)
.map(event -> {
com.azure.messaging.eventgrid.implementation.models.EventGridEvent internalEvent = event.toImpl();
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is at two places (also at line 121) Can we combine it in a function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They look the same but one is for EventGridEvent and one for CloudEvent. the two classes don't have a common parent class or interface so I prefer not combining these lines of code.
Good points though.

Copy link
Member

@srnagar srnagar left a comment

Choose a reason for hiding this comment

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

Overall, looks good. A few minor comments. Just do another pass on improving the javadocs.

* The CloudEvent model. This represents a cloud event as specified by the
* <a href="https://github.com/cloudevents/spec/blob/v1.0.1/spec.md">Cloud Native Computing Foundation</a>
*
* When you send a CloudEvent to an Event Grid Topic, the topic must be configured to receive the CloudEvent schema.
Copy link
Member

Choose a reason for hiding this comment

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

When this is moved to azure-core, we should update this doc to remove Event Grid specific details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to follow-up issue #19014

*
* @throws IllegalArgumentException if subject, eventType or data is {@code null} or empty.
*/
public EventGridEvent(String subject, String eventType, Object data, String dataVersion) {
Copy link
Member

Choose a reason for hiding this comment

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

Since subject, eventType and dataVersion are required, I would put them as the first 3 params and move data to the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll need to check with service team why data is optional and dataVersion is mandatory after beta4.
Added to follow-up issue #19014

@@ -68,19 +72,28 @@ public EventGridServiceVersion getServiceVersion() {
* @param events the EventGrid events to publish.
*
* @return the completion.
Copy link
Member

Choose a reason for hiding this comment

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

Update this doc - A {@link Mono} that completes when the events are sent to the service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Updated


package com.azure.messaging.eventgrid.samples.models;

public class User {
Copy link
Member

Choose a reason for hiding this comment

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

Since this is in samples and users would look at this, we should have javadocs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a javadoc for the class


/**
* This sample code shows how to send {@link EventGridEvent}s to an Event Grid Topic that accepts Event Grid event schema.
* Refer to https://docs.microsoft.com/en-us/azure/event-grid/event-schema.
Copy link
Member

Choose a reason for hiding this comment

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

Use html tag for the link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

*
* For new customers, {@link CloudEvent} is generally preferred over EventGridEvent because the
* <a href="https://docs.microsoft.com/azure/event-grid/cloud-event-schema">CloudEvent schema</a> is supported across
* organizations while the <a href="https://docs.microsoft.com/azure/event-grid/cloud-event-schema">EventGridEvent schema</a> is not.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* organizations while the <a href="https://docs.microsoft.com/azure/event-grid/cloud-event-schema">EventGridEvent schema</a> is not.
* organizations while the <a href="https://docs.microsoft.com/azure/event-grid/event-schema">EventGridEvent schema</a> is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated

* @param events the custom events to publish.
*
* @return the completion.
* @throws NullPointerException if events is {@code null}.
Copy link
Member

Choose a reason for hiding this comment

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

Add more documentation to this as this is an uncommon scenario. Describe when the user can send custom events and what are the prerequisites for sending a custom event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to follow-up issue #19014

* @throws NullPointerException if events is {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> sendCustomEventsWithResponse(Iterable<Object> events, Context context) {
Copy link
Member

Choose a reason for hiding this comment

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

More docs for custom event APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to follow-up issue #19014

/**
* Publishes the given EventGrid events to the given topic or domain.
* @param events the EventGrid events to publish.
* @throws NullPointerException if events is {@code null}.
Copy link
Member

Choose a reason for hiding this comment

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

All service methods (on how to use the API), client builder and clients (how to instantiate a client) should have code snippets in javadoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to follow-up issue #19014

Copy link
Member

@srnagar srnagar left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client This issue points to a problem in the data-plane of the library. Event Grid

Projects

None yet

3 participants