Skip to content

Instantly share code, notes, and snippets.

@terjesb
Created March 16, 2011 11:12
Show Gist options
  • Save terjesb/872334 to your computer and use it in GitHub Desktop.
Save terjesb/872334 to your computer and use it in GitHub Desktop.
Using Akka AMQP to publish tasks to Octobot
import akka.amqp._
import akka.amqp.AMQP._
import akka.util.Logging
object TacoProducer extends Logging {
val connection = AMQP.newConnection()
val exchangeParameters = ExchangeParameters("tacotruck", Direct,
ActiveDeclaration(durable=true, autoDelete=false))
def run() {
// == Producer
val producer = AMQP.newProducer(connection,
ProducerParameters(Some(exchangeParameters), Some("my-producer")))
for (i <- 1 to 5) {
val message = """{"task": "com.example.tasks.TacoTask", "payload": "taco", "retries":0}"""
producer ! Message((message).getBytes, "tacotruck")
Thread.sleep(100)
}
}
}
package com.example.tasks
import org.apache.log4j.Logger
import org.json.simple.JSONObject
object TacoTask {
val log = Logger.getLogger("TacoTask")
def run(task: JSONObject) {
val payload = task.get("payload")
log.info("OMG, GOT A SCALA TACO: " + payload)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment