Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2017 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f255a18830b2d7074831d2a8fd81c1bf to your computer and use it in GitHub Desktop.
Save anonymous/f255a18830b2d7074831d2a8fd81c1bf to your computer and use it in GitHub Desktop.
the description for this gist
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