Skip to content

Commit

Permalink
fix: removing infinite subscription loop (#2174)
Browse files Browse the repository at this point in the history
  • Loading branch information
aludwiko authored Jul 12, 2024
1 parent 56aed6a commit d3b00bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/src/modules/java/pages/actions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ The class `DoubleCounterAction` listens to the counter state changes. When the c
----
include::example$java-spring-valueentity-counter/src/main/java/com/example/action/DoubleCounterAction.java[tag=controller-side-effect]
----
<1> Retrieving the id of the counter.
<1> Exposing dedicated endpoint.
<2> On incoming request, doubling the value of `increase`.
<3> Building a reply using `Confirmed.getDefaultInstance()`. And attaching a side effect, i.e. calling to the `Counter` to increase double the previous amount.
<3> Building a reply and attaching a side effect, i.e. calling to the `Counter` to increase double the previous amount.

NOTE: the response of the side effect is ignored by the command meaning that even if the deferred call to
the `Counter` entity fails, the `Action` reply will succeed.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import kalix.javasdk.action.Action;
import com.example.Number;
import kalix.javasdk.client.ComponentClient;
import kalix.javasdk.annotations.Subscribe;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;


@Subscribe.ValueEntity(CounterEntity.class)
public class DoubleCounterAction extends Action {

final private ComponentClient componentClient;
Expand All @@ -18,13 +18,13 @@ public DoubleCounterAction(ComponentClient componentClient) {
}

// tag::controller-side-effect[]
public Action.Effect<Confirmed> increaseWithSideEffect(Integer increase) {
var counterId = actionContext().eventSubject().get(); // <1>
var doubleIncrease = increase * 2; // <2>
@PostMapping("/counter/{counterId}/double-increase/{value}") // <1>
public Action.Effect<String> increaseWithSideEffect(@PathVariable String counterId, @PathVariable int value) {
var doubleIncrease = value * 2; // <2>
var deferredCall = componentClient.forValueEntity(counterId)
.call(CounterEntity::increaseBy)
.params(new Number(doubleIncrease));
return effects().reply(Confirmed.instance).addSideEffect(SideEffect.of(deferredCall)); // <3>
return effects().reply("ok").addSideEffect(SideEffect.of(deferredCall)); // <3>
}
// end::controller-side-effect[]
}

0 comments on commit d3b00bc

Please sign in to comment.