Skip to content

Commit 6baca09

Browse files
authored
Merge pull request #71 from uber/continueAsNew
Add continueAsNew mechanism to cadence java sample
2 parents d36e7d7 + b050013 commit 6baca09

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/uber/cadence/samples/spring/workflows/impl/SignalWorkflowImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.uber.cadence.samples.spring.models.SampleMessage;
44
import com.uber.cadence.samples.spring.workflows.SignalWorkflow;
55
import com.uber.cadence.workflow.Workflow;
6+
import java.util.Optional;
67
import org.slf4j.Logger;
78

89
public class SignalWorkflowImpl implements SignalWorkflow {
@@ -22,6 +23,16 @@ public void getGreeting(SampleMessage sampleMessage) {
2223
if (!this.greetingMsg.isEmpty()) {
2324
logger.info(++count + ": " + this.greetingMsg + "!");
2425
this.greetingMsg = "";
26+
27+
// A workflow execution cannot receive infinite number of signals due to history limit
28+
// By default 10000 is MaximumSignalsPerExecution which can be configured by DynamicConfig of Cadence cluster.
29+
// But it's recommended to do continueAsNew after receiving certain number of signals.
30+
// in production, use a number <1000.
31+
if (count == 3) {
32+
Workflow.continueAsNew(
33+
Optional.of("SignalWorkflow::getGreeting"), Optional.empty(), sampleMessage);
34+
return;
35+
}
2536
}
2637
}
2738

0 commit comments

Comments
 (0)