-
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
- Loading branch information
Showing
16 changed files
with
150 additions
and
114 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
18 changes: 11 additions & 7 deletions
18
...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,28 +1,32 @@ | ||
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 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); | ||
} | ||
|
||
} |
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.