Пример #1
0
 /**
  *  Publish args with a routing_key containing routing details to exchange
  */
 public function go(RequestReader $req)
 {
     $ch = $this->getChannel();
     $msg = new AMQPMessage($req->getBody(), array('content_type' => 'application/json'));
     if (!$req->isHeaderSet("X-routing-key")) {
         throw new \Exception("x-routing-key not set");
     }
     $ch->basic_publish($msg, self::EXCHANGE, $req->getHeader('X-routing-key'));
 }
Пример #2
0
 public function unmarshalRoutineRequest(RequestReader $r)
 {
     if (!$r->isHeaderSet("X-routing-key")) {
         throw new \Exception("x-routing-key not set");
     }
     list($ns, $dc, $type, $method) = $this->unmarshalTopicString($r->getHeader('X-routing-key'));
     $vos = json_decode($r->getBody(), true);
     $retryErrors = array_pop($vos);
     $exitVo = array_pop($vos);
     $exitCh = $this->unmarshalArg($exitVo, Chan::CLASSNAME);
     $entities = $this->unmarshalForMethod($vos, $type, $method);
     return (new RoutineRequestBuilder())->ns($ns)->dc($dc)->type($type)->method($method)->args($entities)->exitChan($exitCh)->retryErrors($retryErrors)->build();
 }
Пример #3
0
 public function getRoute(RequestReader $request)
 {
     $url = (string) $request->getUrl();
     $method = $request->getHttpMethod();
     if (substr($url, 0, 1) === '@') {
         $key = substr($url, 1);
         return $this->getRouteByKey($key);
     }
     foreach ($this->routes as $route) {
         if ($route->match($request)) {
             return $route;
         }
     }
     throw new RouteException("Route Not Found");
 }
Пример #4
0
 public function match(RequestReader $req)
 {
     return in_array($req->getHttpMethod(), $this->getMethods());
 }
Пример #5
0
 public function getFoo(RequestReader $req, PathParam $id, GetParam $type = null)
 {
     return array('method' => $req->getHttpMethod(), 'id' => $id->get(), 'type' => $type == null ? null : $type->get());
 }