AMQP: RPC should use Future
akka-amqp's RPC feature ties up a thread in a couple places for no good reason.
On the client side,
callAsync() could return a Future instead of taking a handler, and then it could use
Then on the server side,
On the client side,
def call(request: O, timeout: Long = 5000): Option[I] = {
(client.!!(request, timeout)).as[I]
}
def callAsync(request: O, timeout: Long = 5000)(responseHandler: PartialFunction[Option[I],Unit]) = {
spawn {
val result = call(request, timeout)
responseHandler.apply(result)
}
}
callAsync() could return a Future instead of taking a handler, and then it could use
?
instead of !!
under the hood.Then on the server side,
case Delivery(payload, _, tag, _, props, sender) => {
val request = serializer.fromBinary.fromBinary(payload)
val response: Array[Byte] = serializer.toBinary.toBinary(requestHandler(request))
requestHandler
could return a Future instead of a value to avoid blocking receive
.
Leave a comment
on 2011-10-03 12:17 *
By Jonas Bonér
Hi Irmo, will you be able to help out with this one and the other AMQP tickets? /Jonas
on 2011-10-03 15:33 *
By Irmo Manie
Should be ok yes. Any target for a deadline?
on 2011-10-12 18:22 *
By viktorklang
Milestone changed from 2.0-M1 to 2.0
Summary changed from amqp RPC should use Future to AMQP: RPC should use Future
Updating tickets (#1129, #1132, #1138, #1149, #1153, #1154, #1157, #1161, #1163, #1168, #1170, #1171, #1172, #1176, #1177, #1178, #1180, #1199, #1217, #1218, #1219, #1237, #1238, #1239, #1244, #1246, #1249, #1250, #1251, #1252, #1256, #1301, #1302, #1306, #1395, #1396, #1409, #1418, #455, #891, #895, #912, #956, #972, #1031, #1374, #880, #1125, #1146)