Skip to content

Instantly share code, notes, and snippets.

@igorw
Forked from jsor/Acknowledgement.php
Created November 15, 2012 21:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorw/4081306 to your computer and use it in GitHub Desktop.
Save igorw/4081306 to your computer and use it in GitHub Desktop.
<?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.');
}
}
}
<?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