public function testEmptyExchangeProducer() { $this->runWithConfig(__DIR__ . "/../Fixtures/producer.yml", ["producer-name" => "EmptyExchange", "message" => MessageMeta::toJson((new Message())->setIntValue(234)->setFloatValue(2.41)->setStringValue("test"))]); $client = new Client(); $client->connect(); $channel = $client->channel(); /** @var BunnyMessage $msg */ $msg = $channel->get("producer_test_queue", true); $this->assertNotNull($msg); $this->assertEquals(ContentTypes::APPLICATION_JSON, $msg->getHeader("content-type")); $object = MessageMeta::fromJson($msg->content); $this->assertNotNull($object); $this->assertEquals(234, $object->getIntValue()); $this->assertEquals(2.41, $object->getFloatValue()); $this->assertEquals("test", $object->getStringValue()); }
public function testQueue() { $client = new Client(); $client->connect(); $channel = null; try { $channel = $client->channel(); $channel->queueDeclare("test_queue", true, true); $this->fail("queue should not exist."); } catch (ClientException $e) { $client->removeChannel($channel->getChannelId()); } $this->runWithConfig(__DIR__ . "/../Fixtures/queue.yml"); try { $channel = $client->channel(); $channel->queueDeclare("test_queue", true, true); $channel->queueDelete("test_queue"); } catch (ClientException $e) { $this->fail("queue should exist by now."); } }
public function testConsumerWithProtobuf() { $container = $this->runWithConfig(__DIR__ . "/../Fixtures/consumer.yml", ["consumer-name" => "Test"]); /** @var TestConsumer $consumer */ $consumer = $container->get("consumer.test"); $this->assertNull($consumer->message); $client = new Client(); $client->connect(); $channel = $client->channel(); $message = new Message(); $message->setIntValue(42); $message->setFloatValue(3.14); $message->setStringValue("hello, world"); $channel->publish(MessageMeta::toProtobuf($message), ["content-type" => ContentTypes::APPLICATION_PROTOBUF], "consumer_test_exchange", "test.message"); $client->disconnect(); $container = $this->runWithConfig(__DIR__ . "/../Fixtures/consumer.yml", ["consumer-name" => "Test"]); /** @var TestConsumer $consumer */ $consumer = $container->get("consumer.test"); $this->assertNotNull($consumer->message); $this->assertEquals(42, $consumer->message->getIntValue()); $this->assertEquals(3.14, $consumer->message->getFloatValue()); $this->assertEquals("hello, world", $consumer->message->getStringValue()); }
public function testConfirmMode() { $client = new Client(); $client->connect(); $channel = $client->channel(); $deliveryTag = null; $channel->confirmSelect(function (MethodBasicAckFrame $frame) use(&$deliveryTag, $client) { if ($frame->deliveryTag === $deliveryTag) { $deliveryTag = null; $client->stop(); } }); $deliveryTag = $channel->publish("."); $client->run(1); $this->assertNull($deliveryTag); }