开发者

CQRS & ElasticSearch - using ElasticSearch to build read model

开发者 https://www.devze.com 2023-01-30 01:51 出处:网络
Does anyone use ElasticSearch for building read model in CQRS approach? I have some questions related to such solution:

Does anyone use ElasticSearch for building read model in CQRS approach? I have some questions related to such solution:

  1. Where do you store your domain events? In JDBC database? In ElasticSearch?
  2. Do you build indexes by event handlers that pro开发者_如何学JAVAcesses domain events or using ElasticSearch River functionality?
  3. How do you handle complete rebuild of view model - for example in case when view is corrupted? Do you process all events to rebuid view?


Where the authoritative repository for your domain event is located is an implementation detail. For example, you could store serialized versions on S3 or CouchDB or any other number of storage implementations. The easiest if you're just getting started is a relational database.

Typically people use event handlers that understand the business intent behind each message and can then properly denormalize the message into the read model structure appropriate for the needs of your views.

If the view model is ever corrupted or perhaps you have a bug in a view model handler, there are a few simple steps to follow after fixing the bug:

  1. Temporarily enqueue the flow of events arriving from the domain--these are the typical messages that are being published as your domain is doing work. We still want these messages, but not just yet. This could be done by turning off any message bus or not connecting to your queuing infrastructure if you use one.

  2. Read all events from event storage. As each event is received (this can be done through a simple DB query), run each message through the appropriate message handler. Make sure that you keep track of the last 10,000 (or so) identifiers for all messages processed.

  3. Now reconnect to your queues and start processing normally. If the identifier for the message has been seen, drop the message. Otherwise, process it normally.

The reason for tracking identifiers is to avoid a race condition where you're getting all events from the event store but the same message is coming across through the message queue.

Another technique that's highly related, but involves keeping track of all message identifiers can be found here: http://blog.jonathanoliver.com/2011/03/removing-2pc-two-phase-commit.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号