Skip to content

Instantly share code, notes, and snippets.

@photex
Created November 12, 2012 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photex/4061895 to your computer and use it in GitHub Desktop.
Save photex/4061895 to your computer and use it in GitHub Desktop.
import akka.actor.ActorRef
import com.codahale.jerkson.Json.parse
import com.codahale.jerkson.ParsingException
import com.rabbitmq.client.{Channel, DefaultConsumer, Envelope}
import com.rabbitmq.client.AMQP.BasicProperties
class MsgConsumer(channel: Channel, target: ActorRef) extends DefaultConsumer(channel) {
override def handleDelivery(consumer_tag: String,
envelope: Envelope,
properties: BasicProperties,
body: Array[Byte])
{
val delivery_tag = envelope.getDeliveryTag
val body_text = new String(body)
try {
val msg = parse[Map[String, Any]](body_text)
target ! msg
channel.basicAck(delivery_tag, false)
} catch {
case e: ParsingException => {
channel.basicReject(delivery_tag, false)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment