IBM WebSphere MQ 基礎觀念

隔了幾個月再碰到自己寫的 WebSphere MQ 程式,又花了些時間繞來繞去,才找到自己先前寫的筆記,放在某個雲端筆記本裡面 Orz。果然出來混總是要還的,終究得整理一下,放在這裡,免得下次又翻箱倒櫃。


之前寫的<使用 .NET 撰寫 IBM WebSphere MQ 應用程式>著重在使用 C# 來撰寫攔截訊息事件的程式,裡面比較少 MQ 的核心觀念和關鍵術語。這篇可稍微補前篇之不足,但只提重點觀念,不寫範例程式。如需 .NET 範例程式,可參考文後附的延伸閱讀清單。

此外,我只是把這篇筆記當作將來開啟記憶的鑰匙,主要是寫給自己看的,所以其中一些從 IBM 紅皮書剪貼過來的原文段落和圖片,我就沒動手翻譯了。也許將來有機會回頭複習時再加以潤飾。

以下內容主要摘自 IBM 提供的免費電子書:MQSeries Primer (1999)。此電子書版本較舊,另有新版本:WebSphere MQ Primer (2012)。

註:MQSeries 是早期的產品名稱,後來改稱 WebSphere MQ。後面提到此軟體時偶爾會簡稱 MQ。

WebSphere MQ message queuing infrastructure
  • The nodes within a WebSphere MQ message queuing infrastructure are called queue managers.
  • WebSphere MQ Version 6.0 supports point-to-point and publish/subscribe messaging model.
  • The queue managers maintain the queues of the message queuing infrastructure and all of the messages that reside on those queues waiting to be processed or routed. Queue managers are tolerant to failures, maintaining the integrity of the business-critical data flowing through the message queuing infrastructure.
  • The queue managers within the infrastructure are connected with channels. Messages automatically flow across these channels, from the initial producer of a message to the eventual consumer of that message, based on the configuration of the queue managers in the infrastructure.
Facilities for building a WebSphere MQ infrastructure
  • WebSphere MQ V6.0 provides the WebSphere MQ Explorer, which is a graphical user interface (GUI) used to configure and monitor the queue managers within a WebSphere MQ infrastructure from a desktop workstation.
  • WebSphere MQ provides a scripting interface called MQSC to perform administration on all platforms.
The Queue Manager

The heart of MQSeries is the message queue manager (MQM), MQSeries’ run-time program. Its job is to manage queues and messages for applications. It provides the Message Queuing Interface (MQI) for communication with applications. Application programs invoke functions of the queue manager by issuing API calls. For example, the MQPUT API call puts a message on a queue to be read by another program using the MQGET API call. This scenario is shown in Figure 4.

A program may send messages to another program that runs in the same machine as the queue manager (shown above), or to a program that runs in a remote system, such as a server or a host. The remote system has its own queue manager with its own queues. This scenario is shown in Figure 5.

我的程式是採用圖 5 的通訊架構。


MQ 的 channel 可分為兩大類
  • Message Channel:單向通道,用來將訊息從一個 quque manager 傳送至另一個 queue manager。例如專用來做為傳送至遠端 queue manager 的通道(sender channel),或者專用來作為接收從遠端 queue manager 傳來知訊息的通道(receiver channel)。
  • MQI Channel:雙向通到,用來將 MQI 呼叫從一個 MQ 用戶端傳送至某 queue manager,以及將某 queue manager 的回應訊息傳送至 MQ 用戶端。
MQ Channel 又分為兩種:server-connection channel 和 client-connection channel。
  • Server-connection channel:用來供用戶端程式連接至一個 Queue Manager。此通道似乎不是絕對必要--我還不是那麼確定,因為我的用戶端應用程式所運行的機器上即使沒有建立 server connection channel 也能正常執行(有建立的話也可以,而且可以從 MQ Explorer 工具中觀察到,當應用程式存取佇列時,那個 server-connection channel 的狀態會自動從 Inactive 變成 Active)。
  • Client-connection channel: 還沒用到,略。

Queue Types

了解各種 queue 的類型是絕對有必要的。你至少要知道 local queue 和 remote queue 的用途,也要知道什麼是 transmission queue 和 dead-letter queue,這樣在看一些文件時才不至於像無頭蒼蠅,程式出問題時也比較容易抓錯。

Local queue    is a real queue
Remote queue structure describing a queue
Transmission queue (xmitq)local queue with special purpose  
Initiation queue  local queue with special purpose  
Dynamic queue  local queue created "on the fly"  
Alias queue   if you don’t like the name  
Dead-letter queue  one for each queue manager. 所有傳送失敗的訊息都會丟到這裡。
Reply-to-queue  specified in request message  
Model queue  model for local queues
Repository queue  holds cluster informa

Remote Queue

A queue is “remote” if it is owned by a different queue manager. A remote queue definition is the local definition of a remote queue. A remote queue is not a real queue. It is a structure that contains some of the characteristics of a queue hosted by a different queue manager.

The application programmer can use the name of a remote queue just as he or she can use the name of a local queue. The MQSeries administrator defines where the queue actually is. Remote queues are associated with a transmission queue.

  • A program cannot read messages from a remote queue.
  • You don't need a remote queue definition for a cluster queue.
.NET 程式設計相關
  • .NET 應用程式需要引用的 MQ DLL 只有一個:amqmdnet.dll。這是給 .NET 應用程式使用的函式庫。裝好 IBM WebSphere MQ V7.x 之後,在安裝目錄 C:\Program Files(x86)\IBM\WebSphere MQ\bin\ 底下可以找到這個檔案。
  • 要特別注意的是,開發應用程式時繫結的 amqmdnet.dll 版本必須與將來部署至用戶端機器時的版本一致,否則可能會發生找不到組件的錯誤。我曾經在開發機器上更新 WebSphere MQ,然後沒注意到應用程式繫結的 amqmdnet.dll 版本從 v7.5.0.0 變成 v7.5.0.1。就只有這尾數的 build number 版號的差異,就造成用戶端應用程式掛掉。
Copyright © 2012. Huan-Lin 學習筆記 - All Rights Reserved
Powered by Blogger
Template Design by Cool Blogger Tutorials
Published by Templates Doctor