consul-akka-stream-integration-tests


License

License

Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

com.supersonic
ArtifactId

ArtifactId

consul-akka-stream-integration-tests_2.12
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

consul-akka-stream-integration-tests
consul-akka-stream-integration-tests
Project URL

Project URL

https://github.com/SupersonicAds/consul-akka-stream
Project Organization

Project Organization

com.supersonic
Source Code Management

Source Code Management

https://github.com/SupersonicAds/consul-akka-stream

Download consul-akka-stream-integration-tests_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.supersonic/consul-akka-stream-integration-tests_2.12/ -->
<dependency>
    <groupId>com.supersonic</groupId>
    <artifactId>consul-akka-stream-integration-tests_2.12</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.supersonic/consul-akka-stream-integration-tests_2.12/
implementation 'com.supersonic:consul-akka-stream-integration-tests_2.12:1.1.2'
// https://jarcasting.com/artifacts/com.supersonic/consul-akka-stream-integration-tests_2.12/
implementation ("com.supersonic:consul-akka-stream-integration-tests_2.12:1.1.2")
'com.supersonic:consul-akka-stream-integration-tests_2.12:jar:1.1.2'
<dependency org="com.supersonic" name="consul-akka-stream-integration-tests_2.12" rev="1.1.2">
  <artifact name="consul-akka-stream-integration-tests_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.supersonic', module='consul-akka-stream-integration-tests_2.12', version='1.1.2')
)
libraryDependencies += "com.supersonic" % "consul-akka-stream-integration-tests_2.12" % "1.1.2"
[com.supersonic/consul-akka-stream-integration-tests_2.12 "1.1.2"]

Dependencies

compile (7)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.5
com.supersonic : consul-akka-stream_2.12 jar 1.1.2
org.scalatest : scalatest_2.12 jar 3.0.4
com.typesafe.akka : akka-testkit_2.12 jar 2.5.7
com.typesafe.akka : akka-stream-testkit_2.12 jar 2.5.7
com.pszymczyk.consul : embedded-consul jar 1.0.1
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

Build Status Maven Central

consul-akka-stream

consul-akka-stream is a small utility that can listen to a Consul key in its key/value store and provide an Akka stream that emits a value every time the key is updated.

Getting consul-akka-stream

Add these lines you to your SBT project:

libraryDependencies += "com.supersonic" %% "consul-akka-stream" % "1.1.2"

How To

To create a stream we first need a Consul client, we use the Consul Client for Java library:

val consul =
  Consul.builder()
    .withReadTimeoutMillis(0L)
    .withHostAndPort(HostAndPort.fromParts("localhost", 8500))
    .build()

With this in hand, we can initialize an Akka-streams source based on the client using the ConsulStream.consulKeySource function:

val source: Source[Map[String, Option[String]], CancellationToken] = 
  ConsulStream.consulKeySource(key = "foo/baz/bar", consul, blockingTime = 1.seconds)

This creates an Akka source that listens to the foo/baz/bar key in Consul's key/value store. On every change to the key (including recursive changes) a new map is produced. The keys in the map are the Consul keys and the values are the (optional) strings under them.

An example output can be something like:

Map(
  "foo/baz/bar/qux" -> Some("a"), 
  "foo/baz/bar/goo" -> Some("b"), 
  "foo/baz/bar/bla" -> None)

The Source materializes into a CancellationToken token that can be triggered when the user wants to stop polling Consul.

See the tests for further examples.

Integration Tests

The library provides a trait that facilitates testing the Consul stream (with ScalaTest) using the Embedded Consul library.

To obtain the trait, add the following to your SBT project:

libraryDependencies += "com.supersonic" %% "consul-akka-stream-integration-tests" % "1.1.2" % "it"

And mixin the ConsulIntegrationSpec trait into your test.

com.supersonic

IronSource Mobile

Versions

Version
1.1.2
1.1.1