2011年12月22日星期四

WLS_079:WebLogic Server高级管理之八:JMS 存储与转发

运行环境:WebLogic Server 12.1.1 开发版 + Oracle Database 10g Express Edition 10.2.0.1。

我们知道,部署在某个WebLogic Server上的应用可以通过JNDI访问到部署在该Server上的Queue/Topic。
如果有两个应用是分别部署在同一个Domain的两个Server上,或者是两个Domain的Server上,那么如何通过Queue/Topic进行通讯?
WebLogic Server中的JMS功能提供了一个Store and Forward特性,可以帮助我们实现该功能。

设计图如下:


重点步骤说明:
1. 创建两个Domain:dev_domain和dev2_domain
其中dev_domain作为消息源,dev2_domain作为消息目的。

2. 在dev2_domain创建JMS资源
JMS Modules:msg2JMSSystemResource
JMS Server:msg2JMSServer
Connection Factory:msg2ConnectionFactory
Queue:msg2Queue
Subdeployment:msg2Subdeployment


3. 在dev_domain创建JMS资源
创建完成后的JMS Modules:MySAFSystemModule。


(1)创建Store-and-Forward Agents:MySAFAgent,target到Server上。

(2)创建JMS Modules:MySAFSystemModule

(3)在MySAFSystemModule中创建SubDeployment:MySAFSubDeployment,target到MySAFAgent上。
注意,与一般的SubDeployment定义不同,这里要把target到MySAFAgent上。
不要把MySAFSubDeploymenttarget到JMS Server上,这一步很关键,不要搞错。

(4)在MySAFSystemModule中创建Connection Factory:MySAFConnectionFactory,target到MySAFSubDeployment上。

(5)在MySAFSystemModule中创建remote SAF contex:MyRemoteSAFContext。
这里指向dev2_domain。


(6)在MySAFSystemModule中创建SAF imported destinations:MySAFImportedDestination。
此步特别容易出错,建议如图配置后,直接点击finish按钮;然后再为其设置SubDeployment,选择MySAFSubDeployment。


(7)在MySAFImportedDestination中创建Queue:MySAFQueue。
注意别忘了设置Local JNDI Name。
此步也特别容易出错,如图配置后,点击save按钮时如果报出如下错误:
“The imported destination msg2Queue has been targeted to an invalid target:msgJMSServer”
请把MySAFImportedDestination的SubDeployment设置为None。
然后再重新创建Queue并保存。
最后把MySAFImportedDestination的SubDeployment再改回MySAFSubDeployment。


(8)重新启动dev_domain中的AdminServer。
查看JNDI Tree,如果能看到SAF_msg2Queue,说明SAF配置成功。


4. 测试

4.1 测试Forward
(1)分别启动dev_domain和dev2_domain中的AdminServer。
(2)向dev_domain中的SAF Queue:和SAF_msg2Queue中发消息。
(3)观察dev_domain中的SAF Queue:

点击Remote Endpoints进去查看,发现没有一条消息,消息可能已经转发走了。

(4)观察dev2_domain中的Queue:msg2Queue
发现消息都转发过来了。

4.2 测试Store and Forward
(1)只启动dev_domain中的AdminServer。
(2)向dev_domain中的SAF Queue:和SAF_msg2Queue中发消息。
(3)观察dev_domain中的SAF Queue

点击Remote Endpoints进去查看,发现消息都在这里,消息的详细信息如下。

(4)启动dev2_domain中的AdminServer
(5)观察dev2_domain中的Queue:msg2Queue
发现消息都转发过来了。
(6)再次观察dev_domain中的SAF Queue。
发现消息都没有了,已经转发走了。

说明:发送消息的代码可以参考《为JMS消息设置顺序》中的QueueSend.java。

没有评论: