Wednesday, April 22, 2009

Setting up DB2 WebSphere MQ functions

วันนี้ขอนำเสนอวิธีการทำให้ IBM DB2 สามารถติดต่อ รับส่ง ข้อมูลผ่านทาง IBM Websphere MQ ได้
ดังนี้ครับ

1. ตรวจสอบว่า SQLLIB\BIN ในกรณีที่เป็น Windows platform ว่ามี 
db2qgmq.dll
db2mqsw.dll 
     อยู่หรือไม่

2.  จากนั้น download Application Message Interface (AMI) จาก ที่นี้ 
      แล้วเลือกโหลดตาม platform ของ DB2 ครับเช่น Windows ก็ใช้ ma0f_nt.zip

3. เพิ่มตัวแปร AMT_DATA_PATH ซึ่งเป็น DB2 environment variable ที่ถูกใช้โดย DB2 UDB เพื่อให้แน่ใจว่า
MQ UDF จะถูก execute ถูกที่
     โดยการเพิ่มตัวแปรนี้จะเข้าไปเพิ่มใน %DB2PATH%\profile.env หรือใช้ command
     DB2SET DB2ENVLIST="AMT_DATA_PATH" 
     แบบนี้ก็ได้


4. restart DB2 instance ด้วยคำสั่ง
DB2STOP
DB2START 
    เพื่อให้ตัวแปร take effect

5. เสร็จแล้วรัน script สำหรับสร้าง DB2MQ schema ดังนี้
DB2 CONNECT TO UATDB
CD C:\Program Files\IBM\SQLLIB\cfg\mq
DB2 -tvf amtsetup.sql

6. หลังจากนั้นเราจะใช้คำสั่ง enable_MQFunctions ของ DB2 ในการสร้าง Queue Manager ใน 
Websphere MQ โดยโครงสร้างของ enable_MQFunctions เป็นดังนี้

============================================================
Usage: enable_MQFunctions -n dbName -u uID -p password
                    [-q queuemanager] [-v 0pc|1pc|2pc|all]
                    [-novalidate] [-echo] [-force]
============================================================


จากนั้นรันคำสั่งต่อไ ปนี้บน DB2 CONSOLE (DB2CMD)
enable_MQFunctions -n CHANDB -u ADMIN -p PAssword
จะไำด้ผลลัพธ์ดังนี้
C:\Program Files\IBM\SQLLIB\cfg\mq>enable_MQFunctions -n CHANDB -u ADMIN -p PAssword

  *** Please wait: creating queue manager (DB2MQ_DEFAULT_MQM) ......

  *** Please wait: starting the queue manager (DB2MQ_DEFAULT_MQM) ......

   (68) MQ UDFs of the selected version or schema were found.

  MQSeries functions already exist ...

  *** Please allow a few seconds to clean up the system ......

C:\Program Files\IBM\SQLLIB\cfg\mq>

7. จากนั้นทดลองส่งข้อความและอ่านข้อความจาก MQ ดังนี้
VALUES DB2MQ.MQSEND('SAWASDEE MQ') 
VALUES DB2MQ.MQRECEIVE() 


อ้างอิงจาก




No comments: