-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: component client samples update (#1706)
* feat: component client samples update * reverting test changes * fixing sample code after rebase
- Loading branch information
Showing
16 changed files
with
133 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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 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
23 changes: 13 additions & 10 deletions
23
...eventsourced-counter/src/main/java/com/example/actions/CounterCommandFromTopicAction.java
This file contains 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 |
---|---|---|
@@ -1,35 +1,38 @@ | ||
package com.example.actions; | ||
|
||
import com.example.Counter; | ||
import kalix.javasdk.action.Action; | ||
import kalix.javasdk.annotations.Subscribe; | ||
import kalix.spring.KalixClient; | ||
import kalix.javasdk.client.ComponentClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Subscribe.Topic(value = "counter-commands", ignoreUnknown = true) | ||
public class CounterCommandFromTopicAction extends Action { | ||
|
||
public record IncreaseCounter(String counterId, int value) { } | ||
public record MultiplyCounter(String counterId, int value) { } | ||
public record IncreaseCounter(String counterId, int value) { | ||
} | ||
|
||
public record MultiplyCounter(String counterId, int value) { | ||
} | ||
|
||
private KalixClient kalixClient; | ||
private ComponentClient componentClient; | ||
|
||
public CounterCommandFromTopicAction(KalixClient kalixClient) { | ||
this.kalixClient = kalixClient; | ||
public CounterCommandFromTopicAction(ComponentClient componentClient) { | ||
this.componentClient = componentClient; | ||
} | ||
|
||
private Logger logger = LoggerFactory.getLogger(CounterCommandFromTopicAction.class); | ||
|
||
public Effect<String> onValueIncreased(IncreaseCounter increase) { | ||
logger.info("Received increase command: " + increase.toString()); | ||
var deferredCall = kalixClient.post("/counter/"+ increase.counterId + "/increase/" + increase.value, String.class); | ||
var deferredCall = componentClient.forEventSourcedEntity(increase.counterId).call(Counter::increase).params(increase.value); | ||
return effects().forward(deferredCall); | ||
} | ||
|
||
public Effect<String> onValueDecreased(MultiplyCounter increase) { | ||
public Effect<String> onValueMultiplied(MultiplyCounter increase) { | ||
logger.info("Received increase command: " + increase.toString()); | ||
var deferredCall = kalixClient.post("/counter/"+ increase.counterId + "/multiply/" + increase.value, String.class); | ||
var deferredCall = componentClient.forEventSourcedEntity(increase.counterId).call(Counter::multiply).params(increase.value); | ||
return effects().forward(deferredCall); | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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 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 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.