Exemplo n.º 1
0
 /**
  * RabbitMq Test Client
  *
  * @return Client
  */
 public static function getClient()
 {
     $client = new Client(new Connection('tcp://127.0.0.1:61030'));
     $client->setLogin('guest', 'guest');
     $client->setVhostname('/');
     return $client;
 }
Exemplo n.º 2
0
 /**
  * @return ActiveMq
  * @throws \Stomp\Broker\Exception\UnsupportedBrokerException
  */
 protected function getProtocol()
 {
     $protocol = $this->client->getProtocol();
     if (!$protocol instanceof ActiveMq) {
         throw new UnsupportedBrokerException($protocol, ActiveMq::class);
     }
     return $protocol;
 }
Exemplo n.º 3
0
 public function testAbortTransaction()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->simpleStomp->begin('my-id'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test t-id', ['transaction' => 'my-id']));
     $this->assertTrue($this->simpleStomp->abort('my-id'));
     $this->assertTrue($this->simpleStomp->subscribe('/queue/test', 'mysubid'));
     $this->Stomp->getConnection()->setReadTimeout(0, 500000);
     $frame = $this->Stomp->readFrame();
     $this->assertFalse($frame);
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function subscribe(Consumer $consumer, ExecutionCondition $condition)
 {
     $this->stompClient->subscribe($consumer->getConfig()->getDestination());
     while ($condition->isValid()) {
         if ($message = $this->stompClient->readMessage(10)) {
             $condition->incrementMessagesCount();
             $result = $consumer->callback($message->getBody());
             if ($result) {
                 $message->ack();
             } else {
                 $message->nack();
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Tests Stomp->unsubscribe()
  */
 public function testUnsubscribe()
 {
     if (!$this->Stomp->isConnected()) {
         $this->Stomp->connect();
     }
     $this->simpleStomp->subscribe($this->queue, 'mysubid');
     $this->assertTrue($this->simpleStomp->unsubscribe($this->queue, 'mysubid'));
 }
Exemplo n.º 6
0
 /**
  * Tests Stomp->unsubscribe()
  */
 public function testUnsubscribe()
 {
     if (!$this->stomp->isConnected()) {
         $this->stomp->connect();
     }
     $simpleStomp = new SimpleStomp($this->stomp);
     $simpleStomp->subscribe('/queue/unsub');
     $this->assertTrue($simpleStomp->unsubscribe('/queue/unsub'));
 }
Exemplo n.º 7
0
 /**
  * Read next message.
  *
  * @return bool|false|\Stomp\Transport\Frame
  */
 public function read()
 {
     if (!$this->active || $this->reachedEnd) {
         return false;
     }
     if ($frame = $this->client->readFrame()) {
         if ($this->stopOnEnd && $frame['browser'] == 'end') {
             $this->reachedEnd = true;
             return false;
         }
     }
     return $frame;
 }
Exemplo n.º 8
0
 /**
  * Tests Stomp->connect(), send(), and subscribe() - out of order. the messages should be received in FIFO order.
  */
 public function testAsyncSub()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 1'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 2'));
     $this->assertTrue($this->simpleStomp->subscribe('/queue/test', 'mysubid'));
     $frame = $this->Stomp->readFrame();
     $this->assertEquals($frame->body, 'test 1', 'test 1 was not received!');
     $frame = $this->Stomp->readFrame();
     $this->assertEquals($frame->body, 'test 2', 'test 2 was not received!');
 }
Exemplo n.º 9
0
 /**
  * ApolloMq Test Client
  *
  * @return Client
  */
 public static function getClient()
 {
     $client = new Client(new Connection('tcp://127.0.0.1:61020'));
     $client->setLogin('admin', 'password');
     return $client;
 }
Exemplo n.º 10
0
 /**
  * Not acknowledge consumption of a message from a subscription
  *
  * @param Frame $frame
  * @return void
  */
 public function nack(Frame $frame)
 {
     $this->client->sendFrame($this->getProtocol()->getNackFrame($frame), false);
 }
Exemplo n.º 11
0
 /**
  * Tests Stomp->connect()
  */
 public function testFailoverConnect()
 {
     $this->assertTrue($this->Stomp->connect());
 }
Exemplo n.º 12
0
 public function testConnect()
 {
     $params = $this->client->getServerInfo();
     $this->assertEquals('1.1', $params['version']);
 }
Exemplo n.º 13
0
 public function testClientWillAutoConnectOnGetProtocol()
 {
     $connection = $this->getMockBuilder(Connection::class)->setMethods(['connect', 'getParser'])->disableOriginalConstructor()->getMock();
     $connection->expects($this->once())->method('connect');
     $connection->expects($this->any())->method('getParser')->willReturn(new Parser());
     $client = new Client($connection);
     try {
         $client->getProtocol();
     } catch (ConnectionException $connectionFailed) {
         $this->addToAssertionCount(1);
     }
 }
Exemplo n.º 14
0
 /**
  * @return Protocol
  */
 protected function getProtocol()
 {
     return $this->client->getProtocol();
 }
Exemplo n.º 15
0
 public function testConnectOnApollo()
 {
     $this->assertTrue($this->client->connect(), 'Expected reachable broker.');
     $this->assertInstanceOf(Apollo::class, $this->client->getProtocol(), 'Expected a Apollo broker.');
 }