久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='h0prS'></tfoot>

      <legend id='h0prS'><style id='h0prS'><dir id='h0prS'><q id='h0prS'></q></dir></style></legend>
      • <bdo id='h0prS'></bdo><ul id='h0prS'></ul>
    1. <i id='h0prS'><tr id='h0prS'><dt id='h0prS'><q id='h0prS'><span id='h0prS'><b id='h0prS'><form id='h0prS'><ins id='h0prS'></ins><ul id='h0prS'></ul><sub id='h0prS'></sub></form><legend id='h0prS'></legend><bdo id='h0prS'><pre id='h0prS'><center id='h0prS'></center></pre></bdo></b><th id='h0prS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='h0prS'><tfoot id='h0prS'></tfoot><dl id='h0prS'><fieldset id='h0prS'></fieldset></dl></div>
      1. <small id='h0prS'></small><noframes id='h0prS'>

        如何在 DDD 中管理域邏輯和事件之間的事務(wù)?

        How manage transaction between domain logic and events in DDD?(如何在 DDD 中管理域邏輯和事件之間的事務(wù)?)
          <bdo id='kV3H6'></bdo><ul id='kV3H6'></ul>
          • <i id='kV3H6'><tr id='kV3H6'><dt id='kV3H6'><q id='kV3H6'><span id='kV3H6'><b id='kV3H6'><form id='kV3H6'><ins id='kV3H6'></ins><ul id='kV3H6'></ul><sub id='kV3H6'></sub></form><legend id='kV3H6'></legend><bdo id='kV3H6'><pre id='kV3H6'><center id='kV3H6'></center></pre></bdo></b><th id='kV3H6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='kV3H6'><tfoot id='kV3H6'></tfoot><dl id='kV3H6'><fieldset id='kV3H6'></fieldset></dl></div>

          • <tfoot id='kV3H6'></tfoot>

            <small id='kV3H6'></small><noframes id='kV3H6'>

            <legend id='kV3H6'><style id='kV3H6'><dir id='kV3H6'><q id='kV3H6'></q></dir></style></legend>

              <tbody id='kV3H6'></tbody>

                1. 本文介紹了如何在 DDD 中管理域邏輯和事件之間的事務(wù)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在研究 DDD 和事件源中的編程.

                  我看到一個(gè)示例,當(dāng)調(diào)用域邏輯時(shí)(例如 Order.placeOrder()),它會(huì)發(fā)布一個(gè)事件(例如 OrderPlaced).并且該事件將作為事件存儲(chǔ)發(fā)送到 MQ.

                  領(lǐng)域邏輯(Order.placeOrder())應(yīng)該是一個(gè)原子API,如果使用Spring作為事務(wù)管理器,它應(yīng)該有@Transactional注解.p>

                  現(xiàn)在我的問題是:

                  1. 如何確保數(shù)據(jù)庫更改和事件發(fā)送在同一個(gè)事務(wù)中?即,如果在將數(shù)據(jù)提交到 DB 時(shí)出現(xiàn)任何錯(cuò)誤,則該事件不應(yīng)該發(fā)送到 MQ.

                    我知道有像 XA 或 2 階段提交這樣的解決方案來強(qiáng)制數(shù)據(jù)庫更新和在同一事務(wù)中發(fā)送 MQ 消息.但現(xiàn)在似乎沒有被廣泛使用.

                  2. 如果還是使用Spring的@Transactional注解,沒有XA,是不是我們可以在事務(wù)提交成功后做一些邏輯呢?這樣做的最佳做法是什么?

                  解決方案

                  以下兩個(gè)屬性必須具備才能擁有一個(gè)可靠的系統(tǒng):

                  • P1:已發(fā)布的域事件必須描述真正發(fā)生的變化(即確保沒有鬼事件開始四處飛舞).
                  • P2:對(duì)觸發(fā)域事件的數(shù)據(jù)庫進(jìn)行更改必須導(dǎo)致事件被發(fā)布(即不會(huì)丟失事件).

                  有以下幾種可能來實(shí)現(xiàn)這一點(diǎn),所有這些都是我自己使用過的,或者在項(xiàng)目中看到過的:

                  1. 使用與您的應(yīng)用程序使用相同數(shù)據(jù)庫的消息傳遞基礎(chǔ)架構(gòu),以便可以使用單個(gè)事務(wù).當(dāng)一個(gè)非常簡單的消息傳遞基礎(chǔ)架構(gòu)就足夠了,并且團(tuán)隊(duì)決定自己構(gòu)建它時(shí),此解決方案是可行的.

                  2. 使用 2 階段提交.我沒有這個(gè)不再使用的印象,但可能它很少被談?wù)摚驗(yàn)樗皇腔ㄉ诘募夹g(shù)......

                  3. 使用一些巧妙的技巧來確保這兩個(gè)條件都成立.例如.用我所說的雞和蛋的解決方案:

                    • 始終先同步發(fā)布事件,然后持久化到數(shù)據(jù)庫.這確保了 P2 成立.
                    • 然后使用事件處理器檢查事件流并檢查是否可以在數(shù)據(jù)庫中找到事件.如果沒有,請(qǐng)從流中刪除該事件.這可確保 P1 成立.

                  解決方案 3 需要仔細(xì)設(shè)計(jì)和審查系統(tǒng)每個(gè)部分在故障行為方面所做的保證,因此它可能是最難做到的.但它也是一個(gè)非常優(yōu)雅的解決方案,一旦它起作用.

                  順便說一句,我不同意應(yīng)將 Spring 注釋添加到域?qū)ο笾校菓?yīng)添加到相應(yīng)的應(yīng)用程序服務(wù)中.這只是一個(gè)旁注.

                  I am studying on the programming in DDD and event source.

                  I saw one example that when a domain logic was called (e.g. Order.placeOrder()) it would publish an event (e.g. OrderPlaced). And the event would be sent to MQ as the event store.

                  The domain logic (Order.placeOrder()) should be an atomic API, and it should have @Transactional annotation if using Spring for the transaction manager.

                  And now my question is:

                  1. How to make sure the DB change and event sending are within the same transaction? i.e. If there any error when committing data into DB, the event should never send to MQ.

                    I know that there is solution like XA or 2 phase commit to force the DB update and sending MQ messages within the same transaction. But seems it is not widely used nowadays.

                  2. If still using Spring @Transactional annotation and no XA, is it possible that we do some logic after the transaction is committed successfully? What is the best practice to do that?

                  解決方案

                  The following two properties must hold to have a reliable system:

                  • P1: Published domain events MUST describe a change that really happened (i.e. make sure no ghost events start flying around).
                  • P2: Changes to the DB that trigger domain events MUST result in an event being published (i.e. don't lose events).

                  There are the following possibilities to achieve this, all of which I've either used myself or seen being used in a project:

                  1. Use a messaging infrastructure that uses the same database as your application, so that a single transaction can be used. This solution is viable when a very simple messaging infrastructure suffices, and the team decides to build it themselves.

                  2. Use 2 phase commits. I don't have the impression that this is not used anymore, but maybe it's less talked about, because it isn't fancy technology...

                  3. Use some clever trickery to ensure both conditions hold. E.g. with what I call the chicken and egg solution:

                    • Always publish events synchronously first, then persist to the DB. This ensures P2 holds.
                    • Then use an event processor that inspects the event stream and checks whether an event can be found in the DB. If not, remove the event from the stream. This ensures P1 holds.

                  Solution 3 requires careful design and review of the guarantees each part of the system makes in terms of failure behavior, so it is probably the most difficult one to get right. But it is also a very elegant solution, once it works.

                  By the way, I don't agree that Spring annotations should be added to domain objects, but rather to the respective app services. This only as a side note.

                  這篇關(guān)于如何在 DDD 中管理域邏輯和事件之間的事務(wù)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                    <tbody id='3lCld'></tbody>

                    <i id='3lCld'><tr id='3lCld'><dt id='3lCld'><q id='3lCld'><span id='3lCld'><b id='3lCld'><form id='3lCld'><ins id='3lCld'></ins><ul id='3lCld'></ul><sub id='3lCld'></sub></form><legend id='3lCld'></legend><bdo id='3lCld'><pre id='3lCld'><center id='3lCld'></center></pre></bdo></b><th id='3lCld'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3lCld'><tfoot id='3lCld'></tfoot><dl id='3lCld'><fieldset id='3lCld'></fieldset></dl></div>

                      <small id='3lCld'></small><noframes id='3lCld'>

                        • <tfoot id='3lCld'></tfoot>

                            <bdo id='3lCld'></bdo><ul id='3lCld'></ul>
                            <legend id='3lCld'><style id='3lCld'><dir id='3lCld'><q id='3lCld'></q></dir></style></legend>
                            主站蜘蛛池模板: аⅴ资源新版在线天堂 | 嫩草视频在线看 | 久久久看| a在线观看 | 国内精品久久久久久 | 午夜av在线| 久久久九九| 凹凸日日摸日日碰夜夜 | 成人在线免费电影 | 日韩最新网站 | 日韩高清一区二区 | 香蕉大人久久国产成人av | 亚洲欧美日韩电影 | 国产在线区 | 久久久亚洲成人 | 久久精品视频91 | 在线观看中文字幕 | 国产精品一区二区视频 | 亚欧性视频| 国产精品国产成人国产三级 | 精品欧美一区二区三区久久久 | 视频在线亚洲 | h视频在线免费 | 午夜精品久久久久久久久久久久久 | 视频一区二区中文字幕日韩 | 亚州无限乱码 | 99爱国产 | 九九av | 日韩不卡在线 | 日本韩国电影免费观看 | 午夜欧美 | 国产97在线视频 | 国产成人精品免高潮在线观看 | 午夜av影院| 亚洲欧美日韩精品久久亚洲区 | 亚洲精品色 | 超碰综合 | 久久的色 | 久久久久成人精品亚洲国产 | 国产三区视频在线观看 | 欧美黑人狂野猛交老妇 |