Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogdea committed Dec 27, 2019
1 parent 3bb228d commit dca5294
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
This implementation use the [reactivemongo drive](http://reactivemongo.org/).

## Installation
This plugin support scala `2.12` and `2.13`, akka `2.5.23` and reactivemongo `0.18.x` and `0.19.x`.
This plugin support scala `2.12` and `2.13`, akka `2.6.1` and reactivemongo `0.18.x` and `0.19.x`.

Add in your `build.sbt` the following lines:
```scala
resolvers += "Akka RactiveMongo Plugin" at "https://dl.bintray.com/null-vector/releases"
or
resolvers += Resolver.bintrayRepo("null-vector", "releases")

libraryDependencies += "null-vector" %% "akka-reactivemongo-plugin" % "1.2.6"
```
For reactivemongo `0.18.x` use:
```scala
libraryDependencies += "null-vector" %% "akka-reactivemongo-plugin" % "1.2.6"
libraryDependencies += "null-vector" %% "akka-reactivemongo-plugin" % "1.2.8"
```
For reactivemongo `0.19.x` use:
```scala
libraryDependencies += "null-vector" %% "akka-reactivemongo-plugin" % "1.3.0"
```


## Configuration
To active the plugin an set the mongodb uri you have to add in your application.conf the following lines:
```
Expand All @@ -45,16 +40,16 @@ Events adapters must extends from `org.nullvector.EventAdapter[E]`, for example:
```scala
class UserAddedEventAdapter extends EventAdapter[UserAdded] {

private val userAddedMapping: BSONDocumentHandler[UserAdded] = Macros.handler[UserAdded]
private implicit val userAddedMapping: BSONDocumentHandler[UserAdded] = Macros.handler[UserAdded]

override val manifest: String = "UserAdded"

override def payloadToBson(payload: UserAdded): BSONDocument = userAddedMapping.write(payload)
override def payloadToBson(payload: UserAdded): BSONDocument = BSON.writeDocument(payload).get

override def bsonToPayload(doc: BSONDocument): UserAdded = BSON.readDocument(doc).get

override def bsonToPayload(doc: BSONDocument): UserAdded = userAddedMapping.read(doc)
}
```

And then you have to register the new Adapter:
```scala
val serializer = ReactiveMongoEventSerializer(system)
Expand All @@ -78,22 +73,18 @@ akka-persistence-reactivemongo {

Here are some examples of how to use persistence query:
```scala

val readJournal = ReactiveMongoJournalProvider(system).scaladslReadJournal

val tagsSource: Source[EventEnvelope, NotUsed] = readJournal.currentEventsByTag("some_tag", NoOffset)

tagsSource.runWith(Sink.foreach{ envelope => envelope.event match {
case UserAdded(name, age) => // Do Something
}})

```

Sometime is necesary to create an Offset:
```scala

val offset = ObjectIdOffset(DateTime.now())

```
For streams that never complete like `#persistenceIds`, `#eventsByTag`, etc. it is possible to configure the interval that pulls from the journal:
```
Expand All @@ -104,7 +95,6 @@ akka-persistence-reactivemongo {
}
}
```

If you want different refresh intervals from different query, you can add a `RefreshInterval` Attribute in the Source definition:
```scala
readJournal
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/org/nullvector/query/PullerGraph.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.nullvector.query

import akka.NotUsed
import akka.persistence.query.{EventEnvelope, NoOffset, Offset}
import akka.stream.scaladsl.Source
import akka.stream.stage._
import akka.stream.{Attributes, Outlet, SourceShape}


import scala.concurrent.ExecutionContext
import scala.concurrent.duration.FiniteDuration

Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/org/nullvector/EventSerializerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ object EventSerializerSpec {

override def tags(payload: Any): Set[String] = Set("tag_1", "tag_2")

private val anEventMapper: BSONDocumentHandler[AnEvent] = Macros.handler[AnEvent]
private implicit val anEventMapper: BSONDocumentHandler[AnEvent] = Macros.handler[AnEvent]

override def payloadToBson(payload: AnEvent): BSONDocument = anEventMapper.writeTry(payload).get
override def payloadToBson(payload: AnEvent): BSONDocument = BSON.writeDocument(payload).get

override def bsonToPayload(doc: BSONDocument): AnEvent = anEventMapper.readDocument(doc).get
override def bsonToPayload(doc: BSONDocument): AnEvent = BSON.readDocument(doc).get
}

class SomeAkkaEventAdapter(system: ExtendedActorSystem) extends akka.persistence.journal.EventAdapter {
Expand Down

0 comments on commit dca5294

Please sign in to comment.