Beispiel #1
1
 /**
  * Version constructor.
  *
  * @param Frame $frame
  * @throws StompException
  */
 public function __construct(Frame $frame)
 {
     if ($frame->getCommand() != 'CONNECTED') {
         throw new UnexpectedResponseException($frame, sprintf('Expected a "CONNECTED" Frame to determine Version. Got a "%s" Frame!', $frame->getCommand()));
     }
     $this->frame = $frame;
 }
Beispiel #2
0
 public function testFrameInLegacyModeWontEncodeHeaders()
 {
     $frame = new Frame('SEND', ['my:var' => "\\multi\nline\r!"]);
     $frame->legacyMode(true);
     $result = $frame->__toString();
     $expected = "SEND\nmy:var:\\multi\\nline\r!\n\n";
     $this->assertEquals($expected, $result);
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function getNackFrame(Frame $frame, $transactionId = null)
 {
     $nack = $this->createFrame('NACK');
     $nack['transaction'] = $transactionId;
     if ($this->hasVersion(Version::VERSION_1_2)) {
         $nack['id'] = $frame['ack'] ?: $frame->getMessageId();
     } else {
         $nack['message-id'] = $frame['ack'] ?: $frame->getMessageId();
         if ($this->hasVersion(Version::VERSION_1_1)) {
             $nack['subscription'] = $frame['subscription'];
         }
     }
     return $nack;
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function getAckFrame(Frame $frame, $transactionId = null)
 {
     $ack = $this->createFrame('ACK');
     $ack['transaction'] = $transactionId;
     if ($this->hasVersion(Version::VERSION_1_2)) {
         $ack['id'] = $frame->getMessageId();
     } else {
         $ack['message-id'] = $frame->getMessageId();
     }
     // spec quote: "ACK should always specify a "subscription" header for the subscription id that the message to be acked was delivered to ."
     // see https://mq.java.net/4.4-content/stomp-funcspec.html
     $ack['subscription'] = $frame['subscription'];
     return $ack;
 }
 protected function assertIsAbortFrame(Frame $frame)
 {
     $this->assertEquals('ABORT', $frame->getCommand(), 'Frame command is no "abort" command.');
 }
Beispiel #6
0
 public function testParserWontDecodeHeadersInLegacyMode()
 {
     $frame = "COMMAND\nX-Proof:Hello\\c\\r\\n  \\\\World!\n\nBody";
     $this->parser->legacyMode(true);
     $this->parser->addData($frame);
     $this->parser->parse();
     $expected = new Frame('COMMAND', ['X-Proof' => "Hello\\c\\r\n  \\\\World!"], "Body");
     $expected->legacyMode(true);
     $actual = $this->parser->getFrame();
     $this->assertEquals($expected, $actual);
 }
Beispiel #7
0
 /**
  * Write frame to server.
  *
  * @param Frame $stompFrame
  * @return boolean
  * @throws ConnectionException
  */
 public function writeFrame(Frame $stompFrame)
 {
     if (!$this->isConnected()) {
         throw new ConnectionException('Not connected to any server.', $this->activeHost);
     }
     $data = $stompFrame->__toString();
     if (!@fwrite($this->connection, $data, strlen($data))) {
         throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
     }
     return true;
 }
Beispiel #8
0
 /**
  * Send a message to a destination in the messaging system
  *
  * @param string $destination Destination queue
  * @param string|Frame $msg Message
  * @param array $header
  * @param boolean $sync Perform request synchronously
  * @return boolean
  */
 public function send($destination, $msg, array $header = [], $sync = null)
 {
     if (!$msg instanceof Frame) {
         return $this->send($destination, new Frame('SEND', $header, $msg), [], $sync);
     }
     $msg->addHeaders($header);
     $msg['destination'] = $destination;
     return $this->sendFrame($msg, $sync);
 }