/** * Busca por uma estratégia a partir do nome definido para a mesma. * @param $name * @return mixed * @throws StrategyNotFoundException */ public function getStrategy($name) { if (!$this->dictionary->containsKey($name)) { throw new StrategyNotFoundException(); } return $this->dictionary->get($name); }
/** * @param $service * @return ServiceInterface */ public function getService($service) { //Lazy authentication $token = $this->authenticationService->getAccessToken(); if (!$token->getAccessToken()) { $this->authenticationService->authorize(); } $this->client->createClient($this->authenticationService->getConsumerId(), $token->getAccessToken()); return $this->services->get($service); }
/** * {@inheritdoc} */ public function consume($topic, callable $callback, $configs = []) { if (!$configs instanceof MapInterface) { $configs = new Dictionary($configs); } if (!$this->configured || $configs->get('force_config')) { $configs = $this->setConfig($topic, $configs); } while (true) { $this->fetch($topic, $callback); } }
/** * {@inheritdoc} */ public function produce($payload, $configs = []) { $configs = new Dictionary($configs); $this->producers->each(function (ProducerInterface $producer) use($payload, $configs) { /** @var MapInterface $brokerConfigs */ $brokerConfigs = $configs->get($producer->getName()); try { $topic = $brokerConfigs->get('topic'); } catch (\OutOfBoundsException $e) { throw new \InvalidArgumentException('You should configure the topic/exchange that you want to produce to'); } $producer->produce($topic, $payload, $brokerConfigs); }); }
/** * {@inheritDoc} * @return $this */ public function groupBy($callback) { $callback = $this->propertyExtractor($callback); $group = new Dictionary(); foreach ($this as $value) { $key = $callback($value); if (!$group->containsKey($key)) { $element = $this instanceof VectorInterface ? new static([$value]) : new ArrayList([$value]); $group->add($key, $element); } else { $value = $group->get($key)->add($value); $group->set($key, $value); } } return $group; }
/** * {@inheritdoc} */ public function produce($topic, $payload, $configs = []) { if (!$configs instanceof MapInterface) { $configs = new Dictionary($configs); } if (!$this->configured || $configs->get('force_config')) { $configs = $this->setConfig($topic, $configs); } $partition = $this->choosePartition($topic, isset($configs['partition_strategy']) ? $configs['partition_strategy'] : self::PARTITION_STRATEGY_RANDOM); if (is_string($payload)) { $payload = [$payload]; } foreach ($payload as $message) { $this->connection->setMessages($topic, $partition, $message); } return $this->connection->send(); }
/** * @expectedException \OutOfBoundsException */ public function testGetInvalidItem() { $this->coll->set('keyOne', 'testing'); $this->coll->get('keyTwo'); }