reactive-zmq


License

License

Categories

Categories

React User Interface Web Frameworks
GroupId

GroupId

io.github.2gis
ArtifactId

ArtifactId

reactive-zmq_2.12
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

reactive-zmq
reactive-zmq
Project URL

Project URL

https://github.com/2gis/reactive-zmq
Project Organization

Project Organization

io.github.2gis
Source Code Management

Source Code Management

https://github.com/2gis/reactive-zmq

Download reactive-zmq_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.2gis/reactive-zmq_2.12/ -->
<dependency>
    <groupId>io.github.2gis</groupId>
    <artifactId>reactive-zmq_2.12</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.2gis/reactive-zmq_2.12/
implementation 'io.github.2gis:reactive-zmq_2.12:0.5.0'
// https://jarcasting.com/artifacts/io.github.2gis/reactive-zmq_2.12/
implementation ("io.github.2gis:reactive-zmq_2.12:0.5.0")
'io.github.2gis:reactive-zmq_2.12:jar:0.5.0'
<dependency org="io.github.2gis" name="reactive-zmq_2.12" rev="0.5.0">
  <artifact name="reactive-zmq_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.2gis', module='reactive-zmq_2.12', version='0.5.0')
)
libraryDependencies += "io.github.2gis" % "reactive-zmq_2.12" % "0.5.0"
[io.github.2gis/reactive-zmq_2.12 "0.5.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.3
com.typesafe.akka : akka-actor_2.12 jar 2.5.4
com.typesafe.akka : akka-stream_2.12 jar 2.5.4
org.zeromq : jeromq jar 0.4.3

test (5)

Group / Artifact Type Version
org.mockito : mockito-core jar 2.8.47
org.scalatest : scalatest_2.12 jar 3.0.1
com.typesafe.akka : akka-testkit_2.12 jar 2.5.4
com.typesafe.akka : akka-stream-testkit_2.12 jar 2.5.4
org.scalacheck : scalacheck_2.12 jar 1.13.5

Project Modules

There are no modules declared in this project.

Reactive ZMQ

This is akka-stream API for zmq. Currently it only supports receiving data via unidirectional ZMQ sockets of types:

  • ZMQ.PULL
  • ZMQ.SUB

Build Status Maven Central Coverage Status

Supported Scala versions

  • Scala 2.11.11+
  • Scala 2.12.3+

ZMQ compatibility

See jeromq documentation.

30 seconds start

Add the following settings to your build.sbt:

libraryDependencies += "io.github.2gis" %% "reactive-zmq" % "0.5.0"

Create zmq context and Source:

import org.zeromq.ZMQ
val context = ZMQ.context(1)
val source = ZMQSource(context,
  mode = ZMQ.PULL,
  timeout = 1 second,
  addresses = List("tcp://127.0.0.1:12345")
)

Now you may use source in your graphs:

implicit val as = ActorSystem()
implicit val m = ActorMaterializer()
source
  .map { x: ByteString => println(x); x }
  .to(Sink.ignore)
  .run()

Full example is available here

Stopping

To stop the Source you should use the materialized Control object:

val (control, finish) = source
  .map { x: ByteString => println(x); x }
  .toMat(Sink.ignore)(Keep.both)
  .run()

The Control object exposes a gracefulStop method that closes an underlying ZMQ socket and completes the Source:

val stopFuture: Future[Unit] = control.gracefulStop()

implicit val ec = as.dispatcher
Future.sequence(Seq(stopFuture, finish)).onComplete { _ =>
  as.terminate()
  context.close()
}

Bleeding edge

Add the following settings to your build.sbt to use a SNAPSHOT version:

resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "io.github.2gis" %% "reactive-zmq" % "0.6.0-SNAPSHOT"
io.github.2gis

2GIS

Versions

Version
0.5.0