/** * @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'])); } }
/** * @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; }