Skip to content

Instantly share code, notes, and snippets.

@timcharper
Created July 27, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcharper/7388cf7f35bb7c9ce968 to your computer and use it in GitHub Desktop.
Save timcharper/7388cf7f35bb7c9ce968 to your computer and use it in GitHub Desktop.
// psuedo-code; will not actually compile
import com.spingo.op_rabbit.Json4sSupport._ // allows you to use Json4s directly to serialize / deserialize published messages
trait MarketOrEv
case class Market(mkt_id: Int, ev_id: Int, model_type:”Market”) extends MarketOrEv
case class Ev(ev_id: Int, model_type:”Ev”) extends MarketOrEv
implicit val formats = new Formats(
override val typeHints = ShortTypeHints(classOf[Market] :: classOf[Ev] :: Nil)
override val typeHintFieldName = "model_type"
)
val subscription = new Subscription {
def config = channel(qos = 3) {
consume(queue(name)) {
body(as[MarketOrEv]) {
case m: Market =>
// do your thing...
ack
case e: Ev =>
// do your thing...
ack
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment