akka-stream-extensions


License

License

Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

com.github.dnvriend
ArtifactId

ArtifactId

akka-stream-extensions_2.11
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

akka-stream-extensions
akka-stream-extensions
Project URL

Project URL

https://github.com/dnvriend/akka-stream-extensions
Project Organization

Project Organization

com.github.dnvriend
Source Code Management

Source Code Management

https://github.com/dnvriend/akka-stream-extensions

Download akka-stream-extensions_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.dnvriend/akka-stream-extensions_2.11/ -->
<dependency>
    <groupId>com.github.dnvriend</groupId>
    <artifactId>akka-stream-extensions_2.11</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.dnvriend/akka-stream-extensions_2.11/
implementation 'com.github.dnvriend:akka-stream-extensions_2.11:0.0.2'
// https://jarcasting.com/artifacts/com.github.dnvriend/akka-stream-extensions_2.11/
implementation ("com.github.dnvriend:akka-stream-extensions_2.11:0.0.2")
'com.github.dnvriend:akka-stream-extensions_2.11:jar:0.0.2'
<dependency org="com.github.dnvriend" name="akka-stream-extensions_2.11" rev="0.0.2">
  <artifact name="akka-stream-extensions_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.dnvriend', module='akka-stream-extensions_2.11', version='0.0.2')
)
libraryDependencies += "com.github.dnvriend" % "akka-stream-extensions_2.11" % "0.0.2"
[com.github.dnvriend/akka-stream-extensions_2.11 "0.0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8
org.scala-lang.modules : scala-xml_2.11 jar 1.0.5
com.typesafe.akka : akka-stream_2.11 jar 2.4.9
org.scalaz : scalaz-core_2.11 jar 7.2.5
commons-io : commons-io jar 2.5

provided (2)

Group / Artifact Type Version
org.scoverage : scalac-scoverage-runtime_2.11 jar 1.1.1
org.scoverage : scalac-scoverage-plugin_2.11 jar 1.1.1

test (5)

Group / Artifact Type Version
com.typesafe.akka : akka-slf4j_2.11 jar 2.4.9
ch.qos.logback : logback-classic jar 1.1.7
com.typesafe.akka : akka-stream-testkit_2.11 jar 2.4.9
com.typesafe.akka : akka-testkit_2.11 jar 2.4.9
org.scalatest : scalatest_2.11 jar 2.2.6

Project Modules

There are no modules declared in this project.

akka-stream-extensions

Build Status Download Codacy Badge License

Non-official extension library for akka-stream that contains operations like zipWithIndex, Source.fromTry and so on

Installation

Add the following to your build.sbt:

resolvers += Resolver.jcenterRepo

libraryDependencies += "com.github.dnvriend" %% "akka-stream-extensions" % "0.0.1"

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

License

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

akka.stream.scaladsl.extension.io.DigestCalculator

Given a stream of ByteString, it calculates a digest given a certain Algorithm.

akka.stream.scaladsl.extension.io.FileUtils

A stage that does file operations. Very handy for stream processing file operations.

akka.stream.scaladsl.extension.xml.Validation

Given a stream of ByteString, it validates an XML file given an XSD.

akka.stream.scaladsl.extension.xml.XMLEventSource

Given an inputstream or filename, it creates a Source[XMLEvent, NotUsed] that can be used to process an XML file. It can be used together with akka-stream's processing stages and the akka.persistence.query.extension.Journal to store the transformed messages in the journal to be consumed by other components. It can also be used with reactive-activemq's akka.stream.scaladsl.extension.activemq.ActiveMqProducer to send these messages to a VirtualTopic.

akka.stream.scaladsl.extension.xml.XMLParser

It should be easy to write XML parsers to process large XML files efficiently. Most often this means reading the XML sequentially, parsing a known XML fragment and converting it to DTOs using case classes. For such a use case the akka.stream.scaladsl.extension.xml.XMLParser should help you get you up and running fast!

For example, let's process the following XML:

<orders>
    <order id="1">
        <item name="Pizza" price="12.00">
            <pizza>
                <crust type="thin" size="14"/>
                <topping>cheese</topping>
                <topping>sausage</topping>
            </pizza>
        </item>
        <item name="Breadsticks" price="4.00"/>
        <tax type="federal">0.80</tax>
        <tax type="state">0.80</tax>
        <tax type="local">0.40</tax>
    </order>
</orders>

Imagine we are interested in only orders, and only the tax, lets write two parsers:

import scala.xml.pull._
import akka.stream.scaladsl._
import akka.stream.scaladsl.extension.xml.XMLParser
import akka.stream.scaladsl.extension.xml.XMLParser._
import akka.stream.scaladsl.extension.xml.XMLEventSource

case class Order(id: String)

val orderParser: Flow[XMLEvent, Order] = {
 var orderId: String = null
 XMLParser.flow {
  case EvElemStart(_, "order", meta, _) 
    orderId = getAttr(meta)("id"); emit()
  case EvElemEnd(_, "order") 
    emit(Order(orderId))
 }
}

case class Tax(taxType: String, value: String)

val tagParser: Flow[XMLEvent, Tax] = {
  var taxType: String = null
  var taxValue: String = null
  XMLParser.flow {
    case EvElemStart(_, "tax", meta, _) =>
      taxType = getAttr(meta)("type"); emit()
    case EvText(text) 
      taxValue = text; emit()
    case EvElemEnd(_, "tax") 
      emit(Tax(taxType, taxValue))
  }
}

XMLEventSource.fromFileName("orders.xml")
 .via(orderParser).runForeach(println)

XMLEventSource.fromFileName("orders.xml")
 .via(tagParser).runForeach(println)

For a more complex example, please take a look at akka.stream.scaladsl.extension.xml.PersonParser in the test package of this library.

  • v0.0.1 (2016-07-23)
    • Initial release

Have fun!

Versions

Version
0.0.2