ScalaConsultants / reactive-rabbit

Reactive Streams driver for AMQP protocol. Powered by RabbitMQ library.
Apache License 2.0
184 stars 40 forks source link

Reactive Streams: AMQP

Join the chat at https://gitter.im/ScalaConsultants/reactive-rabbit

Build Status

Reactive Streams driver for AMQP protocol. Powered by RabbitMQ library.

Available at Maven Central for Scala 2.11 and 2.12:

libraryDependencies += "io.scalac" %% "reactive-rabbit" % "1.1.4"

Example

Akka Streams - 2.4.12

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import io.scalac.amqp.Connection

// streaming invoices to Accounting Department
val connection = Connection()
// create org.reactivestreams.Publisher
val queue = connection.consume(queue = "invoices")
// create org.reactivestreams.Subscriber
val exchange = connection.publish(exchange = "accounting_department",
  routingKey = "invoices")

implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()
// Run akka-streams with queue as Source and exchange as Sink
Source.fromPublisher(queue).map(_.message).runWith(Sink.fromSubscriber(exchange))

API Docs

Run sbt doc and open target/scala-2.12/index.html.

Settings

There are 3 options for passing AMQP settings:

ConnectionSettings have following properties:

Connection

Connection trait API has two groups of methods: to manage AMQP infrastructure (ie. declare and delete exchanges, queues and bindings) and to create ReactiveStreams entities: Publisher and Subscriber.
consume(queue, prefetch) - creates Delivery stream Publisher for messages from queue.
publish(exchange, routingKey) - creates Subscription that takes stream of Message that will be sent to exchange with fixed routingKey.
publish(exchange) - creates Subscription for stream of Routed (tuple of Message and routing key).

Developed by Scalac