English 中文(简体)
CQRS & ElasticSearch - using ElasticSearch to build read model
原标题:

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 processes 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





相关问题
How to handle set based consistency validation in CQRS?

I have a fairly simple domain model involving a list of Facility aggregate roots. Given that I m using CQRS and an event-bus to handle events raised from the domain, how could you handle validation ...

CQRS 和电子邮箱通知

阅读CLCS时,有很多人谈到电子邮件通知,想从哪里获得数据。 Imagine a senario, 一名用户邀请其他用户参加一次活动。 告知用户他......

CQRS event versioning

Versioning If your events changes you would create a new version of that event, and keep the old ones. To keep your domain code form being bloated with handling of all versions of events you would ...

CQRS - The query side

A lot of the blogsphere articles related to CQRS (command query repsonsibility) seperation seem to imply that all screens/viewmodels are flat. e.g. Name, Age, Location Of Birth etc.. and thus the ...

Domain queries in CQRS

We are trying out CQRS. We have a validation situation where a CustomerService (domain service) needs to know whether or not a Customer exists. Customers are unique by their email address. Our ...

CQRS and CRUD screens

One of the basic tenets of CQRS, as I understand it, is that commands should be behaviour-centric, and have a value in the business or the UL, and not data-centric, ie., CRUD. Instead of focusing on ...

热门标签