Last active
August 29, 2015 14:28
-
-
Save dbousamra/2bbb3174421d5994d450 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Library supports bulk receives of up to 100. I want to be able to pass 750 in, and issue 8 bulk queries. | |
| // That idea of sort of doing it overcoming the limit of 100 is what I want to abstract. | |
| // Every bulk operation supports 100, but I'd like to do more. | |
| // Ideas? Some smaple code (I think receive might be incorrect - not working 100%, but yet to debug) | |
| def consume[A](fetchCount: Int)(f: MessageContainer => AckResponse): Unit = { | |
| val messages = receive(Nil, 1000, fetchCount) | |
| } | |
| @tailrec | |
| private def receive(acc: List[IronMqMessageContainer], timeout: Int, count: Int): List[IronMqMessageContainer] = { | |
| if (count == 0) { | |
| acc | |
| } else { | |
| val takeOff = Math.min(100, count) | |
| Try(queue.reserve(takeOff, timeout)).toOption match { | |
| case Some(deliveries) => { | |
| val messages = deliveries.getMessages.map(m => IronMqMessageContainer(IronMqMessage(m))).toList | |
| receive(messages ::: acc, timeout, count - takeOff) | |
| } | |
| case None => acc | |
| } | |
| } | |
| } | |
| // Also only allows maximum 100 acks at a time | |
| private def ack(acks: List[IronMqMessageContainer]) = ??? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment