/**
  * @test
  */
 public function it_should_rollback_if_consumer_throws_exception()
 {
     $this->setExpectedException(\Exception::class);
     $this->transactionManager->shouldReceive('beginTransaction');
     $this->transactionManager->shouldReceive('commit')->never();
     $this->transactionManager->shouldReceive('rollback');
     $this->consumer->shouldReceive('consume')->andThrow(\Exception::class);
     $consumer = new TransactionalConsumer($this->consumer, $this->transactionManager);
     $consumer->consume('test');
 }
 /**
  * Consumes a message.
  *
  * @param  string $message
  *
  * @return string|null|void
  *
  * @throws \Exception
  */
 public function consume($message)
 {
     try {
         $this->transactionManager->beginTransaction();
     } catch (BeginException $e) {
         throw new ConsumerException($e->getMessage(), $e->getCode(), $e);
     }
     try {
         $this->consumer->consume($message);
         $this->transactionManager->commit();
     } catch (\Exception $e) {
         $this->transactionManager->rollback();
         throw $e;
     }
 }