Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the result to determine acknowldegement #28

Merged
merged 1 commit into from
Nov 24, 2015

Conversation

h-bragg
Copy link
Contributor

@h-bragg h-bragg commented Nov 24, 2015

Resolves: #23

Not sure if this is better than adding checks to the other AcknowledgementHandlers.

As an aside, would the message handling / acknowledgement handling be better split out into their own interfaces. The current Handlers are sort of doing 2 things.

interface MessageHandler {
    public function handle(Iterator $messages, AdapterInterface $adapter, AcknowledgerInterface $acknowledger, callable $worker);
}
class DefaultHandler implements MessageHandler {
    public function handle(Iterator $messages, AdapterInterface $adapter, AcknowledgmentInterface $acknowledger, callable $worker) {
        // Used to break from polling consumer
        $break = false;
        $done = function () use (&$break) {
            $break = true;
        };

        try {
            foreach ($messages as $message) {
                if ($message->isValid()) {
                    $result = call_user_func($worker, $message, $done);
                    $acknowledger->acknowledge($message, $adapter, $result);
                }

                if ($break) {
                    break;
                }
            }
        } catch (Exception $e) {
            $acknowledger->flush($adapter);
            throw $e;
        }

        $this->flush($adapter);
    }
}

interface AcknowledgmentInterface {
    public function acknowledge($message, $adapter, $result);
    public function flush($adapter);
}

@sjparkinson sjparkinson self-assigned this Nov 24, 2015
sjparkinson added a commit that referenced this pull request Nov 24, 2015
use the result to determine acknowldegement
@sjparkinson sjparkinson merged commit 7e21eec into graze:master Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants