/** * {@inheritdoc} */ public function define(Identity $identity) { $name = $identity->getName(); if (isset($this->endpoints[$name])) { throw $this->endpoints[$name] instanceof ServiceInterface ? AmbiguousServiceException::makeAlreadyDefined($name) : AmbiguousServiceException::makeAlreadyDiscovered($name); } $this->endpoints[$name] = new Service($identity); $this->broadcast(new Announce($identity)); return $this->endpoints[$name]; }
/** * {@inheritdoc} */ public function register(Identity $identity) { $name = $identity->getName(); if (!isset($this->identities[$name])) { $this->identities[$name] = $identity; } else { $this->identities[$name]->setUrls($identity->getUrls()); } return $this; }
/** * {@inheritdoc} */ public function call(Identity $identity, Request $request) { $this->logger->debug('Call "%method%" to service "%service%"', ['service' => $identity->getName(), 'request_method' => $request->getMethod(), 'request_arguments' => $request->getArguments(), 'request_headers' => $request->getHeaders(), 'driver' => get_class($this->driver)]); $promise = $this->driver->call($identity, $request); return new Promise(function ($timeout) use($identity, $request, $promise) { $response = $promise->resolve($timeout); $this->logger->debug('Response from "%service%"', ['service' => $identity->getName(), 'request_method' => $request->getMethod(), 'response_value' => $response->getValue(), 'response_headers' => $response->getHeaders(), 'driver' => get_class($this->driver)]); return $response; }); }
public function testGetNameAndUrls() { self::assertEquals('foo', $this->identity->getName()); self::assertEquals(['foo://localhost', 'bar://localhost', 'baz://localhost', 'qux://localhost'], $this->identity->getUrls()); }
/** * @return Request */ public function toRequest() { return new Request('sys.announce', ['name' => $this->identity->getName(), 'urls' => $this->identity->getUrls()]); }