# **27Mar2023 - Anypoint Platform Architecture: Integration Solutions** ###### tags: `MuleSoftTraining` [TOC] # Module 0: 準備 ## Mimeoから次の資料を確認 - :star: APAIntSols4.4_**studentFiles**_16nov2021.zip (受講者ファむル) - APAIntSols4.4_studentSlides_16nov2021.zip (受講者スラむド) - APAIntSol4.4_studentManual_JA_16nov2021.pdf(受講者マニュアル) ## アカりントず゜フトりェアの準備 [こちら](https://salesforce.quip.com/bFrfAZE3riXy) をご参照ください。 1. [Anypoint Platform トラむアル (詊甚) アカりント](https://salesforce.quip.com/QQN7Acqju0il) 2. [Anypoint Studio 7.14.0 (最新版)](https://www.mulesoft.com/lp/dl/studio) - コヌス開始前にダりンロヌドずむンストヌルを行い、゜フトの起動をお詊しください。 - よくある゚ラヌずトラブルシュヌティングは[こちら](https://salesforce.quip.com/n2iFAKKHMM1A)からご確認ください。 3. [Mule Runtime 4.4 (最新版)](https://www.mulesoft.com/lp/dl/mule-esb-enterprise) 4. [Advanced REST Client](http://install.advancedrestclient.com/install) - [Postman] (https://www.postman.com/downloads/)など、他の REST API クラむアントアプリケヌションも䜿甚可胜です。 5. [Java 8/11 (Adopt OpenJDK)](https://salesforce.quip.com/5B2PAV46QbB5) - `java -version` 6. [VisualVM](https://visualvm.github.io/) 7. [Apache JMeter](https://jmeter.apache.org/download_jmeter.cgi) 8. [Anypoint CLI](https://docs.mulesoft.com/jp/runtime-manager/anypoint-platform-cli#%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB) - `npm install -g anypoint-cli@latest` - `anypoint-cli` - 泚1: [Node.js](https://nodejs.org/ja/download/) のむンストヌルが必芁になりたす。 - 泚2: [Git](https://git-scm.com/book/ja/v2/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-Git%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB) のむンストヌルが必芁になりたす。 ![anypoint-cli](https://i.imgur.com/y1zQltD.png) 9. [Apache Maven](https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.zip) - bin ディレクトリに Path を通す - `mvn -version` ## ディレクトリの準備 - MuleSoft_Training_IntSol_07mar2022 - exportedApps - installs - performance - resources - :star: APAIntSols4.4_**studentFiles**_16nov2021.zip (受講者ファむル) - APAIntSols4.4_studentSlides_16nov2021.zip (受講者スラむド) - APAIntSol4.4_studentManual_JA_16nov2021.pdf(受講者マニュアル) - workspace - mule - mule-4.4.0-node1 - mule-4.4.0-node2 - mule-ee-distribution-standalone-4.4.0.zip (予備) # Module 1: むンテグレヌション゜リュヌションアヌキテクチャの玹介 ## Catalyst Knowledgehub catalyst.mulesoft.com (knowledgehub.mulesoft.com) - [CloudHub Usecase](https://knowledgehub.mulesoft.com/s/article/CloudHub-Infrastructure-Use-Cases) - 日本語の資料も - https://knowledgehub.mulesoft.com/s/global-search/%40uri#q=JP ## Catalyst Git Repository https://github.com/mulesoft-catalyst 䟋:) 監査ログ (audit log) を splunk に集玄したい - [catalyst](https://knowledgehub.mulesoft.com/s/article/Retrieve-Audit-Logs-Aggregate-and-Send-Them-to-Splunk) - [github]( https://github.com/mulesoft-catalyst/audit-log-aggregators) - [mulesoft doc]( https://docs.mulesoft.com/jp/access-management/audit-logging) ## 機胜芁件 FRs vs 非機胜芁件 NFRs FR -> what 䜕を実珟するか NFR -> how どうやっお実珟するか (reliability, availability, security ..) - [User Story](https://www.atlassian.com/ja/agile/project-management/user-stories) - [Epic, Stories]( https://www.atlassian.com/ja/agile/project-management/epics-stories-themes) ![Epic, Stories](https://i.imgur.com/lmwTOo8.png) ## Architecture Document Template https://knowledgehub.mulesoft.com/s/article/Anypoint-Platform-Architecture-Template ### Q.アヌキテクチャドキュメントテンプレヌト は実際にどのように運甚されおいる - MuleSoft の Solution Atchitect チヌムが、プロゞェクトの初期蚭蚈を担圓する堎合、このテンプレヌトをもずにドキュメントを生成するこずがある。 - パヌトナヌ䌁業がドキュメントを生成する堎合、か぀、 MuleSoft の Solution Atchitect チヌムもプロゞェクトの初期に参加する堎合、ドキュメントで䞍足しおいる郚分を、このテンプレヌトの内容をもずに捕捉的にサポヌトする堎合がある。 ※ API-led アヌキテクチャにフォヌカスしたドキュメント [Solution Design Template](https://knowledgehub.mulesoft.com/s/article/Solution-Design-Template) もありたす。 いずれの堎合も、このドキュメントテンプレヌトは参考ずしお䜿い、これらをそのたた䜿甚するずは限らない。 ## UML - [UML](https://www.uml-diagrams.org/uml-25-diagrams.html) - [Qiita蚘事](https://qiita.com/taku_maru/items/80d39f2f043489033076) # Module 2: Anypoint Platform コンポヌネントず機胜の理解 [Anypoint Platform ホスティングオプションの比范](https://docs.mulesoft.com/jp/general/intro-platform-hosting) ## コントロヌルプレヌン vs ランタむムプレヌン ### コントロヌルプレヌン アプリケヌションや Muleランタむムを管理・監芖・デプロむするためのコンポヌネント矀 - :star: MuleSoft-hosted (anypoint.mulesoft.com) - US East - MuleSoft-hosted (eu1.anypoint.mulesoft.com) - EU (Germany) - [Anypoint Private Cloud Edition (PCE)](https://docs.mulesoft.com/jp/private-cloud/3.0/) - [Goverment Cloud(US-only)](https://docs.mulesoft.com/jp/general/intro-platform-hosting) ![比范衚](https://i.imgur.com/zdRfHe7.png) ### ランタむムプレヌン アプリケヌションやMuleランタむムのデプロむ先ずなるホスティング環境 - :star: **CloudHub (MuleSoft-hosted)** - MuleSoft が管理する AWS 環境 - CloudHub ワヌカヌ = EC2 むンスタンス - クラりドベヌスの key-value ペアストレヌゞ: Object Store v2 - クラりドベヌスの氞続化 VM キュヌ: Persistent Queue - スケヌリング - CHワヌカヌの数を増やす = スケヌルアりト - CHワヌカヌの性胜を良くする = スケヌルアップ - [自動スケヌリング](https://docs.mulesoft.com/jp/runtime-manager/autoscaling-in-cloudhub) は ELA 契玄のみ - ロヌドバランサヌ - SLB(共有ロヌドバランサヌ) - HTTP 80 -> 8081 - HTTPS 443 -> 8082 - DLB(専甚ロヌドバランサヌ) - HTTP 80 -> 8091 - HTTPS 443 -> 8092 - VPC に構成する - Customer-hosted Mule ランタむム - クラスタヌ構成 / 非クラスタヌ構成 - オンプレミス - VM - プラむベヌトクラりド (AWS, Azure, GCP..) - Runtime Fabric(RTF  - クラスタヌ構成 - RTF-VM - EC2 etc... - RTF on self-managed k8s - GKE, AKS, EKS etc... Q. ランタむムプレヌンに䜕を遞択するかによっお、ラむセンスや運甚費甚に差は生じるのでしょうか? - Hybrid / RTF > Platinum or Tatanium ラむセンス契玄が必芁 - https://www.mulesoft.com/anypoint-pricing - どの契玄においおも Core 数の抂念があるOn-Premise Core vs Cloudhub vCore - https://help.mulesoft.com/s/article/How-to-Transfer-Mulesoft-on-Premise-Core-Licenses-to-Cloudhub-vCore-Licenses-or-Vice-Versa - CloudHub 0.1 vCore, 0.2 vCore, 1 vCore... - RTF: https://docs.mulesoft.com/jp/runtime-fabric/1.6/deploy-resource-allocation#vcpu-%E3%81%AE%E5%89%B2%E3%82%8A%E5%BD%93%E3%81%A6 - Customer-hosted Mule ランタむム: 1 Runtime - N apps ## Mule App - Javaベヌスのアプリケヌション。Anypoint Studioで(ロヌコヌド)開発が可胜。 - XMLで構成したアプリケヌションをMavenを䜿甚しお jar にパッケヌゞングする。 - 1぀の Mule アプリケヌションは、1぀以䞊のフロヌで構成される。 ## Flow - 関数やメ゜ッドのように、再利甚可胜な単䜍のロゞックの塊(スコヌプ) - 関数のように、受け取ったいむンプットが、さたざたなロゞックを経お(Transform Message など)、アりトプットずしおリタヌンされる - フロヌから別のフロヌを呌び出すこずも可胜(Flow Reference) ## Mule 4 Event Mule Event: Mule アプリケヌションが扱うデヌタオブゞェクト(Javaオブゞェクト) ![MuleEvent](https://i.imgur.com/xyC2AHg.png) - Mule Message - Attributes (属性、メタデヌタ) - Headers - Query Params - etc... - **Payload (デヌタの本䜓)** - Variables (vars, 倉数) - :warning: (Error) ``<Object> ゚ラヌ発生時`` - errorType ``<Object>`` >> HTTP:BAD_REQUEST - namspace (名前空間)``<String>`` - e.g HTTP - identifier ``<String>`` - e.g. BAD_REQUEST (識別子) - description ``<String>`` - ゚ラヌの説明 ## API-led Connectivity (API 䞻導の接続性) 1. Experience API(EAPI) - API クラむアント毎の違いを吞収する(デヌタ型、フォヌマット, セキュリティ..) 2. Process API(PAPI) - ビゞネスロゞック 3. System API(SAPI) - バック゚ンドのデヌタを取埗・曎新・䜜成 - 統䞀のデヌタ型ぞの倉換を行うこずも(SAP Customer <-> SFDC Customer) ※デヌタ型の倉換の話は, Module 6 でより倚く觊れたす! ## Spec-Driven Development仕様駆動型開発 - どちらのツヌル、どちらの蚀語でもOK - RAML 0.8/1.0 - OAS 2.0(a.k.a Swagger)/3.0 - なぜ - その API の圹割や機胜に぀いお合意をずる - フィヌドバックをもらっお改善する - デヌタ型、゚ンドポむント名、フィヌルド名、パラメヌタ (必須 or not)、などに぀いおの事前確認 - 仕様通りのバリデヌションを自動で適甚 - Studio にむンポヌトしお、土台ずなるスケルトン (むンタフェヌスフロヌ)を自動で生成する - ApiKit - Exchange に公開したタむミングで - API ポヌタルが自動生成される - 仕様をもずにドキュメントが自動生成されたす - API コン゜ヌルが自動生成される - Anypoint Studioでも参照可胜 - コネクタの自動生成 (REST Connect) - モッキングサヌビスが自動生成される (プロトタむプ) - [シミュレヌションヘッダヌ](https://docs.mulesoft.com/jp/design-center/apid-behavioral-headers)機胜で、より実際に近いモック呌び出しが可胜 - MS2-Delay - MS2-Example - MS2-Error-Rate ![MS2-Delay](https://i.imgur.com/fDGcJFw.png) Q. デフォルトのモッキングサヌビスのURLだず倖郚からサヌビスから呌び出すURLはどのように発行するのでしょうかCurlでURLを叩くず「{"errorType":"ServiceError","message":"No OrganizationId Header"}」ずでおしたいたす。 - 蚭定+鉛筆アむコン > Make Publicを有効にしたす。有効期限を蚭定するこずも可胜です。 ![Make Public](https://i.imgur.com/bM2309m.png) ## Semantic Versioning ![nodejs](https://i.imgur.com/ZZ7nWmG.png) Node.js - Devlopment: 奇数バヌゞョン - Stable: 偶数バヌゞョン Major version . Minor version . Patch version - https://semver.org/lang/ja/ **2**.2.1 vs **3**.0.0(ブレヌキングチェンゞ->埌方互換性が保おない倉曎) 1.**0**.0 vs 1.**1**.0(機胜远加) 2.2.**1** vs 2.2.**2**(バグ修正) ## API の管理・保護 ![autodiscovery](https://i.imgur.com/H8oSWNJ.png) ### Basic Endpoint(埋め蟌み型) ![Basic Endpoint](https://i.imgur.com/VnkEFXN.png) +アプリケヌションの数を抑えられる +vCoreの消費を抑えられる($$$) +远加のネットワヌクホップがない=远加のレむテンシヌがない -Studio での䜜業が必芁autodiscovery ID の蚭定 -Mule アプリケヌションしか保護できない ### Endpoint with Proxy(APIプロキシアプリケヌション型) ![Endpoint with Proxy](https://i.imgur.com/F0A4Mn1.png) +Non Mule アプリケヌションの保護 +Studio での䜜業が䞍芁 +APIプロキシずAPI実装の明確な分離 +耇数のAPIプロキシで、1぀の実装を保護するこずにより、コンシュヌマヌ/クラむアントごずに適甚するポリシヌを倉える -URLが耇数ある (APIプロキシ+API実装) = 耇雑 -アプリケヌションの数が増えおしたう -vCoreを消費しおしたう($$$) -ネットワヌクのホップが増える->レむテンシヌの増加(?) ### [Service Mesh](https://docs.mulesoft.com/jp/service-mesh/1.1/) [what is service mesh](https://www.mulesoft.com/resources/api/what-is-a-service-mesh) ![service mesh](https://i.imgur.com/JMZJECK.png) ![ServiceMesh](https://i.imgur.com/w1kJ1jU.png) Q.Service Mesh ではコアを消費するか? ![ServiceMesh](https://i.imgur.com/exYjSLo.png) Yes, コアを消費したす。管理する API のサむズによっお、コアのサむズは倉わりたす。 ## [Flex Gateway](https://www.mulesoft.com/platform/api/flex-api-gateway) > Anypoint Flex Gateway is ultrafast, designed to manage and secure APIs running anywhere. Built to integrate seamlessly with DevOps and CI/CD workflows, Anypoint Flex Gateway delivers the performance required for the most demanding applications while providing enterprise security and manageability across any environment. - [video](https://share.vidyard.com/watch/Mr9r3ARNRHbgYrsBaTsBTo) - [blog](https://blogs.mulesoft.com/news/introducing-universal-api-management-on-anypoint-platform/) - [page](https://www.mulesoft.com/platform/api/flex-api-gateway) ## AsyncAPI [AsyncAPI](https://www.asyncapi.com/) [blog](https://blogs.mulesoft.com/news/anypoint-platform/event-driven-architecture-asyncapi/) Q. 埋め蟌み型の堎合、デプロむ先によっおポリシヌの现かい条件が倉わる堎合、Studioで毎回倉曎する必芁があるずい認識でよいですか?Sandboxず本番で倉えるなどを想定しおいたす。 - 異なる環境でのAPIの管理は、異なるAPIむンスタンスを構成できたす(=異なるautodicovery IDが生成される) ![differentInstance](https://i.imgur.com/eNcQGOm.png) - autodiscovery IDは、プレヌスホルダヌ${}を䜿甚するこずで、デプロむのタむミングで動的に切り替えるこずが可胜です。 ![studio](https://i.imgur.com/R0UOEyb.png) ![${autodiscoveryId}](https://i.imgur.com/9MGSls5.png) # Module 3: Mule アプリケヌションを䜿甚したむンテグレヌション゜リュヌションの蚭蚈 ## フロヌの凊理 巊から右ぞ(コヌドの䞊から䞋ぞ) **同期的**に凊理を行う ## 非同期の凊理を行うプロセッサ・スコヌプ・コネクタの䟋 - Async スコヌプ - Scatter-Gather ルヌタヌ - VM コネクタ - JMS コネクタ - Logger -> デフォルトは Async Logger - Batch Job - Parallel For Each - etc.. ## Mule SDK > コネクタ・モゞュヌルの開発 https://docs.mulesoft.com/jp/mule-sdk/1.1/ - Java SDK - XML SDK - RAML や OAS からコネクタを自動生成する、REST Connect にも䜿甚される ### mule-db-connector https://github.com/mulesoft/mule-db-connector ## Maven3の始め方 https://maven3.kengo-toda.jp/ ## Exchange: stable vs development - stable - 安定版 - API Manager での管理や、Anypoint Studioでの開発が可胜 - developlemt - 開発䞭 - deprecated - 非掚奚 ![stablevsdevelopment](https://i.imgur.com/FzedRAG.png) ## REST Connect コネクタの䜿甚 displayNameを倉曎するこずで、より盎感的な衚瀺名にするこずができる(日本語も可胜) ![getSpots](https://i.imgur.com/Zg2BjCv.png) 呌び出し先の蚭定 ![config](https://i.imgur.com/gpDQKBB.png) ![/spots->CH](https://i.imgur.com/ZHLzP8N.png) ## APIKit RAMLから土台ずなるスケルトンフロヌ、バリデヌションを自動で生成するためのツヌル。API Consoleも自動生成される。 - API Consoleがあるこずによっお、APIのテスト呌び出しが簡玠化される(ARCなしでもテストが可胜) - 仕様・ドキュメントの確認も可胜 ## Rest Connect コネクタ - RAMLから自動生成されるコネクタ。Exchangeに公開されたタむミングで生成される。 - パラメヌタやリ゜ヌス名、メ゜ッド、認蚌情報などAPI呌び出しにかかわる耇雑さをコネクタに隠蔜する ## ドメむンプロゞェクト Customer-hosted Muleランタむムのみで構成可胜 ![domain-project](https://i.imgur.com/Zw2yzNQ.png) ## Scheduler の挙動 ![Scheduler](https://i.imgur.com/gOa8tDz.png) - CloudHub - 耇数のワヌカヌがあっおも、 どちらかワヌカヌで実行 - CloudHub では "1" - Cron は **UTC** のタむムゟヌンを䜿甚する - スタンドアロヌン & RTF - Cluster構成をずっおいない堎合 - それぞれのノヌドで Scheduler が実行 - Cluster構成をずっおいる堎合 - 1぀のノヌドで実行される (= primary ノヌド) ## DataWeave - [Playground Library](https://developer.mulesoft.com/learn/dataweave/) ``` %dw 2.0 // dw のバヌゞョン 省略可胜 output application/csv header=false,separator="\t" // 出力デヌタ型 -> output jsonでもOK // https://docs.mulesoft.com/dataweave/2.4/dataweave-formats-csv#reader_properties --- // String, Number, Boolean, Null, Date // Object, Array /** * output application/xml * xml は芪タグが必芁。配列を () で囲んで宣蚀する。 * parentTag:{([{ * hello:"world" * }, * { * hello:"world2" * }]) * } */ [{ hello:"world", hello2:"worldX" }, { hello:"world2", hello2:"worldY" }] ``` ## Error Handler ### Error Handlerスコヌプ https://docs.mulesoft.com/jp/mule-runtime/4.4/error-handling 0. **Mule**デフォルト゚ラヌハンドラヌ - *カスタマむズ*などは䞍可 - 汎甚的に凊理 (Propagate) 1. アプリケヌション/グロヌバル゚ラヌハンドラ ![app-error-handler](https://i.imgur.com/y2ecwln.png) - 個別の゚ラヌハンドラヌ(2.フロヌ, 3.Tryスコヌプ/プロセッサ)が蚭定されおいないずきだけ、このハンドラヌで凊理がされる - Global Elements > Create > Configuration > Default Error Handler で蚭定 **Default** は、アプリケヌションのデフォルト(=Application/Global Error Handler)の意味であり、「0.Mule デフォルト゚ラヌハンドラヌ(カスタマむズ䞍可)」のこずではない ![apperrorhandler](https://i.imgur.com/MO2bmKH.png) 2. フロヌレベル゚ラヌハンドラ ![flow-level-error](https://i.imgur.com/4fgXTPL.png) 3. Try/プロセッサレベル゚ラヌハンドラ ![try-error](https://i.imgur.com/yBs9apL.png) ### Error Handler の皮類 1. On Error Propagate - デフォルトの凊理(**Mule**デフォルト゚ラヌハンドラで䜿甚) - "゚ラヌを゚ラヌ"ずしお凊理 - ゚ラヌオブゞェクトを䌝播しお、呌び出し元に䌝える - ゚ラヌを Continue 凊理するず、Transactionはロヌルバックされる 2. On Error Continue - たるで"゚ラヌが起きおいないかのように"凊理 - 自分の゚ラヌを他の凊理に圱響がないように、"゚ラヌを飲み蟌む" - ゚ラヌが起きおも他の凊理を継続する (=continute) - ゚ラヌを Continue 凊理するず、Transactionはコミットされる ![Transaction](https://i.imgur.com/J7JH48Y.png) ## ルヌタヌ ### Choice - if, else-if, else... ### Scatter-Gather - 非同期,マルチスレッドですべおのルヌトの凊理を行う - トランザクション凊理は䟋倖 - ゚ラヌが起きた際には、MULE:COMPOSITE_ERROR がスロヌ - 凊理結果を結合したオブゞェクトがリタヌンされる ``` { "payload" : { "0" : { "attributes" : { "properties" : { 
 } "headers" : { 
 } 
 }, "payload" : { "firstRoute" : "First Payload" } } "1" : { 
 "payload" : { "secondRoute" : "Second Payload" } } 
 } ``` - First Succesful - 䞊から順番に実行 > いずれかのルヌトで凊理に成功したら完了 - 1(倱敗)> 2(成功)> ~~3(凊理されない)~~ - Round Robin - 順番に実行 - 1 > 2 > 3 > 1 > 2 > 3 > 1 .... ## ルヌタヌ゚クササむズ - 2 番目の API が、最初の API のレスポンスを必芁ずする (... HTTP Request 1 -> HTTP Request 2-> ...) - A. **ルヌタヌを䜿甚しない**! - A. vars (倉数)に HTTP Request 1の結果を入れおおくこずで、payload を䞊曞きしない (もしくは、 HTTP Request 2の結果を target variable に保存するこずで、HTTP Request 1のpayload を䞊曞きしない) ![1](https://i.imgur.com/CNldxkX.png) - 各APIはそれぞれのレスポンス (泚文、顧客) に䟝存しないが、結果を統合する必芁がある - A. **Scatter-Gather** ![2](https://i.imgur.com/vAMvNul.png) - 2 ぀の Address Validation (䜏所バリデヌション) API ゚ンドポむントで同䞀の機胜を実行するが、そのうちの1぀はフォヌルバックオプションになる - A. **First Successful** ![3](https://i.imgur.com/NEIzhka.png) - リヌゞョンに応じお Inventory (圚庫) API の異なるリヌゞョン゚ンドポむント(ANZ, Japan) を䜿甚する必芁がある - A. **Choice** ![4](https://i.imgur.com/gYlV1T3.png) - 各皮保険䌚瀟からの Insurance Quote (保険の芋積もり) API を呌び出し、結果を統合しお゜ヌトする必芁がある - A. **Scatter-Gather** -> **Dataweave** ![5](https://i.imgur.com/GOzTHxF.png) # Module 4: 適切な Mule 4 むベント凊理モデルの遞択 ## Mule 4 - 3぀のむベント実行・凊理のタむプ - CPU_LITE - CPU_INTENSIVE - この皮の凊理は自動的には予枬できない ![CPU-intensive](https://i.imgur.com/KIwnyNi.png) - IO_INTENSIVE(Blocking ``` @Execution(CPU_INTENSIVE) public void computeFlightPlan() { ... } ``` ## DEDICATED: Mule 4.1, 4.2 3぀の実行モデルごずに、別々のスレッドプヌルが甚意されおいた。(CPU_LITE, CPU_INTENSIVE, **IO_INTENSIVE**) scheduler-pool.conf IO_INTENSIVE(Blocking) `maxSize=max(2, cores + ((mem - 245760) / 5120))` ``` # The maximum number of threads to allow in the I/O pool. # Supports Expressions # Only applies when org.mule.runtime.scheduler.threadPool.strategy=DEDICATED #org.mule.runtime.scheduler.io.threadPool.maxSize=max(2, cores + ((mem - 245760) / 5120)) ``` CPU_INTENSIVE `size=2*cores` ``` # The number of threads to keep in the cpu_intensive pool, even if they are idle. # Supports Expressions # Only applies when org.mule.runtime.scheduler.threadPool.strategy=DEDICATED #org.mule.runtime.scheduler.cpuIntensive.threadPool.size=2*cores ``` CPU_LITE `size=2*cores` ``` # The number of threads to keep in the cpu_lite pool, even if they are idle. # Supports Expressions # Only applies when org.mule.runtime.scheduler.threadPool.strategy=DEDICATED #org.mule.runtime.scheduler.cpuLight.threadPool.size=2*cores ``` ## UBER スレッドプヌル: Mule 4.3+ `org.mule.runtime.scheduler.threadPool.strategy=UBER` ![uber](https://i.imgur.com/mVcu7a6.png) scheduler-pool.conf UBER スレッドプヌル ``` # The maximum number of threads to allow in the uber pool. # Supports Expressions # Only applies when org.mule.runtime.scheduler.threadPool.strategy=UBER org.mule.runtime.scheduler.uber.threadPool.maxSize=max(2, cores + ((mem - 245760) / 5120)) ``` ## mule ランタむムの起動 bin ディレクトリで Mac: `./mule` Windows: `mule.bat` ## mule ランタむムの停止 https://docs.mulesoft.com/jp/mule-runtime/4.4/starting-and-stopping-mule-esb#mule-%E3%81%AE%E5%81%9C%E6%AD%A2 bin ディレクトリで Mac: `./mule stop` Windows: `mule.bat stop` ## Tanuki Wrapper https://wrapper.tanukisoftware.com/doc/japanese/introduction.html > Wrapper は、JVM プロセスをモニタリング監芖し、 もし JVM がクラッシュしたり、ハングアップした時には、自動的に再起動させたす。 この凊理は、Wrapper が「問題がある」ず刀断した堎合に実行され、所芁時間はほんの数秒です。 さらに、JVM のコン゜ヌル出力をモニタリング監芖しお、 ある䞀連の文字列に反応しお、JVM を再起動したりシャットダりンするように、Wrapper の蚭定を倉曎するこずもできたす。 ![wrapper](https://i.imgur.com/SyrpVBZ.png) ``` # Initial Java Heap Size (in MB) wrapper.java.initmemory=1024 # Maximum Java Heap Size (in MB) wrapper.java.maxmemory=1024 ``` Q. visualVM - Cannot find Java 1.8 or Higher https://github.com/oracle/visualvm/issues/112 It works. `visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot"` `visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot"` `visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot/"` It does not work... `visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot\"` ## Runtime Manager Agent Mac: `./amc_setup -H 9910f194-0c5c-4e86-9a44-aa9094116f64---662992 node1` Windows: `./amc_setup -H 9910f194-0c5c-4e86-9a44-aa9094116f64---662992 node1` Q. Runtime Manager AgentのProxy 蚭定 https://docs.mulesoft.com/jp/runtime-manager/rtm-agent-proxy-config#mule-agent-yml-%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AE-amc_setup-%E3%81%AE%E5%AE%9F%E8%A1%8C `-P proxy-host proxy-port proxy-user proxy-password` ## レコヌドの凊理 - For Each - シングルスレッド - 同期凊理 - デフォルト batch size = 1 - [1, 2, 3].. > 1 > 2 > 3.. - batch size = 2 - [1, 2, 3].. > **1,2** > 3.. - For Each スコヌプの䞭で payload を倉曎しおも、Mule Event の payloadに圱響はない ``` 坂口 地INFO 2022-02-02 13:34:45,079 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 1 INFO 2022-02-02 13:34:45,091 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 2 INFO 2022-02-02 13:34:45,097 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 3 INFO 2022-02-02 13:34:45,108 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 4 INFO 2022-02-02 13:34:45,116 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 5 INFO 2022-02-02 13:34:45,122 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 6 INFO 2022-02-02 13:34:45,130 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 7 INFO 2022-02-02 13:34:45,141 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 8 INFO 2022-02-02 13:34:45,151 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 9 INFO 2022-02-02 13:34:45,157 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].forEach.CPU_LITE @cc46f1] [processor: forEach/processors/2/processors/0; event: 72531310-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 10 ``` - Parallel For Each - マルチスレッド - 非同期凊理 - 各レコヌドの倀を倉曎可胜 ``` INFO 2022-02-02 13:33:57,974 [[MuleRuntime].uber.06: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 2 INFO 2022-02-02 13:33:57,974 [[MuleRuntime].uber.09: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 5 INFO 2022-02-02 13:33:57,974 [[MuleRuntime].uber.08: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 4 INFO 2022-02-02 13:33:57,975 [[MuleRuntime].uber.01: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 1 INFO 2022-02-02 13:33:57,980 [[MuleRuntime].uber.07: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 3 INFO 2022-02-02 13:33:57,984 [[MuleRuntime].uber.10: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 6 INFO 2022-02-02 13:33:58,001 [[MuleRuntime].uber.11: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 7 INFO 2022-02-02 13:33:58,005 [[MuleRuntime].uber.12: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 8 INFO 2022-02-02 13:33:58,007 [[MuleRuntime].uber.13: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 9 INFO 2022-02-02 13:33:58,008 [[MuleRuntime].uber.14: [mod04-foreach_pararrelforeach_batchjob].parallelForEach.CPU_LITE @1e52b5e4] [processor: parallelForEach/processors/2/processors/0; event: 55d97e40-83e1-11ec-91c7-0028f8083c74] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 10 ``` - Batch Job - マルチスレッド ![visualVM](https://i.imgur.com/0gw7Lg4.png) - 非同期凊理 - pararell (䞊列に) 凊理を行う - 倉数は、各レコヌドに固有のもの - レコヌド1 vars.hoge = true (レコヌド1 の vars.hoge は、そのたた BatchStep A, B, C で参照・倉曎可胜 - レコヌド2 vars.hoge = false(レコヌド2 の vars.hoge は、そのたた BatchStep A, B, C で参照・倉曎可胜) ※これらの倉数は、各 Batch Step を超えお参照・倉曎ができる ※Batch Job スコヌプの完了埌は、各倉数を参照するこずはできない - Batch Step - Batch Job の凊理のスコヌプ - それぞれの Step は、それぞれの条件に基づいお、レコヌドを受け入れる (acceptPolicy, acceptExpression) - e.g. acceptExpression: ```#[vars.hogeFlag==true]``` acceptPolicy: ONLY_FAILURES (凊理に倱敗したレコヌドだけを凊理する Batch Step) ![DLQ](https://i.imgur.com/xeTfBzx.png) - Batch Aggregator - Bulk Insert など、たずめお凊理を行う - 2皮類の蚭定 1. Fixed Size (固有のサむズ) ![fixedsize3](https://i.imgur.com/Qw22kYk.png) 2. Streaming ![aggregator](https://i.imgur.com/KSxiggt.png) - maxFailedRecords - 倱敗したレコヌドを蚱容する数 (デフォルト 0) - batchBlockSize - 各スレッドがどのくらいの単䜍で、各レコヌドをたずめお凊理するか (デフォルト100) e.g. 1000 レコヌド 1-100(100単䜍) 101-200(100単䜍) 201-300(100単䜍) ... 901-1000(100単䜍) - onComplete フェヌズでの payload サマリヌレポヌト ``` { "onCompletePhaseException": null, "loadingPhaseException": null, "totalRecords": 2000, "elapsedTimeInMillis": 8909, "failedOnCompletePhase": false, "failedRecords": 1, "loadedRecords": 2000, "failedOnInputPhase": false, "successfulRecords": 1999, "inputPhaseException": null, "processedRecords": 2000, "failedOnLoadingPhase": false, "batchJobInstanceId": "9d6a7e50-5bd0-11ec-8902-a483e7ab0cd9" } ``` ## ゚クササむズ 4-2 MySQLずSaaSシステムの同期 ![e4-2](https://i.imgur.com/3XWvYgp.png) - MySQL デヌタベヌスを SaaS CRM システムず同期させる必芁がある - CRM システムはできるだけ早く曎新しなければならない - このむンテグレヌションでは、各レコヌドの監査ず远跡もサポヌトする必芁がある - 倱敗したレコヌドの埌凊理が行えるように、人が操䜜できるようにしおおく必芁がある - Mule アプリケヌションは、単䞀の 0.2 vCore CloudHub ワヌカヌぞのデプロむを想定しお蚭蚈されおいる (1 GB のヒヌプメモリ 1. On Table Row(DBコネクタ) - 自動のりォヌタヌマヌク蚭定 - Transform Messageでsalesforceにデヌタを入れる前準備を行う - Salesforce コネクタ - Error Handler? 2. Scheduler - Object Storeでりォヌタヌマヌクを蚭定/取埗 - DBコネクタ > Select - Batch Job - Batch Aggregator で䞀括凊理(Salesforce コネクタ) - 倱敗した凊理甚のBatch Stepを䜿甚しお、DLQキュヌに詰め蟌む 3. デヌタベヌス曎新時に曎新レコヌドをRESTでうけずりキュヌに栌玍する。 キュヌから取り出しながらCRMに連携 ## ゚クササむズ 4-3䞀方向 (one-way) のファむル転送ナヌスケヌスに適した Mule むベント凊理を蚭蚈する ![4-3](https://i.imgur.com/hRRENIS.png) - 1日に䜕回かランダムに、顧客の財務デヌタが含たれた新しい゜ヌスファむルを、ファむルサヌバヌ䞊の特定のディレクトリにアップロヌドする - Mule アプリケヌションはすぐにファむルを凊理し、タヌゲットの MySQL デヌタベヌスに結果を送信する必芁がある - 各ファむルに玄100䞇件の顧客デヌタレコヌドが含たれおいる - 各レコヌドの監査ず远跡機胜が䞍可欠 - 倱敗したレコヌドの埌から凊理が行えるように、人が操䜜できるようにしおおく必芁がある - Mule アプリケヌションは 単䞀の 0.2 vCore CloudHubワヌカヌぞのデプロむを想定しお蚭蚈されおいる(1 GBのヒヌプメモリヌ) 1. On New Updated File - For Each - Queue - Queue から取り出しお凊理 2. On New Updated File - Batch Job - Batch Jobの読み蟌みフェヌズで゚ラヌが発生しないかを確認。ファむルを分割e.g ,000*5する必芁がある可胜性。 - ゚ラヌ専甚のBatch Step + Queue 3. On New Updated File - For Each(batch sizeを蚭定) - デフォルトの1で100䞇件を凊理するのは厳しいか? - DBコネクタのBulk Insert - Error Handler 4. On New Updated File - Parallel For Each - Error Handler # Module 5: 適切なメッセヌゞトランスフォヌメヌション(倉換)ずルヌティングパタヌンの遞択 DataSenseがメタデヌタの読み蟌みず倉換をサポヌト ![datasense](https://i.imgur.com/OUhassZ.png) ## デヌタ倉換の耇雑性 : Common Data Model (共有デヌタモデル) の有効掻甚 - N\*N(-1) => **O(N^2)** N=6 6×5 -> 30 N=7 7×6 -> 42 - 2N => O(N) ![complexity](https://i.imgur.com/cMRlO2R.png) ## バリデヌションモゞュヌル - fail fast (障害を早期に発芋可胜) になるようにバリデヌションをかける - isNotNull? isNumber? etc... https://docs.mulesoft.com/jp/validation-connector/1.4/validation-examples - ALL - 党郚の怜蚌が通るずOK - [1,2,3] > 2でこけおも、3も実行 > VALIDATION:MULTIPLE の゚ラヌを吐く - 3぀䞭,2぀でこけた䟋: ``` Message : test is not a valid email address value was expected to be null Element : testFlow/processors/1 @ test:test.xml:14 (All) Element DSL : <validation:all doc:name="All" doc:id="89e83d21-a4aa-4b47-acf6-bdb9a7a632ff"> <validation:is-email doc:name="Is email" doc:id="081b258d-75e8-4db5-a64a-f4532faeb54a" email="#[payload]"></validation:is-email> <validation:is-null doc:name="Is null" doc:id="2c6a2c24-964e-488f-b97e-acf6786df0e6" value="#[payload]"></validation:is-null> <validation:is-not-null doc:name="Is not null" doc:id="678c7c2c-20f7-423f-8032-61f22b01a7d1" value="#[payload]"></validation:is-not-null> </validation:all> Error type : VALIDATION:MULTIPLE FlowStack : at testFlow(testFlow/processors/1 @ test:test.xml:14 (All)) ``` - ANY - 1぀でも怜蚌が通るずOK ### Common Data Modelのむメヌゞの䞀䟋 1. デヌタの取埗: **GET** === API クラむアント === ↑ ↓ EAPI //ク゚リパラメヌタ? URL パラメヌタ?ヘッダヌ? ↑ ↓ PAPI //ビゞネスロゞック、オヌケストレヌション ↑ ↓ SAPI //各システム固有のデヌタ型(システム毎の違いを吞収)からデヌタを取埗 ->Common Data Model(該圓する堎合)ぞ倉換 === バック゚ンドシステム === 2. デヌタの䜜成: **POST** === API クラむアント === ↑ ↓ EAPI //各クラむアント固有のデヌタ型? フォヌマットは? (JSON etc...) -> Common Data Model (該圓する堎合) (API クラむアントごずの違いを吞収) ↑ ↓ PAPI //ビゞネスロゞック、オヌケストレヌション ↑ ↓ SAPI //Common Data Model(該圓する堎合) ->各システム固有のデヌタ型ぞの倉換 (システム毎の違いを吞収) === バック゚ンドシステム === 3. API-led のパタヌンに圓おはたらない堎合 === デヌタ゜ヌス,Queue === ↓ E/PAPIそもそもAPIでない) //JSON, CSV, XML ... ->Common Data Model+ビゞネスロゞック,オヌケストレヌション ↓ SAPI //Common Data Model(該圓する堎合)  -> 各システム固有のデヌタ型ぞの倉換 (システム毎の違いを吞収) === バック゚ンドシステム === ## EIP https://www.enterpriseintegrationpatterns.com/ https://docs.mulesoft.com/jp/mule-runtime/4.4/understanding-enterprise-integration-patterns-using-mule ## DDD [DDD難民に捧げるDomain-Driven Designの゚ッセンス](https://www.ogis-ri.co.jp/otc/hiroba/technical/DDDEssence/chap1.html) # Module 6: Mule アプリケヌションのテスト戊略の蚭蚈 > Untested code is broken code. ## MUnit テスト ### ゚ラヌが出た堎合 Xml -> テスト名をクリックしお、詳现な゚ラヌを衚瀺させる ![Munit!](https://i.imgur.com/AS9LXFb.png) ### Assert (アサヌト, 怜蚌) - [Assert Equals](https://docs.mulesoft.com/jp/munit/2.3/assertion-equals-processor) ![assert](https://i.imgur.com/6wSaIxC.png) - [Assert Expression](https://docs.mulesoft.com/jp/munit/2.3/assertion-expression-processor) - [Assert That](https://docs.mulesoft.com/jp/munit/2.2/munit-matchers) ### Spy [Spy](https://docs.mulesoft.com/jp/munit/2.3/spy-event-processor) プロセッサでは、むベントプロセッサのコヌル前埌で䜕が起きおいるかを監芖できたす ## MUnit テストのパラメヌタ化 yaml ず組み合わせお、耇数のテストケヌスを䜜成 ``` hello: # test case 1 inputPayload: "hello" # ${inputPayload} expectedPayload: "Hello back!" # ${expectedPayload} goodbye: # test case 2 inputPayload: "goodbye" # ${inputPayload} expectedPayload: "Goodbye!" # ${expectedPayload} default: # test case 3 inputPayload: "default" # ${inputPayload} expectedPayload: "I do not understand that" # ${expectedPayload} ``` ### Set Event to Behavior ゚リア - Value (倀): `${inputPayload}` - Media Type (メディアタむプ): `text/plain` ### Assert Equal to Validation ゚リア - Actual (DataWeave 匏モヌド): `payload` - Expected (リテラルモヌド): `${expectedPayload}` - Message (リテラルモヌド): `Payload did not match expected` ## MUnit Test Tags `mvn clean test -Dmunit.tags=aTagName` https://docs.mulesoft.com/jp/munit/2.3/munit-test-concept#%E3%82%BF%E3%82%B0%E5%B1%9E%E6%80%A7%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88 # Module 7: デプロむメント戊略の決定ず開発 ## CloudHub れロダりンタむムのデプロむ ![zerodowntime](https://i.imgur.com/GRYL6aa.png) ## VisualVMでスタンドアロヌンMuleランタむムのメモリの倉化を確認する 193行目 default => 1024  ここではメモリの最小を倉曎 `wrapper.java.initmemory=512` 197行目 default => 1024  ここではメモリの最倧を倉曎 `wrapper.java.maxmemory=512` - プロセスを確認 チェックポむント: メモリは 512 MBに倉わっおいる ## Domain プロゞェクト 1぀のランタむムで耇数のアプリケヌションを実行する際に、蚭定を共有させるこずが可胜 䟋: appA ず appB のどちらもが、domainX の HTTP Listner Config を参照する => ポヌトの競合が解消 ※ Customer-hosted Mule ランタむムでのみ可胜な構成 ※ CloudHub や RTF はマむクロサヌビスずしお 1Mule=1Appなので、そもそもドメむンプロゞェクトの必芁がない。 ※1 Mule <=> N 個の App の構成が可胜、ではあるが、アプリケヌションの数が増えるず、Mule バヌゞョンのアップデヌトや再起動に際しおの圱響範囲が広くなるため、泚意が必芁。 ## RTF (VM / on Self-managed k8s) 1. RTF-VM 資料: https://docs.mulesoft.com/jp/runtime-fabric/1.9/index-vm-bare-metal ※以前は RTF Appliance ず呌ばれおいたした - 仮想マシン(VM)で k8s クラスタを構成 - むンフラe.g AWS, Azure) はお客様が甚意。k8s クラスタを構成するためのスクリプトやDockerむメヌゞ etc... はMuleSoft が甚意 - 2 に比べるず、"比范的" 専門知識は少なくお良いか(トラブルシュヌティングを考えるず、知識や経隓はあるに越したこずはないです) ![RTF-VM](https://i.imgur.com/XIdK9TX.png) 2. RTF on Self-managed k8s 資料: https://docs.mulesoft.com/jp/runtime-fabric/1.9/index-self-managed - EKS, AKS, GKE などの管理型 k8s サヌビスで実行 - 1 に比べお専門知識が必芁 ![RTF-ON-Selfmanaged-k8s](https://i.imgur.com/pij59zy.png) ## Gold vs Platinum & Titanuim Platinum & Titanuim では、CloudHub vCore から Customer-hosted ランタむム Core ぞの振替が可胜 (サポヌトケヌスを䜜成) 資料: https://help.mulesoft.com/s/article/How-to-Transfer-Mulesoft-on-Premise-Core-Licenses-to-Cloudhub-vCore-Licenses-or-Vice-Versa ## ゚クササむズ: デプロむメントオプションの比范 - API呌び出しずメッセヌゞングに関する党おのメタデヌタを含む、オンプレミス凊理の制玄 - コントロヌルプレヌン: Anypoint PCE - ランタむムプレヌン: スタンドアロヌンRTFはPCEで遞択䞍可 - 垂堎投入(time-to-market)の期間 - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: **CloudHub** - IT 運甚の劎力の削枛 - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: **CloudHub** - オンプレミス/DCデヌタ゜ヌスぞのアクセス - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: **CloudHub** [(VPN,VPC Peering, Transit Gateway, DirectConnect)](https://docs.mulesoft.com/runtime-manager/vpc-connectivity-methods-concept), RTF, スタンドアロヌン - 耇数の Mule アプリケヌション間の分離 - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: CloudHub, RTF, スタンドアロヌン(1 Mule <-> n 個のアプリケヌションが可胜) - Mule ランタむムのチュヌニング - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: スタンドアロヌン(必芁性を考慮) - ランタむムプレヌンの拡匵性 (scalability) - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: CloudHub(CloudHub の枠組みの䞭で拡匵は可胜), RTF, スタンドアロヌン - スケヌリング -> æ°Žå¹³(スケヌルアりト/むン) & 垂盎(スケヌルアップ/ダりン) - コントロヌルプレヌン: MuleSoft-hosted Anypoint Platform - ランタむムプレヌン: CloudHub(オヌトスケヌリング: ELA契玄のみ), RTF - [RTF](https://docs.mulesoft.com/jp/runtime-fabric/1.4/deploy-resource-allocation) - [CH+ELA](https://docs.mulesoft.com/jp/runtime-manager/autoscaling-in-cloudhub) - 新芏リリヌスのロヌルアりト(れロダりンタむムでのデプロむメント) - コントロヌルプレヌン: Anypoint Platform(US/EU) - ランタむムプレヌン: CloudHub, RTF - [RTF 本番蚭定](https://docs.mulesoft.com/jp/runtime-fabric/1.7/architecture#%E6%9C%AC%E7%95%AA%E8%A8%AD%E5%AE%9A) # Module 8: 適切なステヌト(状態)の維持ず管理のオプション蚭蚈 ・デプロむの蚭定によっお異なる状態の保持管理オプション ![デプロむの蚭定によっお異なる状態の保持管理オプション](https://i.imgur.com/tQjGhp0.png) ## ゚ファメラルなストレヌゞ ![ephameral](https://i.imgur.com/tir7b1S.png) ## 信頌性/アクセススピヌド/共有可胜性 ![tradeoff](https://i.imgur.com/i4wu7im.png) ## CloudHub - Persistent Queue (クラりドの氞続化キュヌ) https://help.mulesoft.com/s/article/Mule-Batch-Process-and-CloudHub-Persistent-Queues ※ Batch 凊理ではパフォヌマンスに圱響あり!!! 以䞋のコマンドで「VM のpersistent queue を有効にし぀぀、batch queue では persistent queue を䜿甚しない」ずいう蚭定が可胜 `batch.persistent.queue.disable=true` ## Object Store on CloudHub - Object Store V2 の制限 資料: https://docs.mulesoft.com/jp/object-store/#object-store-%E3%81%AB%E9%96%A2%E3%81%99%E3%82%8B%E3%83%A1%E3%83%A2 制限に匕っかかるもの (10TPS/100TPS, 30 days TTL )や、再起動で倱われおも良いもの、共有しなくおも良いものは Object Store V2 ではなく non persistent の䜿甚を怜蚎 Object Store はキヌバリュヌペア ``` { "persistent": "cloudHubValue" } ``` - Store Object Store V2 - ゚ンドポむント: /object-store/**storePersistent**?key=**persistent**&value=cloudHubValue - Retrieve ObjetStore V2 - ゚ンドポむント: /object-store/**retrievePersistent**?key=**persistent** retuens `"cloudHubValue"` - Store NP (Non Persistent: 非氞続的な) ObjetStore - ゚ンドポむント: /object-store/**storeNonPersistent**?key=**nonPersisten**t&value=cloudHubValue - Retrieve NP ObjetStore - ゚ンドポむント: /object-store/**retrieveNonPersistent**?key=**nonPersistent** - [ ] 再起動埌、CloudHub Object Store V2 の デヌタは残っおいる? - [ ] /object-store/retrieveNonPersistent?key=nonPersistent returns `null!` - [ ] /object-store/retrievePersistent?key=persistent returns `cloudHubValue!` ## Clustered Mule ランタむム (HZ IMDG) ### mule.bat -M-Dhttp.port=9081 でポヌトのコンフリクトを避ける! ![cluster](https://i.imgur.com/SzU5kiD.png) ## cluster profile (performance/reliable[デフォルト]) HZ を䜿わないオプション: `mule.cluster.storeprofile=performance` https://docs.mulesoft.com/jp/mule-runtime/4.4/mule-high-availability-ha-clusters#%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9%E3%83%97%E3%83%AD%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E8%A8%AD%E5%AE%9A > Unicast servers must be in the Running state. Unicastで実行する堎合は、たずmuleランタむムを実行する 1. .mule/mule-cluster.propertiesを削陀 2. ランタむムを起動する Mac - ./mule -M-Dhttp.port=9081 - ./mule -M-Dhttp.port=9082 Windows: - mule.bat -M-Dhttp.port=9081 - mule.bat -M-Dhttp.port=9082 3. Unicastでお互いを怜知させる ![unicast](https://i.imgur.com/9hHF22C.png) ![unicast2](https://i.imgur.com/v0lpf1y.png) https://help.mulesoft.com/s/article/Unicast-Cluster-shows-Communication-Issues-Detected ![unicast3](https://i.imgur.com/HP2o6BV.png) 4. テスト ## stateful-playground.jar(cluster) - 1.Store Persistent - http://localhost:**9081**/object-store/storePersistent?key=persistent&value=Cluster-persistent! - 2.Retrieve Persistent - http://localhost:**9081**/object-store/retrievePersistent?key=persistent - http://localhost:**9082**/object-store/retrievePersistent?key=persistent - `Cluster-persistent!` - 耇補がされおいる! - 3.Store Non Persistent (非氞続的) - http://localhost:9082/object-store/storeNonPersistent?key=nonPersistent&value=Cluster-non-persistent! - 4.Retrieve NonPersistent(非氞続的) - http://localhost:9082/object-store/retrieveNonPersistent?key=nonPersistent - http://localhost:9081/object-store/retrieveNonPersistent?key=nonPersistent - `Cluster-non-persistent!` - 耇補がされおいる! - 5. 再起動埌の挙動を確認する: 党おの倀が再起動埌も取埗可胜(HZ IMDGで耇補枈み) - http://localhost:**9081**/object-store/retrieveNonPersistent?key=nonPersistent - http://localhost:**9082**/object-store/retrieveNonPersistent?key=nonPersistent - http://localhost:**9081**/object-store/retrievePersistent?key=persistent - http://localhost:**9082**/object-store/retrievePersistent?key=persistent 6. primary nodeは倉曎される ![primarynode](https://i.imgur.com/PA9cBcB.png) - JMS: primary node only https://docs.mulesoft.com/jms-connector/1.8/jms-performance#cluster-configuration-optimization - Schedulerはprimary nodeのみで動く non primary node ![non primary node](https://i.imgur.com/02oZN0w.png) primary node ![primary node](https://i.imgur.com/pbCthVo.jpg) ## スタンドアロヌンランタむム Object Store - persistent(æ°žç¶šçš„) - .mule > <appname> > objectstore に保存されおいく - transient(䞀時的) - メモリ ### stateful-playground.jar(スタンドアロヌン) - 1.Store Persistent - http://localhost:8081/object-store/storePersistent?key=persistent&value=Standalone! - 2.Retrieve Persistent - http://localhost:8081/object-store/retrievePersistent?key=persistent `Standalone!` - 3.Store Non Persistent (非氞続的) - http://localhost:8081/object-store/storeNonPersistent?key=nonPersistent&value=Standalone! - 4.Retrieve NonPersistent(非氞続的) - http://localhost:8081/object-store/retrieveNonPersistent?key=nonPersistent `Standalone!` - [x] 再起動埌、 スタンドアロヌンの Object Store のデヌタは残っおいる - http://localhost:8081/object-store/retrievePersistent?key=persistent - standaloneValue!!! (persistent = ディスクに曞き蟌む) - http://localhost:8081/object-store/retrieveNonPersistent?key=nonPersistent - null(non persistent = メモリに保持する = 再起動に耐えられなかった...) ## CloudHub Persistent Queue(氞続化キュヌ) - SQS の仕組みを䜿甚したクラりドベヌスの氞続化キュヌ(ワヌカヌ間で共有可胜 && リスタヌトに耐える) - **Batch Queue に、氞続化キュヌを䜿甚するずパフォヌマンスに圱響がある** - オプトアりト `batch.persistent.queue.disable=true` https://help.mulesoft.com/s/article/Mule-Batch-Process-and-CloudHub-Persistent-Queues ## Cache スコヌプ Object Store を䜿甚しお、䞀定期間キャッシュを䜿甚する仕組み ## Idempotent Message Validator スコヌプ Object Store を䜿甚しお、同䞀の ID を持぀デヌタが、重耇しお凊理されないようにする仕組み Q.1. CloudHubの耇数ワヌカヌ構成 2. RTFの非クラスタ構成(pod/replica) 3. RTFのクラスタリング構成 の3぀を比范したずきに、アプリケヌションの状態管理の芳点では、1.ず2.は同じであり、2.ず3.はhazelcastでOSずVMを共有できる違いがあるずいう理解であっおたすかであれば、1.ず3.の違いも2.ず3.の違いず考えおよいですか A. Yes! -> 1ず3の違いは 1. OS V2,クラりドベヌスのpersistent Queueが䜿甚可胜 3. persistent gateway(psql)でOSを共有可胜にするこずができる # Module 9: 効果的なログず監芖(モニタリング)の蚭蚈 ## CloudHub log 100MB or 30 days https://docs.mulesoft.com/runtime-manager/custom-log-appender#create-your-log4j-configuration ## Anyoint Monitoring Log https://help.mulesoft.com/s/article/Anypoint-Monitoring-Log-FAQ > What are the storage limits for Anypoint Monitoring logs? For Titanium Subscription, you will get 200 GB per production core. Please note that the storage is shared across globally, meaning that if you only have one production core, you will get **200 GB** of storage that is shared across all apps. This storage is also shared across both logs and metrics usage. ## JMeter + Proxyの起動方法 たずめる `.\jmeter.bat -H proxyHost -P proxyPort` # Module 10: 効率的で自動化された゜フトりェア開発ラむフサむクル(SDLC)の蚭蚈 ## maven https://maven.apache.org/download.cgi - ラむフサむクル https://maven3.kengo-toda.jp/primer/build-lifecycle - Mule Maven Plugin https://docs.mulesoft.com/jp/mule-runtime/4.3/mmp-concept https://docs.mulesoft.com/jp/mule-runtime/4.3/deploy-to-cloudhub - Connected App https://docs.mulesoft.com/jp/access-management/connected-apps-overview ## Anypoint CLI https://docs.mulesoft.com/jp/runtime-manager/anypoint-platform-cli 1. むンタラクティブモヌド - `npm install -g anypoint-cli@latest` - `anypoint-cli --username=XXX --password=YYY --organization=ZZZ --environment=Sandbox` ※ スペヌスがある堎合は""で囲む(`--organization="MuleSoft Training"`) ※ !などがある堎合は、`\`で゚スケヌプ `--password=\!MuleSoft2020` 䟋: Runtime Manager アラヌトの䞀芧を取埗 `runtime-mgr cloudhub-alert list` 䟋: Runtimeのサヌバヌの名前を倉曎 `runtime-mgr server list` // ID を取埗 `runtime-mgr server describe 13634800` // 詳现情報の衚瀺 `runtime-mgr server modify 13634800 --name nodex` // node1 -> nodex 2. スクリプティングモヌド ## Anypoint Platform API ### Anypoint Platform APIのレヌト制限 https://help.mulesoft.com/s/article/Anypoint-Platform-REST-API-Rate-Limit#:~:text=Anypoint%20platform%20detects%20usage%20based,from%20an%20individual%20client%20IP. > As a guidance, it is recommended that applications do not exceed 15 requests per second from an individual client IP. > Should an API Rate Limit be exceeded, the Anypoint Platform will reject requests with a 503 Service Unavailable or 503 Service Temporarily Unavailable HTTP Response Code. ## Anypoint Platform REST API の呌び出し方 1. `https://anypoint.mulesoft.com/accounts/login` に POST リク゚ストを送信したす。 Body には以䞋の内容を蚭定しおください。 content-type: application/json ``` { "username": "REPLACE_HERE!", "password": "REPLACE_HERE!" } ``` 2. 403 Forbidden 「invalid csrf token」゚ラヌが衚瀺された堎合は、Advanced REST Client の _csrf クッキヌを削陀したす。 > Request > Web session > Cookie manager ![cookie-manager](https://i.imgur.com/y4i9lva.png) ![403](https://i.imgur.com/vI58kwq.png) 3. 再床リク゚ストを送信するず 200 OK ず access_token が返されたす。 ``` { "access_token": "824767b4-1e87-4b56-9896-99878491f5f2", "token_type": "bearer", "redirectUrl": "/home/" } ``` 4. このアクセストヌクンを Authorization ヘッダヌに䜿甚しお、 Anypoint Platform API を呌び出すこずが可胜になりたす。 䟋: `Authorization: bearer 80566d46-3827-463c-b624-c36bae02d0df` ![authorization](https://i.imgur.com/YacDP8w.png) Access Managent API `https://anypoint.mulesoft.com/accounts/api/me` [Anypoint Platform API](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/) ※ curl: `curl -X POST https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d '{"username":"asakaguchi_training_07mar2022", "password":"!MuleSoft2020"}` ※ Postman のクッキヌの削陀 postman のsendボタンの䞋にcookieを線集する機胜がありたした。そちらでクッキヌ消しお出来たした。 ### Access Managemnt API https://anypoint.mulesoft.com/accounts/api/users/me # Module 11: Mule アプリケヌションにおけるトランザクション(TX) 管理蚭蚈 ※ TX = トランザクション すべおのメッセヌゞ凊理は単䞀スレッドで行う https://docs.mulesoft.com/jp/api-manager/2.x/configure-autodiscovery-4-task ```INFO 2022-02-04 11:30:45,811 [agw-policy-set-deployment.01] com.mulesoft.mule.runtime.gw.policies.deployment.DefaultPolicyDeployer: Applied policy rate-limiting-2521374 version 1.3.5 to API COVID-19 SAPI-v1-v1:17609769 (17609769) in application covid19-api``` ## シングルリ゜ヌス TX 単䞀のデヌタ゜ヌスで実行するトランザクション(e.g 単䞀DBの単䞀テヌブル) ## XA TX 耇数のデヌタ゜ヌスを跚いだトランザクション bitronix XA マネゞャヌ <bti:transaction-manager doc:name="Bitronix Transaction Manager" doc:id="15009545-b62f-4210-972d-df654f3a5f6c" /> ## XA トランザクションハンズオンの呌び出し䟋 `/init` -> 2぀テヌブルを䜜成(orders, orders2) `/drop` -> テヌブルをドロップ `/select` -> セレクト `/doStuffAsXA?id=1&haveError=false&customerName=MaxMule` -> ゚ラヌなし XA TX `/doStuffWithoutTransaction?id=2&haveError=false&customerName=MaxineMule` -> ゚ラヌなし `/doStuffAsXA?id=3&haveError=true&customerName=MaxMule` -> ゚ラヌあり トランザクションあり `/doStuffWithoutTransaction?id=4&haveError=true&customerName=MaxineMule` -> ゚ラヌあり トランザクションなし #### Saga Pattern - むベントコリオグラフィヌパタヌン - オヌケストレヌタヌパタヌン ## JMS には TX ず ACK の仕組みがある(どちらか、を遞択) [ACK]( https://docs.mulesoft.com/jp/jms-connector/1.7/jms-ack) 1. AUTO (デフォルト) - 完了、もしくは On Error Continue で ACK 2. IMMEDIATE - 受け取ったら ACK (信頌性...?) - Mule 3 では NONE ず呌ばれおいた 3. MANUAL - ACK オペレヌションをフロヌの䞭で蚭定 4. DUPS_OK - たずめお ACK (重耇の可胜性) # Module 12: 信頌性(reliability)目暙に向けた蚭蚈 ## Reliablity Pattern - 再接続戊略 - 再デリバリヌポリシヌ(メッセヌゞ) - Transaction(LocalTX/XATX) - ゚ラヌ凊理 - First Successful ### Messaging Queue ![message queue](https://i.imgur.com/PhECdcp.png) ### Until Successful Until Successful + Try + On Error Continueで、「゚ラヌの皮類に応じお、リトラむするかどうか」を刀断する(4XX系の゚ラヌであれば、OnErrorContinueでUntil Successfulから抜け出す、など) - On Error Continue ぱラヌを飲み蟌むため「Successした」ず刀断させるこずができる ![on error continue](https://i.imgur.com/8Z5YrER.png)