event-store-http-client icon indicating copy to clipboard operation
event-store-http-client copied to clipboard

ErrorException: Undefined variable: nextPosition when reading all events

Open morrislaptop opened this issue 5 years ago • 3 comments
trafficstars

use Prooph\EventStore\EndPoint;
use Prooph\EventStore\UserCredentials;
use Prooph\EventStoreHttpClient\ConnectionSettings;
use Prooph\EventStore\UserCredentials;
use Prooph\EventStoreHttpClient\EventStoreConnectionFactory;
use Prooph\EventStore\Position;

$creds = new UserCredentials('admin', 'changeit');

$settings = new ConnectionSettings(
  new EndPoint('localhost', '2113'),
  'http',
  $creds
);

$connection = EventStoreConnectionFactory::create($settings);

$from = Position::start();

do {
  $slice = $connection->readAllEventsForward($from, 4096);

  foreach ($slice->events() as $event) {
    $event = $event->event();
    var_dump("/streams/{$event->eventStreamId()}/{$event->eventNumber()}");
  }

  $from = $slice->nextPosition();
} 
while (!$slice->isEndOfStream());

morrislaptop avatar May 21 '20 08:05 morrislaptop

Due to this line - https://github.com/prooph/event-store/blob/ae40e9982935c9d66b4c6ef63144f8a2a9c41d7c/src/AllEventsSlice.php#L40

morrislaptop avatar May 21 '20 08:05 morrislaptop

Ironic issue number 😆

morrislaptop avatar May 21 '20 08:05 morrislaptop

You are subscribing to all events and reached end of stream. This is a known issue, see https://github.com/EventStore/EventStore/issues/1809. As long as this isn't fixed upstream, we could implement a workaround like described in this issue. Do you wanna give a try and submit a PR? I'm currently working on finalizing the async tcp client, so I probably won't get to this here quickly.

prolic avatar May 21 '20 17:05 prolic