-
-
Save igorw/4081306 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
<?php | |
namespace React\Stomp; | |
class AckResolver | |
{ | |
private $result; | |
private $client; | |
private $subscriptionId; | |
private $messageId; | |
public function __construct(Client $client, $subscriptionId, $messageId) | |
{ | |
$this->client = $client; | |
$this->subscriptionId = $subscriptionId; | |
$this->messageId = $messageId; | |
} | |
public function ack(array $headers = array()) | |
{ | |
$this->throwExceptionIfResolved(); | |
$this->result = true; | |
$this->client->ack($this->subscriptionId, $this->messageId, $headers); | |
} | |
public function nack(array $headers = array()) | |
{ | |
$this->throwExceptionIfResolved(); | |
$this->result = false; | |
$this->client->nack($this->subscriptionId, $this->messageId, $headers); | |
} | |
private function throwExceptionIfResolved() | |
{ | |
if (null !== $this->result) { | |
throw new \RuntimeException('You must not try to resolve an acknowledgement more than once.'); | |
} | |
} | |
} |
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
<?php | |
$client->subscribe('/topic/foo', function ($frame, $ackResolver) { | |
if ($problem) { | |
$ackResolver->nack(); | |
} else { | |
$ackResolver->ack(); | |
} | |
}, 'client'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment