- 追加された行はこの色です。
- 削除された行はこの色です。
「[[Open棟梁 wiki>https://opentouryo.osscons.jp]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。
-[[戻る>非同期処理サービス]]
*目次 [#ld25e8d1]
#contents
*概要 [#sf4b4148]
非同期処理サービス構築のチュートリアル作成前段階のメモ
-Open棟梁v02-30以降のリポジトリ分割後の手順(非同期処理サービスv01-00)。
-旧手順(v02-20以前)は[[コチラ>非同期処理サービス構築の覚書(旧)]]を参照。
-v02-30以降のリポジトリ分割後の手順。
-旧手順(v02-20以前)は[[コチラ>非同期処理サービス構築の覚書(旧)]]。
*準備 [#a7c2e6de]
環境を準備する。
-Visual Studio 2015 以上の任意のエディション
-SQL Server 任意のバージョンとエディション
-Open棟梁のテンプレート
-SQL Server 以上の任意のバージョンとエディション
-非同期処理サービス v01-00 以上のテンプレート
検証は、
本ページの作成と検証には、
-Windows 10
-Visual Studio 2015
-SQL Server 2016
を使用した。
*手順 [#x445dade]
**インストール [#e3e22d57]
**前提ソフトウェアのインストール [#e3e22d57]
以下をインストール
-Visual Studio 2015 の任意のエディション
-SQL Server 2016 の任意のエディション
**Open棟梁 - 非同期処理サービスのテンプレート [#n5812bc3]
**非同期処理サービスのテンプレート [#n5812bc3]
***取得 [#g0f23c6e]
-GithubからOpen棟梁 - 非同期処理サービスのテンプレートを取得~
https://github.com/OpenTouryoProject/AsynchronousProcessingService/
--必要に応じて、branchやtagを指定。以下は、01-00のtagを指定した場合。~
https://github.com/OpenTouryoProject/AsynchronousProcessingService/tree/01-00
-rootをC:\rootにデプロイ。
-ビルドを行う。
--https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/3_Build_Framework.bat
--https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/VB/3_Build_Framework.bat
***デプロイ [#ie19c0e1]
rootをC:\rootにデプロイ。
**データベース [#s0240817]
***ビルド [#zbf831f1]
ビルドを行う。
-C:\root\programs\CS\3_Build_Framework.bat
-C:\root\programs\VB\3_Build_Framework.bat
**データベースの準備 [#s0240817]
***作成 [#g96ed721]
-AsyncProcessingServiceDBというデータベースを作成する。
***セキュリティ設定 [#lfdd7d5c]
サービス・アカウントからSQL Serverにログインする。
なので、以下の手順に従って、~
ローカル・システム・アカウントのログインと権限付与をする。
-システム・アカウントのユーザを作成する。
--Windows ユーザー
--NT AUTHORITY\SYSTEM
-アクセス権限を付与する。
--「所有されているスキーマ」に”db_owner”を追加する。
--「メンバーシップ」に”db_owner”を追加する。
***テーブルの作成 [#nfba18e9]
-このデータベースにテーブルを作成する。以下のSQLファイルを実行する。~
https://github.com/OpenTouryoProject/AsynchronousProcessingService/tree/develop/root/files/resource/AsyncProcessingService/Sql/sqlserver
--CreateAsyncProcessingServiceStatusManagementTableScript.sql
--CreateEnumAsyncCommandTableScript.sql
--CreateOpenTouryoCodeTableScript.sql
**非同期処理サービス [#nd7f243e]
***設定 [#x8185bb2]
app.configファイルの接続文字列を設定する。
<connectionStrings>
<!-- SQL Server / SQL Client用 -->
<add name="ConnectionString_SQL" connectionString="Data Source=localhost\sqlexpress;Integrated Security=SSPI;Initial Catalog=AsyncProcessingServiceDB;"/>
</connectionStrings>
***ビルド [#k8d96065]
AsyncProcessingServiceをビルドする。
-Visual Studioからビルド
-もしくは、batでビルド~
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/4_Build_AsyncProcessingService.bat
-もしくは、batでビルド
C:\root\programs\CS\4_Build_AsyncProcessingService.bat
***インストール [#d904c281]
ビルド出力(*.exe)をWindowsサービスとしてインストールする。
-CMDを起動し、CD(Change Directory)コマンドで以下のパスに移動
-CMDを管理者として起動し、CD(Change Directory)コマンドで以下のパスに移動
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
-以下のInstallUtilコマンドで、ビルド出力(*.exe)をWindowsサービスとしてインストールする。
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe -i "C:\root\programs\CS\Frameworks\Infrastructure\AsyncProcessingService\bin\Debug\AsyncProcessingService.exe"
-管理ツールのサービス(コマンドからはservices.msc)を起動し、~
サービスの一覧にAsyncProcessingServiceが登録されていることを確認する。
**非同期処理タスク [#k54bf73d]
非同期処理タスクのクライアントとサーバを開発する。
以下のソリューションファイルを開くと、2つのプロジェクトが開く。
C:\root\programs\CS\Samples\AsyncSvc_sample\AsyncSvc_sample.sln
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Samples/AsyncSvc_sample/AsyncSvc_sample.sln
***非同期処理タスクを投入するクライアント [#e2a3cf97]
TestAsyncSvc_Sample
非同期処理をキューに登録するプログラム。
-設定~
app.configファイルの接続文字列を設定する。
<connectionStrings>
<!-- SQL Server / SQL Client用 -->
<add name="ConnectionString_SQL" connectionString="Data Source=localhost\sqlexpress;Integrated Security=SSPI;Initial Catalog=AsyncProcessingServiceDB;"/>
</connectionStrings>
-ビルド
--Visual Studioからビルド
--もしくは、batでビルド
---https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/5_Build_AsyncSvcSample.bat
---https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/VB/5_Build_AsyncSvcSample.bat
---C:\root\programs\CS\5_Build_AsyncSvcSample.bat
---C:\root\programs\VB\5_Build_AsyncSvcSample.bat
***サーバで実行される非同期処理タスク [#ma5282bf]
AsyncSvc_sample
登録された非同期処理を取り出しディスバッチする先のビジネスロジック。
-ビルド
--Visual Studioからビルド
--もしくは、batでビルド
---https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/5_Build_AsyncSvcSample.bat
---https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/VB/5_Build_AsyncSvcSample.bat
---C:\root\programs\CS\5_Build_AsyncSvcSample.bat
---C:\root\programs\VB\5_Build_AsyncSvcSample.bat
-デプロイ~
ビルドが完了したら、非同期処理サービスのプロジェクト出力フォルダにコピーする。
-デプロイ
--ビルドが完了したら、非同期処理サービスのプロジェクト出力フォルダにコピーする。
"C:\root\programs\CS\Frameworks\Infrastructure\AsyncProcessingService\bin\Debug"
--もしくは、batでデプロイ
C:\root\programs\CS\6_CopyToService.bat
**非同期処理サービスの実行 [#ya79b39f]
***実行 [#g1b2223f]
-AsyncProcessingServiceをSCMから開始する。
-TestAsyncSvc_Sampleを実行して非同期タスクを登録する。
-非同期処理タスクを投入する。
--TestAsyncSvc_Sampleを実行する。
--もしくは、batで投入する。
C:\root\programs\CS\7_SubmitTask.bat
***確認 [#ocf9e758]
-非同期処理管理テーブルを監視して非同期処理が遂行されることを確認する。
#ref(db.png,left,nowrap,非同期処理管理テーブル,50%)
-非同期処理サービスが実行されない場合は以下のログを分析する。~
"C:\root\files\resource\AsyncProcessingService\Log\"
--非同期処理サービス
---ASYNC-SERVICE.log
---ACCESS-ASYNC.YYYY-MM-DD.log
---SQLTRACE-ASYNC.YYYY-MM-DD.log
--クライアント
---ACCESS.YYYY-MM-DD.log
---SQLTRACE.YYYY-MM-DD.log
*非同期処理サービスの開発方法 [#pb6b5072]
**引数・戻り値、B層、D層 [#y5cd25ef]
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Frameworks/Infrastructure/Business/
**非同期処理サービス本体 [#i072c794]
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Frameworks/Infrastructure/AsyncProcessingService/
**DamKeyforABT [#md6775b3]
*非同期処理タスクの開発方法 [#pb6b5072]
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Samples/AsyncSvc_sample/AsyncSvc_sample/LayerB.cs
**MyApsBaseLogic [#n93e57ff]
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Frameworks/Infrastructure/Business/AsyncProcessingService/MyApsBaseLogic.cs
--非同期処理タスクのB層が継承するクラス。
--業務テーブルと非同期処理管理テーブルに接続可能。
***DamKeyforABT [#md6775b3]
業務テーブルにアクセスする場合に使用するDam
**DamKeyforAMT [#uef4e193]
***DamKeyforAMT [#uef4e193]
非同期処理管理テーブルにアクセスする場合に使用するDam
**接続文字列 [#bfb3a689]
***接続文字列 [#bfb3a689]
-非同期処理管理テーブルと業務テーブルが同じデータベース内にある場合は、~
DamKeyforABTとDamKeyforAMTの接続文字列には同じ接続文字列を使用する。
-非同期処理管理テーブルと業務テーブルが異なるデータベース内にある場合は、~
以下をカスタマイズして、DamKeyforABTとDamKeyforAMTの接続文字列を分割する。
-MyApsBaseLogic.UOC_ConnectionOpen()メソッド~
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Frameworks/Infrastructure/Business/AsyncProcessingService/MyApsBaseLogic.cs
*非同期処理タスクの開発方法 [#pb6b5072]
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Samples/AsyncSvc_sample/AsyncSvc_sample/LayerB.cs
**UOC_Start(UOC_XXXX) [#l83ef167]
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Samples/AsyncSvc_sample/AsyncSvc_sample/LayerB.cs#L138
***概要 [#necf8a68]
-[[サーバで実行される非同期処理タスク>#ma5282bf]]のエントリポイント。
-[[通信制御機能]]のインプロセス呼び出しにより呼び出される。
***設定 [#m0062182]
インプロセス呼び出しの定義は以下のファイルの中に定義にされている。
https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/files/resource/AsyncProcessingService/Xml/TMInProcessDefinition.xml
***処理の流れ [#z7f12540]
-[[DeserializeFromBase64String>#i4045a40]]メソッドで業務データを復元
-JsonConvert.DeserializeObjectメソッドで業務データを復元
-[[GetCommandValue>#w05390ae]]メソッドによりCommandIDを取得する。
-CommandIDがStopの場合、
--[[ResumeProcessing>#e40a69f7]]メソッドでCommandIDを「0」クリアする。
--既存処理のResumeを行う。
-それ以外の場合、
--新規処理の初期化を行う。
-Updateメソッドにより業務処理を行う。
-処理を抜けた場合、正常終了の扱いとなる。
**Utilityメソッドの説明 [#t9139027]
**業務処理メソッド [#h47d5d87]
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Samples/AsyncSvc_sample/AsyncSvc_sample/LayerB.cs#L183
***DeserializeFromBase64Stringメソッド [#i4045a40]
DeserializeFromBase64Stringメソッドで、~
userParameterValue.Dataの業務データをバイナリデータからオブジェクトへ復元する。
***業務処理(Updateメソッド) [#w087037a]
***SerializeToBase64String [#y9726992]
[[DeserializeFromBase64String>#i4045a40]]メソッドの逆を行う。
***GetCommandValueメソッド [#w05390ae]
非同期処理管理テーブルから本非同期タスクのTaskIDに対応するCommandIDを取得する。
***ResumeProcessingメソッド [#e40a69f7]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応するCommandIDを、~
[[UpdateTaskCommand>#y4b09b2b]]メソッドによって「0」クリアする。
***UpdateProgressRateメソッド [#gbfce054]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応する進捗率をアップデートする。
***UpdateTaskCommandメソッド [#y4b09b2b]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応するCommandIDを更新する。
**業務処理 [#h47d5d87]
***Updateメソッド(業務処理) [#w087037a]
業務処理([[GenerateProgressRate>#mde46ab2]])を実行する。
-[[GetCommandValue>#w05390ae]]メソッドによりCommandIDを取得する。
-取得したCommandIDをチェックする。
--Stop:業務例外をthrowして処理をリトライする。
--Abort:システム例外をthrowして処理をABENDする。
--その他:
---業務処理を続行する。
---業務処理([[GenerateProgressRate>#mde46ab2]])を実行する。
---進捗率を[[UpdateProgressRate>#gbfce054]]メソッドでアップデートする。
-補足
--必要に応じてループで実装する。
--サンプルでは一定の確率で
---StopとAbortを実行する。
---[[UpdateTaskCommand>#y4b09b2b]]メソッドを使用する。
***GenerateProgressRateメソッド [#mde46ab2]
ダミーの業務処理。進捗率を返す。
***確率計算メソッド [#y2245939]
ダミーの業務処理。
-GenerateProgressRateメソッド~
ランダムに進捗率を返す。
-Fortuneメソッド~
ランダムに真/偽を返す。
**Utilityメソッド [#t9139027]
v02-30から、Utilityメソッドの実装を以下に移動。
-https://github.com/OpenTouryoProject/AsynchronousProcessingService/blob/develop/root/programs/CS/Frameworks/Infrastructure/Business/AsyncProcessingService/ApsUtility.cs
***GetCommandValueメソッド [#w05390ae]
非同期処理管理テーブルから本非同期タスクのTaskIDに対応するCommandIDを取得する。
***ResumeProcessingメソッド [#e40a69f7]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応するCommandIDを、~
[[UpdateTaskCommand>#y4b09b2b]]メソッドによって「0」クリアする。
***UpdateProgressRateメソッド [#gbfce054]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応する進捗率をアップデートする。
***UpdateTaskCommandメソッド [#y4b09b2b]
非同期処理管理テーブルの本非同期タスクのTaskIDに対応するCommandIDを更新する。