SlideShare a Scribd company logo
非同期といえばMQ
おっさんの昔話
MQ以前
• プログラム同士は相互に通信していた
• いちいち応答を待たないといけない
• メッセージはきちんと届いた?保証さ
れている?
• 文字コード変換は?文字化けしてな
い?
• セキュリティは?
• 接続するシステムが増えるほどコスト
が増える
そこでMQですよ
• プログラムはキューにメッセージを
PUTしたらあとはお任せ
• 処理をする側がGETして処理する
• プログラムはキューのみを意識すれ
ば良い
• 適切なホストへのメッセージ送信は
MQが行う
MQ
といっても
• MQの中は結構入り組んでいたりする
• システム相互接続を隠蔽しているのでその複雑さがMQの中に移動
• 環境ごとにGET・PUTするキューを作る(プログラムが意識するのはあくまでも目の
前のキューのみ)
• キューを転送用の設定をする、キュー同士をチャネルで結ぶ
• そういうわけである程度のネットワークの知識もあったほうがスムーズ
• IPアドレスとポートくらい分かってればいいかな・・・というレベル
• この辺りはMQSIという製品がソリューションとして存在していた
• 送達保証はスティッキーメッセージというメッセージを利用するが重たい
スティッキーメッセージ
• こんな処理
• 送信元は送信先にメッセージを転送(送信元には保管される)
• 送信先がメッセージをGETする
• 送信先キューは送信元キューに「メッセージがGETされた」ことを通知する
• 送信元キューから該当するメッセージを削除する
• ネットワーク的に複数回の往復が発生する
MQの使用例
• バッチ処理の開始メッセージをキューにPUT、ジョブネットがメッセージをGET
したらバッチ処理を開始する
• オープン系システムがひたすらメッセージをキューにPUTしていき、ある程度蓄
積されたらメインフレームでバッチ処理を行う
• メッセージは基本テキストだが、バイナリデータを送っても良い
• ファイル転送を行うこともアプリ次第では可能
• 最近だとチャットなんかにもMQは利用されているらしい(AWSのSQS)
使うべきでない箇所
• リアルタイム処理が必要になるケース
• 処理の結果を送信元が受け取って後続処理をするような場合は少々複雑になりやすい
• できないわけではない
• 「この処理やってる間にこっちではあの処理やろう」という場合は真っ当
• 単なるプロセス間通信として使うのであれば却って使いにくい
• JavaならSession Bean(EJB)を使うほうが良い
• いっそすべて非同期にするというデザインは何気にあり
• オペレータが処理要求を送信したらすぐに次の処理ができる
• 「後で確認する」という運用が発生するのでそこは要検討
デザイン
• あくまでも「メッセージが送信されたら完
結する」という粒度を考える
• 実行したいコマンドとそのパラメータなど
• 複数のメッセージに分割して送信する、と
いうやり方は修羅の道を歩む羽目になる
• 受け取り側でメッセージを組み立て直す
などするので
• DBに必要なデータを保存したら、先方
にコマンド実行のコマンドメッセージを
送る、などが良さそう
• 送ったメッセージの結果を同一プログラ
ムで応答待ちするのは筋が悪い(せめて
別スレッドで)
送信
PGM
受信
PGM
サー
バーサ
イド
MQ DB
JAVAとMQ
• Java APIで当初提供
• 二つ目くらいのバージョンからコネクションプーリングをサポート(IBMの場合)
• コネクションのコストがかなり高かったので、これによって10倍くらい早くなった
• JMSで標準化
• Java Messaging Service
• JavaEEの標準ライブラリでインターフェースを統一
• なんだかんだでベンダースペシフィックな部分が利用可能だったりした
• モダンなJavaEEではどの程度隠蔽されたかはすいません知らないです
JAVAとMQ その2
• Message Driven Bean
• JMS+Event Driven+EJB
• 所定のキューにメッセージがPUTされたらJavaEEサーバーがGETしてEJBをイベントドリブ
ンに呼び出す
• これがなかった頃は、EJBでJMSを使用してキューにメッセージがPUTされるのをひたすら
待つ、ということをしていた
• 使い方としては微妙
• これのおかげで結構EJBも使いやすくなった気がする
• トランザクションはコンテナマネージドになった気がする
• つまり、マニュアルにbeginやcommitを呼ぶことができないので、rollbackをきちんと意識する
SOAとMQ
• サービス指向アーキテクチャになると、MQはインフラとして活用される
• もともとインフラといえばインフラだけど、SOAによってかなり隠蔽される
• SOAによってプロトコルが統一されたので、EJBだろうとDBだろうと全部繋がる
• ただ仕様がめちゃくちゃ重たい
• Hello Worldしたらその10倍くらいのXMLが付いてくる
• 様々な技術の相互接続性を確保するためなので、最小公倍数がでかいのではと推察
トランザクションとMQ
• 2PCをサポート
• MQとDBをUOW(Unit Of Work)として処理できる
• MQからメッセージをGET、ビジネスロジックを実行(DB更新含む)、結果をMQにPUTと
いうのを一つのトランザクションとしてbegin~commit/rollbackで囲って良い
• XAインターフェースを実装している必要がある
• トランザクションのスコープに参加するためにミドルウェアが実装するインターフェース
• 2PCは、ようはトランザクションに参加するすべてのリソースに「コミットするよ?」と
聞いて、全部が「コミットしていいよ!」と応答したら改めてすべてコミットさせる方式
• 2PCが実務上必要なシチュエーションは少ないかもしれないけど金融系では普通に利用さ
れています
MQあるある
• 高橋の高問題
• 文字コードのマッピングに不備があり、一部環境では高橋が髙橋に変換される
• 同じように渡辺が確か渡邊になる問題もあった
• 文字コードがSJISやEUCといったものが乱立していたために起きた出来事

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

非同期といえばMQ