Created
June 29, 2017 06:17
-
-
Save anonymous/f255a18830b2d7074831d2a8fd81c1bf to your computer and use it in GitHub Desktop.
the description for this gist
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
def createSimple( | |
connection: Connection, | |
exchange: String | |
): Consumer[OutboundMessage, Unit] = | |
Consumer.fromObserver { s => | |
new Observer[OutboundMessage] { | |
val ch = connection.createChannel() | |
val properties = new AMQP.BasicProperties() | |
def publish(m: OutboundMessage) = | |
ch.basicPublish(exchange, m.routingKey, properties, m.body) | |
def onNext(m: OutboundMessage): Future[Ack] = | |
Future { | |
blocking(publish(m)) | |
Continue | |
}(s) | |
def onError(ex: Throwable): Unit = abort() | |
def onComplete(): Unit = abort() | |
private def abort(): Unit = if (ch.isOpen) ch.abort() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment