コード例 #1
0
ファイル: Driver.php プロジェクト: skolodyazhnyy/service-bus
 /**
  * {@inheritdoc}
  */
 public function call(Identity $identity, Request $request)
 {
     $url = Url::parse($identity->getUrl(['amqps', 'amqp']));
     $reply = $this->invoker->call($this->createRequest($request), $url->getQueryParameter('exchange', $this->exchange), $request->getMethod());
     return new Promise(function ($timeout) use($reply) {
         return $this->createResponse($reply->resolve($timeout));
     }, function () use($reply) {
         $this->invoker->dequeue($reply);
     });
 }
コード例 #2
0
 /**
  * {@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];
 }
コード例 #3
0
 /**
  * {@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;
 }
コード例 #4
0
 /**
  * {@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;
     });
 }
コード例 #5
0
ファイル: Driver.php プロジェクト: skolodyazhnyy/service-bus
 /**
  * @todo: should also resolve jsonrpc and jsonrpcs schemas.
  *
  * {@inheritdoc}
  */
 public function call(Identity $identity, Request $request)
 {
     $url = $identity->getUrl(['https', 'http']);
     $headers = $this->getEncodedHeaders();
     $body = $this->getEncodedBody($request);
     /** @var HttpResponse $response */
     $response = $this->buzz->call($url, 'POST', $headers, $body);
     return new Promise(function () use($response) {
         $result = $this->getDecodedBody($response->getContent());
         return new Response($result);
     });
 }
コード例 #6
0
 public function testGetSchemas()
 {
     self::assertEquals(['foo', 'bar', 'baz', 'qux'], $this->identity->getSchemas());
 }
コード例 #7
0
 /**
  * @return Request
  */
 public function toRequest()
 {
     return new Request('sys.announce', ['name' => $this->identity->getName(), 'urls' => $this->identity->getUrls()]);
 }