/** * Begin new transaction * * @param peer.stomp.Connection $conn * @return peer.stomp.Transaction */ public function begin(Connection $conn) { try { $this->conn = $conn; $conn->sendFrame(new BeginFrame($this->name)); } catch (\lang\Throwable $t) { $this->conn = null; throw $t; } }
public function run() { $conn = new Connection(new \peer\URL('stomp://localhost:61613/?log=default')); $conn->connect(); $dest = $conn->getDestination('/queue/producer'); for ($i = 1; $i <= $this->amount; $i++) { $msg = new SendableMessage('Message ' . $i . ' of ' . $this->amount . ' in ' . $this->hashCode(), 'text/plain'); $dest->send($msg); $this->out->writeLine('Wrote message ' . $i); } }
public function run() { $conn = new Connection(new \peer\URL('stomp://localhost:61613/?log=default')); $conn->connect(); $self = $this; $sub = $conn->subscribeTo(new Subscription('/queue/producer', function ($message) use($self, $conn) { $self->out->writeLine('Consuming: ', \xp::stringOf($message)); $cpy = $message->toSendable(); $conn->getDestination('/queue/foobar')->send($cpy); $message->ack(); })); while ($conn->consume(1)) { } }
public function run() { $conn = new Connection(new \peer\URL('stomp://localhost:61613/?log=default')); $conn->connect(); $self = $this; $sub1 = $conn->subscribeTo(new Subscription('/queue/producer', function ($message) use($self) { $self->out->writeLine('Acking message ', $message->getMessageId()); $message->ack(); })); $sub2 = $conn->subscribeTo(new Subscription('/queue/foobar', function ($message) use($self) { $self->out->writeLine('Consumed message ', $message->getMessageId()); }, AckMode::AUTO)); while ($conn->consume()) { } }
public function run() { $conn = new Connection(new \peer\URL('stomp://localhost:61613/?log=default')); $conn->connect(); $self = $this; $sub = $conn->subscribeTo(new Subscription('/queue/producer', function (ReceivedMessage $msg) use($self) { $self->out->writeLine('Consuming: ', \xp::stringOf($msg)); if ($msg) { $msg->ack(); } })); while ($conn->consume(1)) { } $conn->disconnect(); }
/** * Fill message members from given frame. * * @param peer.stomp.frame.MessageFrame $frame * @param peer.stomp.Connection $conn */ public function withFrame(MessageFrame $frame, Connection $conn) { $this->frame = $frame; $this->setDestination($conn->getDestination($frame->getHeader(Header::DESTINATION))); $this->messageId = $frame->getHeader(Header::MESSAGEID); if ($frame->hasHeader(Header::CONTENTTYPE)) { $this->contentType = $frame->getHeader(Header::CONTENTTYPE); } if ($frame->hasHeader(Header::SUBSCRIPTION)) { $this->setSubscription($conn->subscriptionById($frame->getHeader(Header::SUBSCRIPTION))); } $this->setPersistence(false); if ($frame->hasHeader(Header::PERSISTENCE)) { $this->setPersistence('true' === $frame->getHeader(Header::PERSISTENCE)); } $skipHeaders = [Header::DESTINATION => true, Header::MESSAGEID => true, Header::CONTENTTYPE => true, Header::SUBSCRIPTION => true, Header::CONTENTLENGTH => true]; foreach ($frame->getHeaders() as $name => $value) { if (isset($skipHeaders[$name])) { continue; } $this->addHeader($name, $value); } $this->body = $frame->getBody(); }
/** * Create a subscription on a destination * * @param peer.stomp.Connection $conn * @throws lang.Throwable If any error occurrs */ public function subscribe(Connection $conn) { $this->destination = $conn->getDestination($this->dest); try { $this->id = uniqid('xp-sub-'); $frame = new SubscribeFrame($this->destination->getName(), $this->ackMode, $this->selector); $frame->setId($this->id); $this->destination->getConnection()->sendFrame($frame); } catch (\lang\Throwable $t) { $this->id = null; throw $t; } }
public function invalidCredentials() { $conn = new Connection(new \peer\URL('stomp://' . $this->host)); $conn->connect('unknownuser', 'invalidpass'); }