コード例 #1
0
 public function testLookupWithInvalidResponseEntry()
 {
     $newIdentity = new Identity('foo', ['http://localhost']);
     $this->backend->expects(self::exactly(2))->method('get')->with('foo')->willReturnOnConsecutiveCalls(null, $newIdentity);
     $this->discovery->expects(self::once())->method('call')->with(new Discover())->willReturn(new Promise(function () {
         return new Response([['name' => 'foo', 'urls' => ['http://localhost']], ['invalid']]);
     }));
     $this->backend->expects(self::once())->method('register')->with($newIdentity);
     $identity = $this->registry->get('foo');
     self::assertSame($newIdentity, $identity);
 }
コード例 #2
0
 public function testHandleRPCException()
 {
     $this->endpoint->expects($this->once())->method('call')->willThrowException(new \Exception('foo', 129));
     $request = new Delivery($this->channel, 'cons', 1, false, '', 'boo', '{}', ['reply-to' => 'foo']);
     $reply = $this->handler->handle($request);
     $this->assertNotNull($reply);
     $headers = $reply->getHeaders();
     $this->assertArrayHasKey('x-error', $headers);
     $this->assertEquals('foo', $headers['x-error']);
     $this->assertArrayHasKey('x-error-code', $headers);
     $this->assertEquals(129, $headers['x-error-code']);
 }
コード例 #3
0
 /**
  * @throws DiscoveryException
  */
 private function update()
 {
     $response = $this->discovery->call(new Discover())->fallback(function (\Exception $e) {
         throw new DiscoveryException(sprintf('An error occur while fetching discovery information: %s', $e->getMessage()), 0, $e);
     })->resolve()->getValue();
     if (!is_array($response)) {
         throw new DiscoveryException(sprintf('Invalid response type \\"%s\\", array expected', gettype($response)));
     }
     foreach ($response as $entry) {
         if (empty($entry['name']) || !isset($entry['urls'])) {
             continue;
         }
         $this->register(new Identity($entry['name'], $entry['urls']));
     }
 }
コード例 #4
0
ファイル: Handler.php プロジェクト: skolodyazhnyy/service-bus
 /**
  * @param Delivery $message
  *
  * @return Message|null
  *
  * @throws \Exception
  */
 public function handle(Delivery $message)
 {
     $request = $this->createRequest($message);
     if (!$message->hasProperty('reply-to')) {
         $this->endpoint->publish($request);
         return;
     }
     try {
         $response = $this->endpoint->call($request)->resolve();
     } catch (\Exception $e) {
         $response = new Response('', ['x-error' => $e->getMessage(), 'x-error-code' => $e->getCode()]);
     }
     $reply = $this->createReply($response);
     if ($message->hasProperty('correlation-id')) {
         $reply = $reply->withProperty('correlation-id', $message->getProperty('correlation-id'));
     }
     return $reply;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->endpoint = $this->createMock(EndpointInterface::class);
     $this->endpoint->expects(self::once())->method('getIdentity')->willReturn(new Identity('foo'));
     $this->discovery = new ArrayDiscovery([$this->endpoint]);
 }