---
schema_version: "1"
id: bbd5e335e1fd3f00ab2522b3f41dc8c5646ef7c6927a9be1ba60f42f7fba8d41
title: Bitronix を使用したトランザクションの管理
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.9/using-bitronix-to-manage-transactions.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.9/using-bitronix-to-manage-transactions
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ac5f53ecf30227830c7e54ba3cce5df3b460782017c051b7a5e2d1b9235e5731
description: MuleSoft Documentation Site
release: "4.9"
latest: false
---
# Bitronix を使用したトランザクションの管理

Bitronix トランザクションマネージャーにより、中断されていたトランザクションを Mule の再起動時に自動的に復元できます。

Mule インスタンスがクラッシュするか、リソースマネージャー (JMS ブローカーやデータベースなど) との接続が失われると、2 フェーズコミットプロトコル (2PC) の準備フェーズとコミットフェーズの間にあるトランザクションは失敗します。この場合、トランザクションマネージャーは、復元プロセスを実行して、障害の発生時に実行途中だったトランザクションを完了させる必要があります。このような障害はあまり発生しませんが、発生した場合のデータの一貫性を維持するためのメカニズムが必要です。

## [](#単一アプリケーションでの-bitronix-の使用)単一アプリケーションでの Bitronix の使用

Bitronix を使用するようにアプリケーションを設定するには、次のようにフローの外部でトランザクションマネージャーを宣言します。

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
      xsi:schemaLocation="
       http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
       http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd">
    <bti:transaction-manager/>
...
</mule>
```

## [](#mule-ドメインのすべてのアプリケーションでの-bitronix-の使用)Mule ドメインのすべてのアプリケーションでの Bitronix の使用

Mule ドメインに関連付けられているすべてのドメインで Bitronix を使用するには、次のようにドメイン設定ファイルで Bitronix をトランザクションマネージャーとして定義します。このように設定すると、ドメインに関連付けられているすべてのアプリケーションが Bitronix を使用するため、個別のアプリケーションでトランザクションマネージャーを宣言する必要はありません。

```xml
<?xml version="1.0" encoding="UTF-8"?>
<domain:mule-domain
        xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:domain="http://www.mulesoft.org/schema/mule/ee/domain"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/ee/domain http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd
http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd">
	<bti:transaction-manager/>

    <!-- ... -->

</domain:mule-domain>
```

ドメインの詳細については、​[「共有リソース」](https://docs.mulesoft.com/jp/mule-runtime/4.9/shared-resources)​を参照してください。

## [](#anypoint-studio-からの-bitronix-の追加)Anypoint Studio からの Bitronix の追加

Studio からアプリケーションやドメインに Bitronix を追加する手順は次のとおりです。

1. **\[Global Elements (グローバル要素)\]**​ タブに移動します。
2. **\[Create (作成)\]**​ ボタンをクリックします。
3. `Bitronix Transaction Manager`​ を検索します。
    
    ![Anypoint Studio の \[Bitronix Transaction Manager (Bitronix トランザクションマネージャー)\] が含まれるオプションでグローバル要素種別を選択する設定タブ](_images/bitronix-studio.png)

## [](#bitronix-トランザクションマネージャーの設定)Bitronix トランザクションマネージャーの設定

Bitronix のデフォルト設定値は、ほとんどのユースケースに適していますが、システムプロパティまたは ​`$MULE_HOME/conf`​ ディレクトリの ​`wrapper.conf`​ ファイルを使用してトランザクションマネージャーをカスタマイズすることもできます。

Bitronix の設定属性を下表に示します。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 35%;">
<col style="width: 40%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">設定属性</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">デフォルト値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.bitronix.transactiontimeout</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">XA トランザクションのタイムアウト (秒)。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">60</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.bitronix.recoveryinterval</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">XA トランザクションの復元実行間隔 (秒)。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">60</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mule.bitronix.serverId</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">XA トランザクションログに登録するためのトランザクションマネージャーの一意の ID。この値は、Mule インスタンスごとに一意である必要があります。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ホスト IP と、HA で動作している場合はクラスターノード ID との組み合わせ。</p></td>
</tr>
</tbody>
</table>

### [](#データベースのプーリングデータソースの設定)データベースのプーリングデータソースの設定

Bitronix とのインテグレーションにより、Database Connector でリソースプーリングを実装するときには必ず使用する Database Connector 用のデータソース接続プールが提供されます。

すべての接続用の共有プーリングデータソースを設定できます。これにより、アプリケーションによってこれらのデータソースが集中して使用されていない場合の接続使用状況が改善されます。

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule-domain xmlns="http://www.mulesoft.org/schema/mule/ee/domain"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:db="http://www.mulesoft.org/schema/mule/db"
      xmlns:bti="http://www.mulesoft.org/schema/mule/ee/bti"
      xmlns:spring="http://www.mulesoft.org/schema/mule/spring"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/ee/bti http://www.mulesoft.org/schema/mule/ee/bti/current/mule-bti-ee.xsd
               http://www.mulesoft.org/schema/mule/ee/domain http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd
               http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">

    <spring:config name="springConfig" files="domain-config/datasource-beans.xml"/>

    <bti:transaction-manager/>

    <bti:xa-data-source-pool name="pooledDataSource" dataSource-ref="jdbcDataSource"/>

    <db:generic-config name="dbConfig" dataSource-ref="pooledDataSource"/>

</mule-domain>
```

プーリングデータソースの設定属性を下表に示します。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 35%;">
<col style="width: 45%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">属性</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">必須</th>
<th class="tableblock halign-left valign-top">デフォルト値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">コネクタが参照できるようにプールを識別します。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">はい</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>datasource-ref</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">JDBC データソースオブジェクトへの参照。​<code>XADataSource</code>​ オブジェクトを用意する必要があります。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">はい</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>minPoolSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プールに格納する最小の接続数を定義します。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>maxPoolSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プールに格納できる最大の接続数を定義します。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>maxIdleTime</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プール内のアイドル接続を閉じるまでの秒数。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">60</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>acquireIncrement</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プールが枯渇したときに一度に取得を試みる接続数を決定します。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>acquireTimeoutSeconds</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プールが枯渇したときに ​<code>getConnection()</code>​ を呼び出しているクライアントが接続のチェックインまたは取得を待つ秒数。0 を指定すると無限に待ちます。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">30</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>preparedStatementCacheSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プールされた接続ごとにキャッシュされるステートメント数を決定します。0 を指定するとキャッシュは無効になります。</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">いいえ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
</tr>
</tbody>
</table>

## [](#トランザクションの復元)トランザクションの復元

Mule には自動的に実行される復元手順があり、設定は不要です。システムクラッシュ後に Mule が再起動すると、XA トランザクションに関与していたすべてのリソースに接続してトランザクション復元プロセスを開始し、すべてのシステムを一貫した状態に保ちます。

## [](#関連情報)関連情報

- [共有リソース](https://docs.mulesoft.com/jp/mule-runtime/4.9/shared-resources)
- [トランザクションの管理](https://docs.mulesoft.com/jp/mule-runtime/4.9/transaction-management)
- [XA トランザクション](https://docs.mulesoft.com/jp/mule-runtime/4.9/xa-transactions)