Sample for NexusSerializationContext - #802
Conversation
| import javax.crypto.spec.SecretKeySpec; | ||
|
|
||
| /** Selects a payload encoding from the Nexus endpoint, service, and operation. */ | ||
| public final class NexusCodec implements PayloadCodec { |
There was a problem hiding this comment.
I would structure this a bit differently, I would make the NexusCodec take a map of endpoints and PayloadCodec and then pick the right one based on the context. I think it would be easier for a user to copy it and apply it to their unique situations
There was a problem hiding this comment.
I would also want to show encryption here since that is the main reason customer want this feature, per endpoint encryption, so I would maybe have two endpoints one that uses compression and encryption with key A, and one that just does encryption with key B. Does that make sense?
There was a problem hiding this comment.
Thanks, updated to have this.
|
|
||
| ```bash | ||
| temporal operator namespace create --namespace nexus-serialization-handler | ||
| temporal operator namespace create --namespace nexus-serialization-caller |
There was a problem hiding this comment.
I would lean towards separating this out more so it is a more realistic sample, we have gotten some feedback from product on our samples not being reflective of what the customer would actually do. So I would suggest having 3 namespaces here like 1 caller and two handler and each handler has its own endpoint and worker
There was a problem hiding this comment.
Created 3 in different namespaces
| import io.temporal.common.converter.DefaultDataConverter; | ||
| import java.util.Collections; | ||
|
|
||
| public final class SampleConfig { |
There was a problem hiding this comment.
I would remove most things here except for the endpoints since you wouldn't want to expose the handlers or callers task queue that breaks part of the abstraction of Nexus
| WorkflowClient client = | ||
| ClientOptions.getWorkflowClient( | ||
| args, | ||
| WorkflowClientOptions.newBuilder().setDataConverter(SampleConfig.dataConverter())); |
There was a problem hiding this comment.
I think the handler should have its own Data converter, if the caller and handler can share a data converter then it kind of removes the value of doing per endpoint stuff
There was a problem hiding this comment.
I would make the caller endpoint aware and then the handlers actually don't need to be
There was a problem hiding this comment.
Moved the creation of Data converts to be with 3 different workers. Only the caller endpoint is aware of all the codecs
| Promise<Void> timer = Workflow.newTimer(MAX_AWAIT_TIME); | ||
| Workflow.await( | ||
| () -> timer.isCompleted() || !unprocessedGreetings.isEmpty() || exitRequested); | ||
| boolean timedout = timer.isCompleted() && unprocessedGreetings.isEmpty() && !exitRequested; |
There was a problem hiding this comment.
This is a fix for unit tests, it was stalling after this SDK version change
| can decode the final result before printing it. | ||
|
|
||
| `NexusSerializationContext` works end to end for synchronous Nexus operations. | ||
| For an asynchronous operation, the handler's final result is serialized as a workflow |
There was a problem hiding this comment.
I'd mention this is something we are going to improve
| `NexusCodec` uses `NexusSerializationContext` to select the `PayloadCodec` | ||
| registered for each endpoint. The sample uses these keys: | ||
|
|
||
| - Key A: compresses with zlib, then encrypts the first synchronous endpoint's payloads. |
There was a problem hiding this comment.
instead of first or seconds can we just say the endpoints name?
| temporal operator namespace create --namespace nexus-serialization-key-a-handler | ||
| temporal operator namespace create --namespace nexus-serialization-key-b-handler | ||
| temporal operator namespace create --namespace nexus-serialization-async-handler | ||
| temporal operator nexus endpoint create \ |
There was a problem hiding this comment.
Do we need 4 endpoints? I was thinking the async call could just be on the same nexus endpoint?
There was a problem hiding this comment.
Made this to be 2 services for Async and Sync, and two endpoints for encrypt and compress+encrypt
What was changed
Adding a sample for NexusSerializationContext
Why?
Show users how to use NexusSerializationContext for per endpoint encryption
Checklist
Closes
How was this tested:
Tested locally with temporal dev server