/**
  * {@inheritDoc}
  */
 public function listen(AsyncEventBus $eventBus)
 {
     $callback = function ($msg) use($eventBus) {
         $eventBus->handle($this->serializer->deserialize(json_decode($msg->body, true)));
     };
     $this->adapter->listen($callback);
 }
 /**
  * @test
  */
 public function it_should_still_publish_events_after_exception()
 {
     $domainMessage1 = $this->createDomainMessage(array('foo' => 'bar'));
     $domainMessage2 = $this->createDomainMessage(array('foo' => 'bas'));
     $domainEventStream1 = new DomainEventStream(array($domainMessage1));
     $domainEventStream2 = new DomainEventStream(array($domainMessage2));
     $eventHandler = $this->createEventHandlerMock();
     $eventHandler->expects($this->at(0))->method('publish')->with($domainMessage1)->will($this->throwException(new \Exception('I failed.')));
     $eventHandler->expects($this->at(1))->method('publish')->with($domainMessage2);
     $eventBus = new AsyncEventBus($eventHandler);
     try {
         $eventBus->publish($domainEventStream1);
     } catch (\Exception $e) {
         $this->assertEquals('I failed.', $e->getMessage());
     }
     $eventBus->publish($domainEventStream2);
 }