-
Notifications
You must be signed in to change notification settings - Fork 219
Adding remote endpoint request from inside activity with retry #1388
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
Merged
dapr-bot
merged 12 commits into
dapr:master
from
salaboy:1386-http-endpoint-from-workflow
May 31, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e318b0
adding remote endpoint request from inside activity with retry
salaboy 64e87af
adding retry with Microcks payloads
salaboy 4beeda4
fixing review comments
salaboy 69975b7
chore: New task execution task id test (#1352)
javier-aliaga 47b89d3
Revert "chore: New task execution task id test (#1352)" (#1389)
javier-aliaga db54d32
1.5.5 (#1390)
cicoyle c8eda7e
Add Documentation for Conversation AI SDK (#1387)
siri-varma 4917a44
Cleanup Spring Dependencies (#1334)
siri-varma 35e7b3a
network is needed
salaboy bf1f02d
Merge branch 'master' into 1386-http-endpoint-from-workflow
artur-ciocanu 721c4c4
Merge branch 'master' into 1386-http-endpoint-from-workflow
artur-ciocanu d6c6e42
Merge branch 'master' into 1386-http-endpoint-from-workflow
artur-ciocanu 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
51 changes: 51 additions & 0 deletions
51
.../main/java/io/dapr/springboot/examples/wfp/remoteendpoint/CallRemoteEndpointActivity.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,51 @@ | ||
/* | ||
* Copyright 2023 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.springboot.examples.wfp.remoteendpoint; | ||
|
||
import io.dapr.workflows.WorkflowActivity; | ||
import io.dapr.workflows.WorkflowActivityContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Component | ||
public class CallRemoteEndpointActivity implements WorkflowActivity { | ||
|
||
private Logger logger = LoggerFactory.getLogger(CallRemoteEndpointActivity.class); | ||
|
||
@Value("${application.process-base-url:}") | ||
private String processBaseURL; | ||
|
||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
|
||
@Override | ||
public Object run(WorkflowActivityContext ctx) { | ||
logger.info("Starting Activity: " + ctx.getName()); | ||
var payload = ctx.getInput(Payload.class); | ||
|
||
HttpEntity<Payload> request = | ||
new HttpEntity<>(payload); | ||
payload = restTemplate.postForObject(processBaseURL + "/process", request, Payload.class); | ||
|
||
logger.info("Payload from the remote service: " + payload); | ||
|
||
return payload; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...mples/workflows/src/main/java/io/dapr/springboot/examples/wfp/remoteendpoint/Payload.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,62 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.springboot.examples.wfp.remoteendpoint; | ||
|
||
public class Payload { | ||
private String id; | ||
private String content; | ||
private Boolean processed = false; | ||
|
||
public Payload(String id, String content) { | ||
this.id = id; | ||
this.content = content; | ||
} | ||
|
||
public Payload() { | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public Boolean getProcessed() { | ||
return processed; | ||
} | ||
|
||
public void setProcessed(Boolean processed) { | ||
this.processed = processed; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Payload{" + | ||
"id='" + id + '\'' + | ||
", content='" + content + '\'' + | ||
", processed=" + processed + | ||
'}'; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../src/main/java/io/dapr/springboot/examples/wfp/remoteendpoint/RemoteEndpointWorkflow.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,42 @@ | ||
/* | ||
* Copyright 2023 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.springboot.examples.wfp.remoteendpoint; | ||
|
||
import io.dapr.workflows.Workflow; | ||
import io.dapr.workflows.WorkflowStub; | ||
import io.dapr.workflows.WorkflowTaskOptions; | ||
import io.dapr.workflows.WorkflowTaskRetryPolicy; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Duration; | ||
|
||
@Component | ||
public class RemoteEndpointWorkflow implements Workflow { | ||
|
||
@Override | ||
public WorkflowStub create() { | ||
return ctx -> { | ||
ctx.getLogger().info("Starting Workflow: " + ctx.getName()); | ||
|
||
Payload payload = ctx.getInput(Payload.class); | ||
payload = ctx.callActivity(CallRemoteEndpointActivity.class.getName(), payload , | ||
new WorkflowTaskOptions(new WorkflowTaskRetryPolicy(5, | ||
Duration.ofSeconds(2), 1.0, Duration.ofSeconds(10), Duration.ofSeconds(20))), | ||
Payload.class).await(); | ||
|
||
ctx.getLogger().info("Workflow finished with result: " + payload); | ||
ctx.complete(payload); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.