Created
March 16, 2011 11:12
-
-
Save terjesb/872334 to your computer and use it in GitHub Desktop.
Using Akka AMQP to publish tasks to Octobot
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
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) | |
} | |
} | |
} |
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
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