Beispiel #1
0
 public function testConsumeCallback()
 {
     $dotenv = new Dotenv(dirname(__DIR__));
     $dotenv->load();
     JsonBus::register('request', '\\Messages\\Request');
     $message = new Request(["id" => "1", "clientId" => "php-unit", "subject" => "just second test", "params" => ["case" => "push-get"]]);
     $connection = new AMQPStreamConnection(getenv('RABBITMQ_HOST'), getenv('RABBITMQ_PORT'), getenv('RABBITMQ_USER'), getenv('RABBITMQ_PASSWORD'));
     $queue = new RabbitQueue($connection, 'requests');
     $queue->push($message);
     $queue->registerCallback(function ($message) use($queue) {
         $message = JsonBus::make($message);
         file_put_contents('test.json', $message->toJson());
         $queue->clearCallbacks('test');
     }, 'test');
     $queue->process();
     $this->assertJsonStringEqualsJsonString($message->toJson(), file_get_contents('test.json'));
 }
Beispiel #2
0
 protected function tearDown()
 {
     JsonBus::deregister();
 }
Beispiel #3
0
 /**
  * @param bool|false $acknowledge Auto acknowledgement flag
  * @return JsonBusMessage
  */
 public function get($acknowledge = false)
 {
     $message = $this->channel->basic_get($this->queue, $acknowledge);
     return JsonBus::make($message->body);
 }