Skip to content

Commit 50bc3c9

Browse files
authored
feat: Access to component gRPC clients in actions and workflows (#2296)
* feat: Access to component gRPC clients in actions and workflows * formatting
1 parent d4fcf59 commit 50bc3c9

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

sdk/java-sdk-protobuf/src/main/java/kalix/javasdk/action/ActionCreationContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public interface ActionCreationContext extends Context {
2828
*/
2929
<T> T getGrpcClient(Class<T> clientClass, String service);
3030

31+
/**
32+
* Get an Akka gRPC client for the given component that is in the same service.
33+
*
34+
* <p>Lower level alternative to using the generated components. Prefer that when possible.
35+
*/
36+
<T> T getComponentGrpcClient(Class<T> componentServiceClass);
37+
3138
/**
3239
* Get an OpenTelemetry tracer for the current action. This will allow for building and automatic
3340
* exporting of spans.

sdk/java-sdk-protobuf/src/main/java/kalix/javasdk/workflow/WorkflowContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ public interface WorkflowContext extends Context {
2626
* `akka.grpc.client.[service-name]` in `application.conf`.
2727
*/
2828
<T> T getGrpcClient(Class<T> clientClass, String service);
29+
30+
/**
31+
* Get an Akka gRPC client for the given component that is in the same service.
32+
*
33+
* <p>Lower level alternative to using the generated components. Prefer that when possible.
34+
*/
35+
<T> T getComponentGrpcClient(Class<T> componentServiceClass);
2936
}

sdk/scala-sdk-protobuf/src/main/scala/kalix/scalasdk/action/ActionCreationContext.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ trait ActionCreationContext extends Context {
2323
*/
2424
def getGrpcClient[T](clientClass: Class[T], service: String): T
2525

26+
/**
27+
* Get an Akka gRPC client for the given component that is in the same service. <p> Lower level alternative to using
28+
* the generated components. Prefer that when possible.
29+
*/
30+
def getComponentGrpcClient[T](componentServiceClass: Class[T]): T
31+
2632
/**
2733
* Get an OpenTelemetry tracer for the current action. This will allow for building and automatic exporting of spans.
2834
*

sdk/scala-sdk-protobuf/src/main/scala/kalix/scalasdk/impl/action/ActionAdapters.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private[scalasdk] final case class ScalaActionCreationContextAdapter(
127127
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
128128
javaSdkCreationContext.getGrpcClient(clientClass, service)
129129

130+
override def getComponentGrpcClient[T](componentServiceClass: Class[T]): T =
131+
javaSdkCreationContext.getComponentGrpcClient(componentServiceClass)
132+
130133
override def materializer(): Materializer = javaSdkCreationContext.materializer()
131134

132135
override def getTracer: Tracer = javaSdkCreationContext.getTracer

sdk/scala-sdk-protobuf/src/main/scala/kalix/scalasdk/impl/workflow/WorkflowAdapters.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ private[scalasdk] final class ScalaWorkflowContextAdapter(javaSdkContext: javasd
217217
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
218218
javaSdkContext.getGrpcClient(clientClass, service)
219219

220+
override def getComponentGrpcClient[T](componentServiceClass: Class[T]): T =
221+
javaSdkContext.getComponentGrpcClient(componentServiceClass)
222+
220223
override def materializer(): Materializer = javaSdkContext.materializer()
221224

222225
override def workflowId: String = javaSdkContext.workflowId()

sdk/scala-sdk-protobuf/src/main/scala/kalix/scalasdk/workflow/WorkflowContext.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ trait WorkflowContext extends Context {
3030
*/
3131
def getGrpcClient[T](clientClass: Class[T], service: String): T
3232

33+
/**
34+
* Get an Akka gRPC client for the given component that is in the same service. <p> Lower level alternative to using
35+
* the generated components. Prefer that when possible.
36+
*/
37+
def getComponentGrpcClient[T](componentServiceClass: Class[T]): T
38+
3339
}

0 commit comments

Comments
 (0)