/**
  * Initial method triggered by blocked call in mbp-user-digest_director.php. $payload
  * is the contents of the message being processed from the queue.
  *
  * @param array $payload
  *   The contents of the queue entry
  */
 public function consumeDigestProducerQueue($payload)
 {
     echo '- mbc-user-digest_director - MBP_UserDigest_DirectorConsumer->consumeDigestProducerQueue() START', PHP_EOL;
     parent::consumeQueue($payload);
     // Watch for specific user messages
     if (strpos($this->message['url'], '/user?email=') !== FALSE) {
         if ($this->canProcess()) {
             $this->setter($this->message);
             $this->processUser();
         }
     } else {
         if ($this->canProcess()) {
             $this->setter($this->message);
             $this->process();
         }
     }
     echo '- mbc-user-digest_director - MBP_UserDigest_DirectorConsumer->consumeDigestProducerQueue() END', PHP_EOL;
 }
 /**
  * Coordinate processing of messages consumed fromn the target queue defined in the
  * application configuration.
  *
  * @param array $message
  *  The payload of the unserialized message being processed.
  */
 public function consumeDigestUserQueue($message)
 {
     echo '------- mbc-digest-email - MBC_DigestEmail_Consumer->consumeDigestUserQueue() START -------', PHP_EOL;
     parent::consumeQueue($message);
     echo PHP_EOL . PHP_EOL;
     echo '** Consuming: ' . $this->message['email'], PHP_EOL;
     // Process messages in batches for submission to the service. Once the number of
     // messages processed reached the BATCH_SIZE send messages.
     $waitingUserMessages = $this->waitingUserMessages();
     echo '- waitingUserMessages: ' . $waitingUserMessages, PHP_EOL;
     echo '- batchSize: ' . $this->batchSize, PHP_EOL;
     if ($waitingUserMessages < $this->batchSize) {
         if ($this->canProcess()) {
             echo '- canProcess(): OK', PHP_EOL;
             $setterOK = $this->setter($this->message);
             // Build out user object and gather / trigger building campaign objects
             // based on user campaign activity
             if ($setterOK) {
                 echo '- setter(): OK', PHP_EOL;
                 $this->process();
             }
         }
         $this->messageBroker->sendAck($this->message['payload']);
         echo '- Ack sent: OK', PHP_EOL . PHP_EOL;
         echo '------- mbc-digest-email - MBC_DigestEmail_Consumer->consumeDigestUserQueue() END -------', PHP_EOL;
     }
     // Send batch of user digest messages OR
     // If the number of messages remaining to be processed is zero and there are user
     // objects waiting to be sent create a batch of messages from the remaining user objects.
     // Not clear on the ready vs unacked values as the docs suggest re-declaring
     $queueMessages = parent::queueStatus('digestUserQueue');
     echo '- queueMessages ready: ' . $queueMessages['ready'], PHP_EOL;
     echo '- queueMessages unacked: ' . $queueMessages['unacked'], PHP_EOL;
     echo '- waitingUserMessages: ' . $this->waitingUserMessages(), PHP_EOL;
     if ($this->sendBatch($queueMessages['ready'])) {
         echo '%% sending email batch', PHP_EOL . PHP_EOL;
         // @todo: Support different services based on interface base class
         $status = $this->mbcDEMessenger->sendDigestBatch();
         // @todo: Log digest message activity, include errors encountered generating campaign
         // objects: $this->campaignErrors
         //
         // $this->logStatus();
         echo '- unset $this->users: ' . count($this->users), PHP_EOL . PHP_EOL;
         unset($this->users);
     }
     echo '~~~~~~~~~~~~~~', PHP_EOL . PHP_EOL;
 }