Scala client listening to a RabbitMQ queue.
Scala
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src/main
.gitignore
LICENSE
README.md
build.sbt

README.md

Scala RabbitMQ Example

This project is an example that combines

  • RabbitMQ client with Op-Rabbit
  • Akka actors
  • Akka supervision

Usage

You need to configure your own queue in application.conf:

op-rabbit {
  # exchange
  exchange = "amq.direct"

  # queue
  my-queue = "my-queue"

  # connection information
  connection {
    virtual-host = "xxxxxxx"
    hosts = ["x.y.w.z"]
    username = "yyyyyyy"
    password = "123456789"
    port = 5672
    timeout = 3s
  }
}

and then run the program with sbt run. The listener actor listens to the queue for object with the following Json structure:

{
  "name" : "a string",
  "version" : 1234
}

This is the code snipped that opens a connection and starts listening:

// initialize a queue subscription
myQueueSubscription = Some(
  Subscription.run(RABBIT_CONTROL) {
    channel(qos = 3) {
      consume(queue(QUEUE)) {
        body(as[MyObject]) {
          (obj) =>
            log.debug(s"received my object $obj")
            ack
        }
      }
    }
  }
)

License

Copyright 2016 Fabio Tiriticco / Fabway

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.