README.md 1.21 KB
Newer Older
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
1
2
3
4
5
# Import Process Effects Registry

In its core, this library maps maintenance messages targeted at individual
services inside the import workflows to effects which should be applied on
receiving such messages. For that purpose it provides a `EffectsRegistry`
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
6
7
8
9
10
class. This utility class helps to register message patterns matching to a
certain effect. Messages have a `compare` method which is used to compare the
message pattern with the message currently processed by the application.
`Effect` is a case class requiring a name, an action which is performed upon a
message match, and an optional description. 
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
11
12
13
14

## Usage

```scala
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
15
16
17
18
import ch.memobase.{EffectsRegistry, Effect, ShutdownMessage}

val builder = ... // Set up KafkaStream
val inputTopic = ...
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
19
20

// `inputTopic` is the name of the topic where the maintenance message are
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
21
stored; props is a variable containing properties for the Kafka consumer
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
22
val registry = EffectsRegistry()
23
24
val shutdownEffect = Effect("shutdown", () => sys.exit(0), Some("shuts down
application"))
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
25
26
27
// the `register` method takes a message matcher as well as an instance of the
`Effect` case class
registry.register(ShutdownMessage, shutdownEffect)
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
28
// start to consume messages
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
29
registry.run(builder, inputTopic)
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
30
31

```