---
schema_version: "1"
id: 4bddecbbb3a9b8a10f57ada9d5efd53d2c87feb2b6d1af6f9e3b141e8e79291f
title: Async (<async/>)
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/anypoint-code-builder/acb-component-async.md
canonical_url: https://docs.mulesoft.com/jp/anypoint-code-builder/acb-component-async
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8b0d94bcf2ca066b47263ef6445b8ce7136a2504278ef0248ddee5797b47c4ac
description: MuleSoft Documentation Site
latest: true
---
# Async (<async/>)

![logo cloud IDE](/mulesoft/current/ja-jp/_/img/logos/deployment-cloud-ide.png "Cloud IDE") Cloud IDE

![logo desktop IDE](/mulesoft/current/ja-jp/_/img/logos/deployment-desktop-ide.png "Desktop IDE") Desktop IDE

コンポーネントをスコープ内でグループ化し、非同期方式でメインフローと同時に実行します。

アプリケーションのメインフローは、Async スコープの開始後や処理後に実行され続けます。非同期フローに埋め込まれた最後のメッセージプロセッサーがタスクを完了するまで、フローは一時停止する必要はありません。Async は、応答を開始フローに返信する必要がない、時間のかかる操作 (ファイルの印刷やメールサーバーへの接続など) を実行する場合に役立ちます。

同時分岐処理を容易にするため、Async スコープは受信したメッセージの 1 つのコピーを独自の処理ブロック内にある最初の埋め込みメッセージプロセッサーに送信します。同時に、メインフロー内の次のメッセージプロセッサーにメッセージの別のコピーを送信します。

Async スコープは「ファイヤアンドフォゲット」方式で実行されるため、スコープ内の処理の結果はメインフローでは使用できません。

## [](#component-xml)コンポーネント XML

このコンポーネントは、次の XML 構造をサポートします。

```xml
<async maxConcurrency="" name="">
    <!-- Components to execute asynchronously -->
</async>
```

Async (​`<async/>`​) 属性は UI および XML で設定できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 60%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">属性名</th>
<th class="tableblock halign-left valign-top">属性 XML</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Async (非同期)</strong>​ (デフォルト)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>doc:name</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>設定 XML ファイルにのみ表示される編集可能な名前。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>[Name (名前)]</strong>​ または ​<strong>[Display Name (表示名)]</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>name</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>キャンバスに表示されるコンポーネントの編集可能な名前。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Max concurrency (最大同時実行)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>maxConcurrency</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>スコープが処理できる同時メッセージの最大数を設定します。デフォルトでは、メッセージの処理時にパフォーマンスを最適化するために使用される最大スレッド数は、コンテナスレッドプールによって異なります。スコープが最大数の同時メッセージを処理している間は追加要求を受信できません。
 <br>
 <br>
スコープが要求を 1 つずつ処理するようにするには、​<code>maxConcurrency</code>​ を ​<code>1</code>​ に設定します。
 <br>
 <br>
最大同時実行値に達した後の Mule の動作についての詳細は、「​<a href="https://docs.mulesoft.com/mule-runtime/latest/execution-engine#backpressure" class="xref page">バックプレッシャーの管理</a>​」を参照してください。</p>
</div></div></td>
</tr>
</tbody>
</table>

## [](#async-スコープとサブフローの比較)Async スコープとサブフローの比較

Async スコープは、次の点でサブフローと異なります。

- メインフローの例外戦略を継承しない。
    
    Async スコープでエラーを処理するには、Try スコープを使用する。
- メッセージを非同期的に処理する。
- データをメインフローに渡さない。
- メインフロースレッドの範囲内に存在する。
- Flow Reference コンポーネントからはコールされない。
- 再利用できない。

Async スコープが Mule メッセージのコピーを受信しても、ペイロードはコピーされません。同じペイロードオブジェクトが両方の Mule メッセージによって参照されます。そのメッセージの 1 つは元のフローに沿って進み続け、もう 1 つは Async スコープによって処理されます。

メッセージのペイロードが可変オブジェクト (異なる項目が含まれる Bean など) であり、Async スコープ内のメッセージプロセッサーがいずれかの項目の値を変更した場合、Async スコープ外部のメッセージプロセッサーが変更された値を参照できます。

## [](#async-スコープの設定例)Async スコープの設定例

次の XML フラグメントは、アプリケーションフローでの Async スコープの設定例を示しています。Async スコープにある ​`file:read`​ 操作は、トリガーされると非同期に実行され、アプリケーションはフローの次の操作である ​`http:request`​ の処理に移ります。

```xml
<!-- Main application flow -->
<flow name="myMainFlow" >
  <!-- HTTP Listener as event source -->
  <http:listener doc:name="Listener" />
  <!-- A Transform operation that executes as part of the main flow -->
  <ee:transform doc:name="Transform Message" >
    <ee:message >
      <ee:set-payload >
        <![CDATA[%dw 2.0
        output application/json
        ---
        payload]]>
      </ee:set-payload>
    </ee:message>
  </ee:transform>
    <!-- The Async scope executes its message processors in a different thread, while the main flow continues its execution -->
    <async doc:name="Async" >
      <!-- A Try scope to handle errors, because the async scope does not inherit the error strategy from the flow -->
      <try doc:name="Try" >
        <!-- A Write operation -->
        <file:write doc:name="Write" path="/" />
        <!-- Error handling strategy defined in the Try scope, to handle errors during the Async scope execution -->
        <error-handler >
          <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" type="ANY">
            <!-- Some error handling logic for this strategy -->
            ...
          </on-error-continue>
        </error-handler>
      </try>
    </async>
  <!-- This HTTP Request operation starts executing without waiting for the Async scope to finish its execution -->
  <http:request method="GET" doc:name="Request" />
</flow>
```

## [](#see-also)関連情報

- [トランザクションによるスコープとルーターへの影響](https://docs.mulesoft.com/mule-runtime/latest/transaction-management#tx_scopes_routers)
- [back-pressure と maxConcurrency](https://docs.mulesoft.com/mule-runtime/latest/tuning-backpressure-maxconcurrency)