<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## BeetlSQL Saga BeetlSQL提供倆種Saga實現但只需一種編碼風格。第一種實現是用于單機多庫,第二種實現則是你覺得需要改成微服務的時候,可以無縫切換成微服務 第一種適用于單體系統,需要操作多個庫。不需要Saga-Server參與 ```java /** * 參考代碼org.beetlsql.sql.saga.test.standalone.StandaloneSagaTest 或者 springboot * org.beetlsql.sql.saga.test.spring.SpringBootSagaTest */ @Test public void simple(){ SagaContext sagaContext = SagaContext.sagaContextFactory.current(); UserMapper userMapper = sqlManager.getMapper(UserMapper.class); long count = sqlManager.allCount(User.class); try{ sagaContext.start() User user = new User(); user.setName("abc"); userMapper.insert(user); User user2 = new User(); user2.setName("efg"); userMapper.insert(user2); if(1==1){ throw new RuntimeException("模擬異常"); } sagaContext.commit(); }catch(RuntimeException ex){ sagaContext.rollback(); } long afterCount = sqlManager.allCount(User.class); Assert.assertEquals(count,afterCount); } ``` 假設User是個多庫設計(關于BeetlSQL如何使用分庫分表,參考BeetlSQL3 多庫使用),開發者只需在套用如下模板 ```java SagaContext sagaContext = SagaContext.sagaContextFactory.current(); try{ sagaContext.start(); //任何操作,或者是調用嵌套Saga事務的其他代碼 sagaContext.commit(); }(Exception ex){ sagaContext.rollback(); } ``` 第二種適合微服務,BeeltSQL還需要通過Saga—Server來管理回滾任務,但編程模式跟上面是一致的,如下 ```java /** * 代碼參考 源碼 sql-saga/sql-saga-microservice/sql-saga-microservice-demo */ SagaContext sagaContext = SagaContext.sagaContextFactory.current(); try { //需要一個gid標志唯一的事務,如訂單號 sagaContext.start(gid); //模擬調用倆個微服務,訂單和用戶,訂單系統和用戶系統也可以使用同樣的模板 rest.postForEntity(orderAddUrl, null,String.class, paras); rest.postForEntity(userBalanceUpdateUrl, null,String.class, paras); if (1 == 1) { throw new RuntimeException("模擬失敗,查詢saga-server 看效果"); } } catch (Exception e) { sagaContext.rollback(); return e.getMessage(); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看