-
Notifications
You must be signed in to change notification settings - Fork 8
Provide a way for customer to inject their own data converter. #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kaibocai
wants to merge
6
commits into
main
Choose a base branch
from
kaibocai/deserialize-date
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
samples-azure-functions/src/main/java/com/functions/CustomizeDataConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.functions; | ||
|
||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.HttpMethod; | ||
import com.microsoft.azure.functions.HttpRequestMessage; | ||
import com.microsoft.azure.functions.HttpResponseMessage; | ||
import com.microsoft.azure.functions.annotation.AuthorizationLevel; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.annotation.HttpTrigger; | ||
import com.microsoft.durabletask.DurableTaskClient; | ||
import com.microsoft.durabletask.TaskOrchestrationContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableActivityTrigger; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientInput; | ||
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
public class CustomizeDataConverter { | ||
|
||
@FunctionName("StartCustomize") | ||
public HttpResponseMessage startExampleProcess( | ||
@HttpTrigger(name = "req", | ||
methods = {HttpMethod.GET, HttpMethod.POST}, | ||
authLevel = AuthorizationLevel.ANONYMOUS) final HttpRequestMessage<Optional<String>> request, | ||
@DurableClientInput(name = "durableContext") final DurableClientContext durableContext, | ||
final ExecutionContext context) { | ||
context.getLogger().info("Java HTTP trigger processed a request"); | ||
|
||
final DurableTaskClient client = durableContext.getClient(); | ||
final String instanceId = client.scheduleNewOrchestrationInstance("Customize"); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("Customize") | ||
public ExampleResponse exampleOrchestrator( | ||
@DurableOrchestrationTrigger(name = "taskOrchestrationContext") final TaskOrchestrationContext context, | ||
final ExecutionContext functionContext) { | ||
return context.callActivity("ToLower", "Foo", ExampleResponse.class).await(); | ||
} | ||
|
||
@FunctionName("ToLower") | ||
public ExampleResponse toLower( | ||
@DurableActivityTrigger(name = "value") final String value, | ||
final ExecutionContext context) { | ||
return new ExampleResponse(LocalDate.now(), value.toLowerCase()); | ||
} | ||
|
||
static class ExampleResponse { | ||
private final LocalDate date; | ||
private final String value; | ||
|
||
public ExampleResponse(LocalDate date, String value) { | ||
this.date = date; | ||
this.value = value; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
samples-azure-functions/src/main/java/com/functions/converter/MyConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.functions.converter; | ||
|
||
import com.google.gson.Gson; | ||
import com.microsoft.durabletask.DataConverter; | ||
|
||
public class MyConverter implements DataConverter { | ||
|
||
private static final Gson gson = new Gson(); | ||
@Override | ||
public String serialize(Object value) { | ||
return gson.toJson(value); | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(String data, Class<T> target) { | ||
return gson.fromJson(data, target); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...re-functions/src/main/resources/META-INF/services/com.microsoft.durabletask.DataConverter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.functions.converter.MyConverter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why you can't use a regular
Boolean
here? Since we're already in asynchronized
block, I wouldn't expect that you'd need to use any additional synchronization primitives.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use a regular
Boolean
in java, I need to declare it withvolatile
which avoids using thread cache, that means that when a thread modifies the value of thisBoolean
, all other threads will see the updated value when they access it in Java. So I am thinking of just using AtomicBoolean which provides both visibility and atomicity at the same time.