Skip to content

Commit

Permalink
chore: Transformation.identity vs empty
Browse files Browse the repository at this point in the history
* fail fast
  • Loading branch information
patriknw committed Aug 28, 2023
1 parent 8bd1d60 commit b3344c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ import com.google.protobuf.timestamp.Timestamp
import io.grpc.Status
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import scala.concurrent.Future

import akka.projection.grpc.producer.scaladsl.EventProducer.Transformation

/**
* INTERNAL API
*/
Expand Down Expand Up @@ -78,6 +79,10 @@ import scala.concurrent.Future
eventsBySlicesPerStreamId.contains(s.streamId) ||
eventsBySlicesStartingFromSnapshotsPerStreamId.contains(s.streamId),
s"No events by slices query defined for stream id [${s.streamId}]")
require(
s.transformation ne Transformation.empty,
s"Transformation is not defined for stream id [${s.streamId}]. " +
"Use Transformation.identity to pass through each event as is.")
}

private val protoAnySerialization = new ProtoAnySerialization(system)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ object EventProducer {
val empty: Transformation = new Transformation(
mappers = Map.empty,
orElse = envelope =>
Future.failed(new IllegalArgumentException(s"Missing transformation for event [${envelope.event.getClass}]")))
Future.failed(
new IllegalArgumentException(
s"Missing transformation for event [${envelope.event.getClass}]. " +
"Use Transformation.identity to pass through each event as is.")))

/**
* No transformation. Pass through each event as is.
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/paradox/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Java

To omit an event the transformation function can return @scala[`None`]@java[`Optional.empty()`].

Use @scala[`Transformation.identity`]@java[`Transformation.identity()`] to pass through each event as is.

That `EventProducer` service is started in an Akka gRPC server like this:

Scala
Expand Down

0 comments on commit b3344c0

Please sign in to comment.