Process With Cloud Events - using gRPC
For using gRPC, this demo follows the guidelines suggested for any gRPC ASP.NET Core App.
Which for this demo means:
- Making use of
builder.Services.AddGrpcReflection()andapp.MapGrpcReflectionService() - Making use of
gRPCuifor testing
Explanation
This demo showcases how SK Process Framework could interact with a gRPC Server and clients.
The main difference of this demo is the custom implementation of the gRPC Server and client used internally by the SK Process in the SK Proxy Step.
Main gRPC components:
documentationGenerator.proto:<root>\dotnet\samples\Demos\ProcessWithCloudEvents\ProcessWithCloudEvents.Grpc\Protos\documentationGenerator.proto- gRPC Server:
<root>\dotnet\samples\Demos\ProcessWithCloudEvents\ProcessWithCloudEvents.Grpc\Services\DocumentGenerationService.cs - gRPC Client/IExternalKernelProcessMessageChannel implementation:
<root>\dotnet\samples\Demos\ProcessWithCloudEvents\ProcessWithCloudEvents.Grpc\Clients\DocumentGenerationGrpcClient.cs
SK Process and gRPC Events
sequenceDiagram
participant grpcClient as gRPC Client
box Server
participant grpcServer as gRPC Server
participant SKP as SK Process
end
grpcClient->>grpcServer: UserRequestFeatureDocumentation <br/>gRPC
grpcServer->>SKP: StartDocumentGeneration <br/>SK event
SKP->>grpcServer: RequestUserReview (SK Topic)/<br/>RequestUserReviewDocumentationFromProcess (gRPC)
grpcServer->>grpcClient: RequestUserReviewDocumentation <br/>gRPC
grpcClient->>grpcServer: UserReviewedDocumentation <br/>gRPC
grpcServer->>SKP: UserApprovedDocument/UserRejectedDocument <br/>SK event
SKP->>grpcServer: PublishDocumentation (SK Topic)/<br/>PublishDocumentation (gRPC)
grpcServer->>grpcClient: ReceivePublishedDocumentation <br/>gRPC
- When the
UserRequestFeatureDocumentationgRPC request is received from the gRPC client, the server initiates an SK Process and emits theStartDocumentGenerationSK event. - The
RequestUserReviewtopic is emitted when theDocumentationApprovedevent is triggered during theProofReadDocumentationStep. This event invokes theRequestUserReviewDocumentationFromProcessgRPC method to communicate with the server. - The
RequestUserReviewDocumentationFromProcessmethod updates the shared stream, which is used to communicate with the subscribers ofRequestUserReviewDocumentation. The gRPC client then receives the document for review and approval. - The gRPC client can approve or reject the document using the
UserReviewedDocumentationmethod to communicate with the server. The server then sends theUserApprovedDocumentorUserRejectedDocumentSK event to the SK Process. - The SK Process resumes, and the
PublishDocumentationStepnow has all the necessary parameters to execute. Upon execution, thePublishDocumentationtopic is triggered, invoking thePublishDocumentationmethod on the gRPC server. - The PublishDocumentation method updates the shared stream used by
ReceivePublishedDocumentation, ensuring that all subscribers receive the update of the latest published document
Demo
Requirements
- Have Dapr setup ready
- Build and Run the app
- Interact with the server by:
-
Install and run
gRPCuilistening to the addresslocalhost:58641:./grpcui.exe -plaintext localhost:58641or
-
Use the
ProcessWithCloudEvents.ClientApp and use it to interact with the server. This app uses gRPC Web, which interacts with the server throughlocalhost:58640.
-
Usage without UI
For interacting with the gRPC server, the
-
Build and run the app
-
Open 2 windows of
gRPCuiwith the following methods:- Window 1:
- Method name:
UserRequestFeatureDocumentationandUserReviewedDocumentation
- Method name:
- Window 2:
- Method name:
RequestUserReviewDocumentation
- Method name:
- Window 3:
- Method name:
ReceivePublishedDocumentation
- Method name:
- Window 1:
-
Select a process id to be used with all methods. Example: processId = "100"
-
Execute different methods in the following order:
-
RequestUserReviewDocumentationwith Request Data:{ "processId": "100" }This will subscribe to any request for review done for the specific process id and a response will be received when the process emits a notification. Set timeout to 30 seconds.
-
UserRequestFeatureDocumentationwith Request Data:{ "title": "some product title", "userDescription": "some user description", "content": "some product content", "processId": "100", }This request will kickstart the creation of a new process with the specific processId passing an initial event to the SK process.
-
-
Once the
RequestUserReviewDocumentationis received, execute the following methods:-
ReceivePublishedDocumentationwith Request Data:{ "processId": "100" }This will subscribe to any request for review done for the specific process id and a response will be received when the process emits a notification. Set timeout to 30 seconds.
-
UserReviewedDocumentationwith Request Data:{ "documentationApproved": true, "reason": "", "processData": { "processId": "100" } }
-
Debugging
For debugging and be able to set breakpoints in different stages of the app, you can:
- Install the Visual Studio Dapr Extension and make use of it by making use of the
<root>\dotnet\dapr.yamlfile already in the repository.
or
- Set the
ProcessWithCloudEvents.Grpcas startup app, run and attach the Visual Studio debugger:
dapr run --app-id processwithcloudevents-grpc --app-port 58640 --app-protocol http -- dotnet run --no-build