示例#1
0
 /**
  * Connects to the ZMQ inbound queue from the deferred queue server.
  * Starts the gearman worker and processes the workload by calling
  * the registered callback functions.
  */
 public function produce()
 {
     $this->client->connect();
     while ($this->active) {
         $this->gearman->work();
     }
 }
示例#2
0
 /**
  * Simulates messages on the producer side.
  *
  * @param string $keyPrefix Prefix for key generation.
  * @param int $keyDistribution Number of different keys to generate.
  * @param int $numMessages Number of messages to send
  * @param int $expMinMs Start value for random expiration in microseconds.
  * @param int $expMaxMs End value for random expiration in microseconds.
  * @param int $sleepMicroSeconds Sleep duration between each send call in microseconds.
  */
 public function simulate($keyPrefix, $keyDistribution, $numMessages, $expMinMs, $expMaxMs, $sleepMicroSeconds)
 {
     $this->logger->info("Starting console producer simulation. Generating {$numMessages} messages with a key " . "distribution of {$keyDistribution}. The key prefix is {$keyPrefix} and the expiration " . "timeout is between {$expMinMs} and {$expMaxMs} microseconds.");
     $client = new Client($this->getZmqOut(), $this->logger);
     $client->setVerbose($this->isVerbose());
     $client->connect();
     // Sleep until socket is ready
     // @todo Figure out a better way to check if the socket is ready.
     usleep(1000000);
     $this->logger->info("Starting to generate packets...");
     for ($i = 0; $i < $numMessages; $i++) {
         $key = $keyPrefix . '_' . mt_rand(1, $keyDistribution);
         $expire = mt_rand($expMinMs, $expMaxMs);
         $data = serialize(['a' => mt_rand(1, 10), 'b' => mt_rand(1, 10)]);
         $message = new RequestMessage($key, $data, $expire, 'aggregate');
         $client->send((string) $message);
         if ($sleepMicroSeconds) {
             usleep($sleepMicroSeconds);
         }
     }
 }