doufu6196 2018-08-20 09:29
浏览 27
已采纳

在PROOPH中通过投影创建的读取模型中等待新记录

I use prooph(https://github.com/prooph) so I have my write model, where I store events like below(aggregate table):

Write model

when I run projection in background using command:

php bin/console event-store:projection:run card_projection

I have read model like below:

Read model

In front of my background application I have rest API, where I create event:

CardWasAdded

through url:

POST /cards

and I receive code 201.

After that I refresh my list through url:

GET /cards

The issue is that sometimes this new event is not processed by projection. So the question is:

How to manage that issue?

  1. Should I wait 2 sec or some time?(ugly hack for me).
  2. Should I process event after is inserted - not use projection process in background?
  • 写回答

2条回答 默认 最新

  • dtnat80842 2018-08-20 12:01
    关注

    My answer is not prooph specific, but here are some strategies you may use in any CQRS system:

    1. Just accept the fact read-model is not imeediately consistent (do nothing). Example - when I post something to Twitter, i may not immediately see my post in the stream and this is ok. It will appear there eventually.
    2. Optimistic UI update. Just update UI as if your command went through. If not - not a big deal. Example - Like something on Twitter. You don't need to wait for confirmation. If somehow like failed - its status will come with next read model refresh.
    3. Wait at the API endpoint. Your API was called, you issue a command, and look for particular read model update to happen. Fail on timeout.
    4. Wait at UI level. You send a command and display some "Waiting" UI element until your query returns what you are looking for, or fail on timeout.

    With strategy 3 and 4 you may use some kind of server signaling - sockets or something like this. Your read model might be able to confirm it was updated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错