Created
May 15, 2015 11:45
-
-
Save pjazdzewski1990/59d00735c6d3532e690e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val connection = Connection() | |
val exchange = Exchange(exchangeName, Headers, durable = false) | |
connection.exchangeDeclare(exchange) onComplete { | |
case Success(_) => | |
Source[GameEvent](EventPublisherActor.props) | |
.map(toMessage) | |
.to(Sink(connection.publish(exchange = exchangeName, ""))) | |
.run()(ActorFlowMaterializer()) | |
case Failure(ex) => | |
log.error("Cannot create exchange", ex) | |
sys.exit(1) | |
} | |
def toMessage(event: GameEvent) = { | |
val serialized = compact(render(Extraction.decompose(event))) | |
Message( | |
body = ByteString(serialized), | |
contentType = Some(MediaType.JSON_UTF_8), | |
contentEncoding = Some("UTF-8"), | |
headers = Map( | |
"gameId" -> event.id.value, | |
"type" -> event.getClass.getSimpleName)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment