Code Monkey home page Code Monkey logo

geteventstore-php-core's People

Contributors

akii avatar arnovr avatar codetriage-readme-bot avatar cordoval avatar dbellettini avatar dependabot[bot] avatar fabiocarneiro avatar fhoutr01 avatar kmox83 avatar nicolopignatelli avatar ohader avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geteventstore-php-core's Issues

EventType wrong when reading projections

This is due to the fact that the summary field contains anything but the EventType ("$>") when reading streams that are based on projections. The events (and the data) itself are fetched normally.

A possible solution to this problem is to set the feeds embed mode to FULL and fix the EventStore\StreamFeed\Entry::getType() like this:

return (isset($this->json['eventType'])) ? $this->json['eventType'] : $this->json['summary'];

Should this be an acceptable solution, I'd gladly provide a pull-request.

Remove Broadway integration

Broadway should integrate with the eventstore-client, like the symfony package does. I don't know the reason why it was designed like this, but eventually this should be reversed.

I'd gladly provide a pull-request to both packages. Additionally, the implementation of the Broadway repository is flawed since the order of events is wrong (newest events come first).

Is this project alive and kicking?

Hi,

having a look at this repository I'm wondering whether it's still active? There's a fork by @tetsuobe with projection management support, that's not been incorporated via PR: https://github.com/tetsuobe/php-eventstore-client โ€“ It contains some non-automatically mergable changes in terms of vagrant vs. docker test setup iirc. There's another eventstore client project done by @rayrutjes (php7 only): https://github.com/rayrutjes/php-geteventstore-client

Basically I'm wondering what your take is on those three repositories and where things might by heading for EventStore support in the PHP world. :-)

[BUG] Infinite loop while reading a stream

Imagine I have a stream called 'A', and that I have 1 event for that stream. When I try consume all the events for this stream, the first event is read correctly with:

if ($feed->hasLink(LinkRelation::LAST())) {
    $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::LAST());
} else {
    $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::FIRST());
}

Then, when fetching next feed, I expect it to be NULL. However, I'm getting an instance of StreamFeed. If I do a while, like suggested in the readme, I'll get an infinite loop, because the eventStore->navigateStreamFeed (using previous) will always return always this stream feed:

{
  "title": "Event stream '5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef'",
  "id": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
  "updated": "0001-01-01T03:00:00Z",
  "streamId": "5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
  "author": {
    "name": "EventStore"
  },
  "headOfStream": false,
  "links": [
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
      "relation": "self"
    },
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/head/backward/20",
      "relation": "first"
    },
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/0/forward/20",
      "relation": "last"
    },
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/0/backward/20",
      "relation": "next"
    },
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/1/forward/20",
      "relation": "previous"
    },
    {
      "uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/metadata",
      "relation": "metadata"
    }
  ],
  "entries": []
}

I've checked why is that, and the reason is that the method navigateFeed will only return null when there is no link for previous, but this feed always has.

@dbellettini Any ideas of we could check on the length of "entries" to return null instead? or at least check in both properties?

Thanks,

Follow "linktos"

Currently "linktos" are not followed despite of the parameter in method call

[Proposal] Api && Wiki fix

You can't explore the API via Wiki or docblocks now.

Example wiki doesn't describe other way to iterate over stream than:

   $iterator = $es->forwardStreamFeedIterator('StreamName');

What about this?:

  $streamFeed = $es->openStreamFeed('testStream');
  $streamFeed = $es->navigateStreamFeed($streamFeed, \EventStore\StreamFeed\LinkRelation::PREVIOUS());

EventStore\StreamFeed\LinkRelation is very confusing.
I had no idea, how to create LinkRelation, because my IDE didn't show any available methods inside.
So after some time I figured out, that it use annotations to generate static methods.

My proposal is to remove annotations for value objects and create own implementation inside the classes. It will be easier to explore the API, through IDE.

Last thing is public method on top, private and protected on bottom of the class.
It makes class more readable, because most of people are interested in public ones, not the private/protected ones

HTTP Client Decoupling

I would like to refactor to decouple Guzzle as a required dependency and introduce a HTTP client interface that can be switched out. In a high volume system I would rather use persistent sockets for example which will allow me to keep pace with the speed of EventStore. While testing I can maintain 1000 requests per second with persistent sockets but only 200-250 a second with Guzzle on the same machine.

This also makes it easier to test the EventStore class in isolation and allow for dependency injection.

I would be more than happy to write this change, just want to get feedback on what everyone thinks first.

interface EventStore\Http\Client

$client = new EventStore\Http\Guzzle($uri);
$es = new EventStore\EventStore(Client $client);

$client = new EventStore\Http\PersistentSockets($uri);
$es = new EventStore\EventStore(Client $client);

$client = new EventStore\Http\Curl($uri);
$es = new EventStore\EventStore(Client $client);

Allow for custom headers in requests

Hi,

I have a feature request caused by/based on a bug in the EventStorm product itself: EventStore/EventStore#1574.

It would be nice if you could set headers in the requests ( such as in writeToStream ).

Situation
We have a cluster of three nodes. One master and two slaves.
The bug I linked above always sends the header Transport-Encoding header as chunked.
There's a chance we get an HTTP 415 error when we write to a stream. Eventstore slaves drop certain headers when they forward their write requests to the master node.
Thus some events get rejected, because they ended up on the slave node. The more slaves we add, the bigger the chance for this to occur. When we write to a stream on the master there is no issue.

Workaround
The reporter suggests a workaround by setting the Content-Length header. If there is a Content-Length header, the Transport-Encoding header is not added. The internal redirect works in this case.

This header( Transport-Encoding ) is presumably (?) added somewhere outside of your library ( PHP Curl implementation? Curl itself? ).

I can't find a way to add a request header for the writeToStream method from your EventStore class.
My only "clean" solution is to extend your class and overwrite your writeToStream method. This until they resolve the original issue, which has been open since March 2018.

conclusion
It seems like a neater solution if we could add extra header(s) to the request.

Added my quickfix below. Look for the Content-Length line. The length gets recalculated so you can default it to 0.

File:: dbellettini/geteventstore-core/src/EventStore/EventStore.php

    public function writeToStream($streamName, WritableToStream $events, $expectedVersion = ExpectedVersion::ANY)
    {
        if ($events instanceof WritableEvent) {
            $events = new WritableEventCollection([$events]);
        }

        $request = new Request(
            'POST',
            $this->getStreamUrl($streamName),
            [
                'ES-ExpectedVersion' => intval($expectedVersion),
                'Content-Type'       => 'application/vnd.eventstore.events+json',
                'Content-Length'     => '0',
            ],
            json_encode($events->toStreamData())
        );
        $this->sendRequest($request);

        $responseStatusCode = $this->getLastResponse()->getStatusCode();

        if (ResponseCode::HTTP_BAD_REQUEST == $responseStatusCode) {
            throw new WrongExpectedVersionException();
        }
    }

An alternative is to set the correct size immediately:

$request = $request->withAddedHeader( 'Content-Length', $request->getBody()->getSize() );

I'm sceptical about this feaure request, as it's an implementation to work around a bug in EventStore.

Let me know your thoughts. I may be missing something

EDIT: changed some phrasings for clarity.
EDIT: Removed the ** for bold in the code block as it's ignored.

Finalize EventStore\StreamFeed\Event

Currently the properties are private but the class not final. Additionally, the instantiation is hardcoded so we might as well make it "official" by finalizing the class.

writeToStream lacks support for other transport error types

The only error check is:

if (ResponseCode::HTTP_BAD_REQUEST == $responseStatusCode) { throw new WrongExpectedVersionException(); }

However, while running against an EventStore cluster Guzzle is failing to redirect properly and returning 500. By not handling this, it looked like the write call was successful when it was not.

Client does not catch 404 responses for deleted Events

So I've deleted a stream and the EventStore continues to serve the deleted events in my projections. At the moment I'm not sure how to exclude them from the projections but this results in an empty response that should be handled by the client.

Catchable Fatal Error: Argument 1 passed to EventStore\StreamFeed\Event::__construct()
must be of the type array, null given, called in
.../dbellettini/eventstore-client/src/EventStore/EventStore.php on line 124

A possible solution would be to simply return NULL instead of the Event if the $jsonResponse is NULL.

 $jsonResponse = $this->lastResponse->json();

if ($jsonResponse === NULL) {
    return NULL;
}

return new Event($jsonResponse);

This would be a breaking change though. Any suggestions / ideas?

dependency on old Ramsey/Uuid version 2.8

Hi, I think 2.8 is prior to a major upgrade
[quote from https://github.com/ramsey/uuid#what-to-do-if-you-see-a-rhumsaauuid-is-abandoned-message ]
Don't panic. Simply execute the following commands with Composer:

composer remove rhumsaa/uuid
composer require ramsey/uuid=^2.9
[/quote]
So when I try and install Ramsey 3 I am prevented from doing so by eventstoreclient.

Dependencies

nicolopignatelli/valueobjects has some requirements that just don't really make any sense like mathiasverraes/money (which is afaik, an example implementation for VOs).

Additionally the Enum thing is not supported by PHPStorm. I'd like deprecate that for simple constants. With that we would only have a dependency to guzzle. Then use rhumsaa/uuid directly for UUID generation.

Not saying that the valueobjects package is bad btw! Just a lot of unnecessary dependencies :)
If you guys agree I'd provide a PR soonish.

Fatal error when trying to open a stream

For whatever reason, eventstore sends a 401 for any internal projection (e. g. $ce-things). EventStore::ensureStatusCodeIsGood only checks for 404 and 410.

GET: http://127.0.0.1:2113/streams/$et-asdf -> 401
GET: http://127.0.0.1:2113/streams/et-asdf -> 404

In my opinion, anything that's not 2xx should be considered a failure.

The concrete error:

Catchable Fatal Error: Argument 1 passed to
  EventStore\StreamFeed\StreamFeed::__construct() must be of the type
  array, null given, called in
  [...] EventStore.php
  on line 207

Uuid VO wrapper

What is the advantage of having this UUID VO if in the end its using Ramsey implementation internally?

Reading streams by category

Is there a way to read the by category projection?

I'm new to getEventStore, and I have no interest of using their projection system. Instead, I would like to navigate through all the events for multiple streams myself. I made some testing projections like this one:

fromCategory('blog')
.when({
    'PostWasCreated': function(state, event) {
        state[event.data.postId] = {
            title: event.data.title,
            date: event.data.date,
            body: event.data.body
        }
    }
})

This allows me to project a collection of all the posts I have. Any idea on how I can replicate the same projection with this library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.