public function testConsume()
 {
     $queue = $this->createMock(Queue::class);
     $options = array('foo' => 'bar');
     $this->queueFactory->expects($this->once())->method('create')->with('foobar')->willReturn($queue);
     $this->consumer->expects($this->once())->method('consume')->with($queue, $options);
     $this->subject->consume('foobar', $options);
 }
 /**
  * @test
  */
 public function it_sends_an_event_to_queue_pulls_it_with_consumer_and_forwards_it_to_event_bus()
 {
     $event = new SomethingDone(['data' => 'test event']);
     //The message dispatcher works with a ready-to-use bernard producer and one queue
     $messageProducer = new BernardMessageProducer($this->bernardProducer, 'test-queue');
     //Normally you would send the event on a event bus. We skip this step here cause we are only
     //interested in the function of the message dispatcher
     $messageProducer($event);
     //Set up event bus which will receive the event message from the bernard consumer
     $consumerEventBus = new EventBus();
     $somethingDoneListener = new MessageHandler();
     $consumerEventBus->utilize(new EventRouter([$event->messageName() => [$somethingDoneListener]]));
     //We use a special bernard router which forwards all messages to a command bus or event bus depending on the
     //Prooph\ServiceBus\Message\MessageHeader::TYPE
     $bernardRouter = new BernardRouter(new CommandBus(), $consumerEventBus);
     $bernardConsumer = new Consumer($bernardRouter, new EventDispatcher());
     //We use the same queue name here as we've defined for the message dispatcher above
     $bernardConsumer->tick($this->persistentFactory->create('test-queue'));
     $this->assertNotNull($somethingDoneListener->getLastMessage());
     $this->assertEquals($event->payload(), $somethingDoneListener->getLastMessage()->payload());
 }
Beispiel #3
0
include 'include/do_submit.php';
use Bernard\Router\SimpleRouter;
use Bernard\Consumer;
use Bernard\QueueFactory\PersistentFactory;
use Bernard\Message\DefaultMessage;
use Bernard\Producer;
use Bernard\Serializer;
use Symfony\Component\EventDispatcher\EventDispatcher;
class CDashSubmissionService
{
    public function doSubmit(DefaultMessage $message)
    {
        global $CDASH_BASE_URL, $CDASH_REMOTE_ADDR;
        // Since this could be running on a remote machine, spoof the IP
        // to appear as the IP that actually submitted the build
        $CDASH_REMOTE_ADDR = $message['submission_ip'];
        $result = do_submit($message['buildsubmissionid'], $message['projectid'], $message['expected_md5'], $message['do_checksum'], $message['submission_id']);
        // If the submission didn't explicitly fail, delete the submission XML to avoid
        // duplicate submissions
        if ($result !== false) {
            $client = new GuzzleHttp\Client();
            $response = $client->request('DELETE', $CDASH_BASE_URL . '/api/v1/deleteBuildSubmissionXml.php', array('query' => array('buildsubmissionid' => $message['buildsubmissiondid'])));
        }
    }
}
$router = new SimpleRouter();
$router->add('DoSubmit', new CDashSubmissionService());
$factory = new PersistentFactory($CDASH_BERNARD_DRIVER, new Serializer());
// Create a Consumer and start the loop.
$consumer = new Consumer($router, new EventDispatcher());
$consumer->consume($factory->create('do-submit'));
 /**
  * @param TickOccurred $event
  */
 public function onTickOccurred(TickOccurred $event)
 {
     $this->psbBernardMessageConsumer->tick($this->queue);
 }
 /**
  * {@inheritdoc}
  */
 protected function doConfigure(array $options)
 {
     parent::configure($options);
 }
 public function consumeAction()
 {
     $queue = $this->queues->create($this->getRequest()->getParam('queue'));
     $this->consumer->consume($queue, ['max-runtime' => $this->getRequest()->getParam('max-runtime', PHP_INT_MAX), 'stop-on-error' => $this->getRequest()->getParam('stop-on-failure', false), 'max-messages' => $this->getRequest()->getParam('max-messages', null), 'stop-when-empty' => $this->getRequest()->getParam('stop-when-empty', false)]);
 }
 /**
  * {@inheritdoc}
  */
 public function consume($queue, array $options = [])
 {
     $queue = $this->queueFactory->create($queue);
     $this->consumer->consume($queue, $options);
 }