RecordIO Framing
The codec parses a ByteString stream in the RecordIO format used by Apache Mesos into distinct frames.
For instance, the response body:
128\n
{"type": "SUBSCRIBED","subscribed": {"framework_id": {"value":"12220-3440-12532-2345"},"heartbeat_interval_seconds":15.0}20\n
{"type":"HEARTBEAT"}
is parsed into frames:
{"type": "SUBSCRIBED","subscribed": {"framework_id": {"value":"12220-3440-12532-2345"},"heartbeat_interval_seconds":15.0}
{"type":"HEARTBEAT"}
[+] Show project infoProject Info: Alpakka Simple Codecs (RecordIO) | |
---|---|
Artifact | com.lightbend.akka
akka-stream-alpakka-simple-codecs
9.0.0
|
JDK versions | Eclipse Temurin JDK 11 Eclipse Temurin JDK 17 |
Scala versions | 2.13.12, 3.3.3 |
JPMS module name | akka.stream.alpakka.simplecodecs |
License | |
Readiness level |
Since 0.5, 2017-01-13
|
Home page | https://doc.akka.io/libraries/alpakka/current |
API documentation | |
Forums | |
Release notes | GitHub releases |
Issues | Github issues |
Sources | https://github.com/akka/alpakka |
Artifacts
The Akka dependencies are available from Akka’s library repository. To access them there, you need to configure the URL for this repository.
Additionally, add the dependencies as below.
- sbt
val AkkaVersion = "2.10.0" libraryDependencies ++= Seq( "com.lightbend.akka" %% "akka-stream-alpakka-simple-codecs" % "9.0.0", "com.typesafe.akka" %% "akka-stream" % AkkaVersion )
- Maven
- Gradle
The table below shows direct dependencies of this module and the second tab shows all libraries it depends on transitively.
- Direct dependencies
Organization Artifact Version com.typesafe.akka akka-stream_2.13 2.10.0 org.scala-lang scala-library 2.13.12 - Dependency tree
Usage
The flow factory RecordIOFraming
provides a scanner
factory method for a Flow<ByteString, ByteString, ?>
which parses out RecordIO frames.
- Scala
- Java
-
source
String firstRecordData = "{\"type\": \"SUBSCRIBED\",\"subscribed\": {\"framework_id\": {\"value\":\"12220-3440-12532-2345\"},\"heartbeat_interval_seconds\":15.0}"; String secondRecordData = "{\"type\":\"HEARTBEAT\"}"; String firstRecordWithPrefix = "121\n" + firstRecordData; String secondRecordWithPrefix = "20\n" + secondRecordData; Source<ByteString, NotUsed> basicSource = Source.single(ByteString.fromString(firstRecordWithPrefix + secondRecordWithPrefix)); CompletionStage<List<ByteString>> result = basicSource.via(RecordIOFraming.scanner()).runWith(Sink.seq(), system);
We obtain:
- Scala
- Java
-
source
List<ByteString> byteStrings = result.toCompletableFuture().get(1, TimeUnit.SECONDS); assertThat(byteStrings.get(0), is(ByteString.fromString(firstRecordData))); assertThat(byteStrings.get(1), is(ByteString.fromString(secondRecordData)));
Running the example code
The code in this guide is part of runnable tests of this project. You are welcome to edit the code and run it in sbt.
- Scala
-
sbt > simpleCodecs/testOnly *.RecordIOFramingSpec