Skip to content

Commit

Permalink
Replace Akka with Pekko
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Jun 2, 2023
1 parent b816e19 commit 6e11d69
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 107 deletions.
8 changes: 0 additions & 8 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
updatePullRequests = "always"

# https://www.lightbend.com/blog/why-we-are-changing-the-license-for-akka
updates.pin = [{ groupId = "com.typesafe.akka", version = "2.6." }]
updates.ignore = [
{ groupId = "com.typesafe.akka" },
{ groupId = "com.lightbend.akka" },
{ groupId = "com.lightbend.akka.grpc" }
]
73 changes: 28 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,75 @@
[![Join at Gitter][gitter-img]][gitter]
[![Apache License][license-img]][license]

# Akka Streams Json Support
# Pekko Streams Circe Support

This library provides Json support for stream based applications using [jawn](https://github.com/non/jawn)
as a parser. It supports all backends that jawn supports with support for [circe](https://github.com/travisbrown/circe) provided as a example.

## Differences with [akka-stream-json](https://github.com/knutwalker/akka-stream-json)

This is a fork of [akka-stream-json](https://github.com/knutwalker/akka-stream-json) since it no longer
appears to be maintained. Hence the main differences between akka-stream-json and this project is.

* The project is called akka-streams-json rather than akka-stream-json. This is
just to differentiate the git repos and project names.
* This project aims to be updated to the latest versions of akka/akka-http/circe
as frequent as possible. PR's are also welcome to maintain the project
* We use [ScalaTest](http://www.scalatest.org/) rather then [Specs2](https://etorreborre.github.io/specs2/) for testing.
This is because ScalaTest has better `Future` support compared to Specs2
(in order to do tests against `Future` in Specs2 you have to block on the `Future`
which degrades performance a lot).

Apart from this, the actual initial code/implementation is exactly the same as the fork, the only difference
being the package names (i.e. using `org.mdedetrich` rather than `de.knutwalker`). The following contents of
README.md was also mainly copied from the original repo.
It is a fork of [akka-streams-json](https://github.com/mdedetrich/akka-streams-json) built with [Apache Pekko](https://pekko.apache.org/).
[akka-streams-json](https://github.com/mdedetrich/akka-streams-json) which is in itself a fork of
https://github.com/knutwalker/akka-stream-json.

## Installation

There are two main modules, `akka-stream-json` and `akka-http-json`.
`akka-stream-json` is the basis and provides the stream-based parser while
`akka-http-json` enabled support to use the desired json library as an Unmarshaller.
There are two main modules, `pekko-stream-json` and `pekko-http-json`.
`pekko-stream-json` is the basis and provides the stream-based parser while
`pekko-http-json` enabled support to use the desired json library as an Unmarshaller.


```
libraryDependencies ++= List(
"org.mdedetrich" %% "akka-stream-json" % "0.8.2",
"org.mdedetrich" %% "akka-http-json" % "0.8.2"
"org.mdedetrich" %% "pekko-stream-json" % <VERSION>,
"org.mdedetrich" %% "pekko-http-json" % <VERSION>"
)
```

`akka-streams-json` depends on `jawn-parser` at version `1.0.0` for the `0.7.x` series
The circe submodule depends on version `0.13.x` of `circe-jawn` for `0.7.x` series

`akka-stream-json` is published for Scala 2.13 and 2.12.
`pekko-stream-circe` is published for Scala 2.13 and 2.12.

## Usage

The parser lives at `org.mdedetrich.akka.json.stream.JsonStreamParser`
The parser lives at `org.mdedetrich.pekko.json.stream.JsonStreamParser`

Use one of the constructor methods in the companion object to create the parser at
various levels of abstraction, either a Stage, a Flow, or a Sink.
You just add the [jawn support facade](https://github.com/non/jawn#supporting-external-asts-with-jawn)
of your choice and you will can parsed into their respective Json AST.


For Http support, either `import org.mdedetrich.akka.http.JsonSupport._`
or mixin `... with org.mdedetrich.akka.http.JsonSupport`.
For Http support, either `import org.mdedetrich.pekko.http.JsonSupport._`
or mixin `... with org.mdedetrich.pekko.http.JsonSupport`.

Given an implicit jawn facade, this enable you to decode into the respective Json AST
using the Akka HTTP marshalling framework. As jawn is only about parsing and does not abstract
using the Pekko HTTP marshalling framework. As jawn is only about parsing and does not abstract
over rendering, you'll only get an Unmarshaller.


### Circe

```
libraryDependencies ++= List(
"org.mdedetrich" %% "akka-stream-circe" % "0.8.2",
"org.mdedetrich" %% "akka-http-circe" % "0.8.2"
"org.mdedetrich" %% "pekko-stream-circe" % "<VERSION>",
"org.mdedetrich" %% "pekko-http-circe" % "<VERSION>"
)
```

(Using circe 0.14.x)

Adding support for a specific framework is
[quite](support/stream-circe/src/main/scala/org/mdedetrich/akka/stream/support/CirceStreamSupport.scala)
[easy](support/http-circe/src/main/scala/org/mdedetrich/akka/http/support/CirceHttpSupport.scala).
[quite](support/stream-circe/src/main/scala/org/mdedetrich/pekko/stream/support/CirceStreamSupport.scala)
[easy](support/http-circe/src/main/scala/org/mdedetrich/pekko/http/support/CirceHttpSupport.scala).

These support modules allow you to directly marshall from/unmarshall into your data types
using circes `Decoder` and `Encoder` type classes.

Just mixin or import `org.mdedetrich.akka.http.support.CirceHttpSupport` for Http
or pipe your `Source[ByteString, _].via(org.mdedetrich.akka.stream.CirceStreamSupport.decode[A])`
Just mixin or import `org.mdedetrich.pekko.http.support.CirceHttpSupport` for Http
or pipe your `Source[ByteString, _].via(org.mdedetrich.pekko.stream.CirceStreamSupport.decode[A])`
to get a `Source[A, _]`.

This flow even supports parsing multiple json documents in whatever
fragmentation they may arrive, which is great for consuming stream/sse based APIs.

If there is an error in parsing the Json you can catch `org.mdedetrich.akka.http.support.CirceStreamSupport.JsonParsingException`.
If there is an error in parsing the Json you can catch `org.mdedetrich.pekko.http.support.CirceStreamSupport.JsonParsingException`.
The exception provides Circe cursor history, current cursor and the type hint of the error.

## Why jawn?
Expand All @@ -104,14 +87,14 @@ using directly the underlying ByteBuffers without conversion.

This code is open source software licensed under the Apache 2.0 License.

[ci-img]: https://github.com/mdedetrich/akka-streams-json/actions/workflows/ci.yml/badge.svg?branch=main
[coverage-img]: https://coveralls.io/repos/github/mdedetrich/akka-streams-json/badge.svg?branch=main
[maven-img]: https://img.shields.io/maven-central/v/org.mdedetrich/akka-stream-json_2.12.svg?label=latest
[ci-img]: https://github.com/mdedetrich/pekko-streams-circe/actions/workflows/ci.yml/badge.svg?branch=main
[coverage-img]: https://coveralls.io/repos/github/mdedetrich/pekko-streams-circe/badge.svg?branch=main
[maven-img]: https://img.shields.io/maven-central/v/org.mdedetrich/pekko-stream-json_2.12.svg?label=latest
[gitter-img]: https://img.shields.io/badge/gitter-Join_Chat-1dce73.svg
[license-img]: https://img.shields.io/badge/license-APACHE_2-green.svg

[ci]: https://github.com/mdedetrich//akka-streams-json/actions/workflows/ci.yml?query=branch%3Amain
[coverage]: https://coveralls.io/github/mdedetrich/akka-streams-json?branch=main
[maven]: http://search.maven.org/#search|ga|1|g%3A%22org.mdedetrich%22%20AND%20%28a%3Aakka-stream-*_2.11%20OR%20a%3Aakka-http-*_2.11%20OR%20a%3Aakka-stream-*_2.12%20OR%20a%3Aakka-http-*_2.12%29
[gitter]: https://gitter.im/mdedetrich/akka-streams-json?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[ci]: https://github.com/mdedetrich/pekko-streams-circe/actions/workflows/ci.yml?query=branch%3Amain
[coverage]: https://coveralls.io/github/mdedetrich/pekko-streams-circe?branch=main
[maven]: http://search.maven.org/#search|ga|1|g%3A%22org.mdedetrich%22%20AND%20%28a%3Apekko-stream-*_2.11%20OR%20a%3Apekko-http-*_2.11%20OR%20a%3Apekko-stream-*_2.12%20OR%20a%3Apekko-http-*_2.12%29
[gitter]: https://gitter.im/mdedetrich/pekko-streams-circe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[license]: https://www.apache.org/licenses/LICENSE-2.0
34 changes: 18 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import com.jsuereth.sbtpgp.PgpKeys.publishSigned

name := "akka-streams-json"
name := "pekko-streams-circe"

val scala213Version = "2.13.10"
val scala212Version = "2.12.17"

ThisBuild / resolvers += Resolver.ApacheMavenSnapshotsRepo

val circeVersion = "0.14.5"
val akkaVersion = "2.6.20"
val akkaHttpVersion = "10.2.10"
val pekkoVersion = "0.0.0+26669-ec5b6764-SNAPSHOT"
val pekkoHttpVersion = "0.0.0+4411-6fe04045-SNAPSHOT"
val jawnVersion = "1.5.0"
val scalaTestVersion = "3.2.16"

Expand All @@ -20,30 +22,30 @@ ThisBuild / versionScheme := Some(VersionScheme.EarlySemVer)
lazy val streamJson = project
.in(file("stream-json"))
.settings(
name := "akka-stream-json",
name := "pekko-stream-json",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided,
"org.apache.pekko" %% "pekko-stream" % pekkoVersion % Provided,
"org.typelevel" %% "jawn-parser" % jawnVersion
)
)

lazy val httpJson = project
.in(file("http-json"))
.settings(
name := "akka-http-json",
name := "pekko-http-json",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided
"org.apache.pekko" %% "pekko-stream" % pekkoVersion % Provided,
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion % Provided
)
)
.dependsOn(streamJson)

lazy val streamCirce = project
.in(file("support") / "stream-circe")
.settings(
name := "akka-stream-circe",
name := "pekko-stream-circe",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided,
"org.apache.pekko" %% "pekko-stream" % pekkoVersion % Provided,
"io.circe" %% "circe-jawn" % circeVersion
)
)
Expand All @@ -52,9 +54,9 @@ lazy val streamCirce = project
lazy val httpCirce = project
.in(file("support") / "http-circe")
.settings(
name := "akka-http-circe",
name := "pekko-http-circe",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion % Provided
)
)
.dependsOn(streamCirce, httpJson)
Expand All @@ -75,8 +77,8 @@ lazy val tests = project
.settings(
libraryDependencies ++=
List(
"com.typesafe.akka" %% "akka-stream" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Test,
"org.apache.pekko" %% "pekko-stream" % pekkoVersion % Test,
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion % Test,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test,
"io.circe" %% "circe-generic" % circeVersion % Test
),
Expand All @@ -103,10 +105,10 @@ Defaults.itSettings

configs(IntegrationTest)

ThisBuild / homepage := Some(url("https://github.com/mdedetrich/akka-streams-json"))
ThisBuild / homepage := Some(url("https://github.com/mdedetrich/pekko-streams-circe"))

ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/mdedetrich/akka-streams-json"), "[email protected]:mdedetrich/akka-streams-json.git")
ScmInfo(url("https://github.com/mdedetrich/pekko-streams-circe"), "[email protected]:mdedetrich/pekko-streams-circe.git")
)

ThisBuild / developers := List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* limitations under the License.
*/

package org.mdedetrich.akka.http
package org.mdedetrich.pekko.http

import akka.http.scaladsl.model.HttpEntity
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import akka.http.scaladsl.util.FastFuture
import org.mdedetrich.akka.json.stream.JsonStreamParser
import org.apache.pekko
import pekko.http.scaladsl.model.HttpEntity
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import pekko.http.scaladsl.util.FastFuture
import org.mdedetrich.pekko.json.stream.JsonStreamParser
import org.typelevel.jawn.Facade

trait JsonSupport {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.3
sbt.version=1.9.0-RC3
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
* limitations under the License.
*/

package org.mdedetrich.akka.json.stream

import akka.NotUsed
import akka.stream.Attributes.name
import akka.stream.scaladsl.{Flow, Keep, Sink}
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import akka.stream._
import akka.util.ByteString
package org.mdedetrich.pekko.json.stream

import org.apache.pekko
import pekko.NotUsed
import pekko.stream.Attributes.name
import pekko.stream.scaladsl.{Flow, Keep, Sink}
import pekko.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import pekko.stream._
import pekko.util.ByteString
import org.typelevel.jawn.AsyncParser.ValueStream
import org.typelevel.jawn._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* limitations under the License.
*/

package org.mdedetrich.akka.http.support
package org.mdedetrich.pekko.http.support

import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import org.apache.pekko
import pekko.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import io.circe.jawn.CirceSupportParser._
import io.circe.{Decoder, Encoder, Json, Printer}

import org.mdedetrich.akka.http.JsonSupport
import org.mdedetrich.akka.stream.support.CirceStreamSupport
import org.mdedetrich.pekko.http.JsonSupport
import org.mdedetrich.pekko.stream.support.CirceStreamSupport

trait CirceHttpSupport extends JsonSupport {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* limitations under the License.
*/

package org.mdedetrich.akka.stream
package org.mdedetrich.pekko.stream
package support

import akka.NotUsed
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import org.apache.pekko
import pekko.NotUsed
import pekko.stream.scaladsl.Flow
import pekko.util.ByteString
import io.circe.CursorOp.DownField
import io.circe.jawn.CirceSupportParser._
import io.circe._
import org.mdedetrich.akka.json.stream.JsonStreamParser
import org.mdedetrich.pekko.json.stream.JsonStreamParser
import org.typelevel.jawn.AsyncParser

trait CirceStreamSupport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
* limitations under the License.
*/

package org.mdedetrich.akka.http

import akka.actor.ActorSystem
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model.HttpCharsets.`UTF-8`
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.model.{HttpEntity, RequestEntity, UniversalEntity}
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.scaladsl.{Keep, Sink, Source}
import akka.util.ByteString
package org.mdedetrich.pekko.http

import org.apache.pekko
import pekko.actor.ActorSystem
import pekko.http.scaladsl.marshalling.Marshal
import pekko.http.scaladsl.model.HttpCharsets.`UTF-8`
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.model.{HttpEntity, RequestEntity, UniversalEntity}
import pekko.http.scaladsl.unmarshalling.Unmarshal
import pekko.stream.scaladsl.{Keep, Sink, Source}
import pekko.util.ByteString
import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder, Printer}
import org.mdedetrich.akka.http.support.CirceHttpSupport
import org.mdedetrich.akka.stream.support.CirceStreamSupport
import org.mdedetrich.pekko.http.support.CirceHttpSupport
import org.mdedetrich.pekko.stream.support.CirceStreamSupport
import org.scalatest._
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
Expand Down

0 comments on commit 6e11d69

Please sign in to comment.