Exemple #1
0
 /**
  * Prepares the environment before running a test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->Stomp = ClientProvider::getClient();
     $this->Stomp->setSync(false);
     $this->simpleStomp = new SimpleStomp($this->Stomp);
 }
 public function testWithClientAck()
 {
     $this->clearDLQ();
     $client = $this->getClient();
     $client->getConnection()->setReadTimeout(0, 500000);
     $client->setClientId('durable-client-id-2');
     $durableInit = new DurableSubscription($client, '/topic/durable-test-2', null, 'client-individual');
     $durableInit->activate();
     $durableInit->inactive();
     $client->disconnect(true);
     $producer = ClientProvider::getClient();
     $producer->setClientId('producer');
     $producer->send('/topic/durable-test-2', new Message('First', ['persistent' => 'true']));
     $producer->send('/topic/durable-test-2', new Message('Second', ['persistent' => 'true']));
     $producer->disconnect(true);
     $durableAwake = new DurableSubscription($client, '/topic/durable-test-2', null, 'client-individual');
     $durableAwake->activate();
     $durableAwake->nack($durableAwake->read());
     $durableAwake->ack($durableAwake->read());
     $durableAwake->deactivate();
     $dlq = $this->getCurrentDLQ();
     $this->assertCount(1, $dlq);
     $message = $dlq[0];
     $this->assertEquals('First', $message->body);
 }
Exemple #3
0
 protected function getClient()
 {
     return ClientProvider::getClient();
 }
Exemple #4
0
 protected function consume()
 {
     $consumer2 = ClientProvider::getClient();
     $consumer2->setSync(false);
     $consumer2->setClientId('test');
     $consumer2->getConnection()->setReadTimeout(1);
     $consumer2->connect();
     $amq = $consumer2->getProtocol();
     $this->assertInstanceOf(ActiveMq::class, $amq);
     /**
      * @var $amq ActiveMq
      */
     $consumer2->sendFrame($amq->getSubscribeFrame($this->topic, 'test', 'auto', null, true));
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, 'test message');
     if ($frame != null) {
         $consumer2->sendFrame($amq->getAckFrame($frame));
     }
     // yes, that's active mq! you must unsub two times...
     // http://mail-archives.apache.org/mod_mbox/activemq-dev/201205.mbox/raw/
     //        %3C634996273.21688.1336051731428.JavaMail.tomcat@hel.zones.apache.org%3E/
     $consumer2->sendFrame($amq->getUnsubscribeFrame($this->topic, 'test'));
     // that took me some time...
     $consumer2->sendFrame($amq->getUnsubscribeFrame($this->topic, 'test', true));
     $consumer2->disconnect();
 }