2009年3月7日星期六

WLS_016:WebLogic Server基本管理之十二:为JMS消息设置过期时间

运行环境:WebLogic Server 10.3.5 + Oracle Database 10g Express Edition 10.2.0.1。

Queue中的消息如果没有订阅者,默认会在Queue中一直保留,时间长了,消息会越积越多。
应该设置一个消息过期时间,到了时间还未读取的消息将进入一个专门的Queue:expiredQueue。
设计图如下:

重要步骤说明:
1.创建JMS Server:msgJMSServer
设置expiration scan interval=20,单位:seconds,即JMS Server每隔20秒扫描一次信息,看看哪些信息过期了。
如果你不想启用该选项,设置为0。

2.创建JMS Module:msgJMSSystemResource
在msgJMSSystemResource中创建如下对象:
(1)Subdeployment:msgSubdeployment。
(2)connection factory:msgConnectionFactory。
其中设置Time-to-Live=10000,单位:millseconds,即10秒钟后,消息就过期了。

(3)Queue:expireQueue。

(4)Queue:msgQueue。
其中设置JNDI name:PracticeQueue;Expiration Policy: Redirect;Error Destination: expireQueue。

(5)Topic:msgTopic。
其中设置JNDI name:PracticeTopic。

3.部署shoppingcart应用
订购一个商品,这个订购信息会发送到msgQueue中。
等待10秒钟后,检查msgQueue,发现有1条消息。

但是,点击Show Message按钮,无法看到信息内容,说明信息已经转到expireQueue了。

检查expireQueue,发现有1条消息,并且可以看到信息内容。

4.常见问题
(1)找不到PracticeQueue
日志中会报告如下错误:
javax.naming.NameNotFoundException: Unable to resolve 'PracticeQueue'. Resolved ''; remaining name 'PracticeQueue'
检查JNDI Tree后,发现确实没有PracticeQueue节点。
仔细检查后发现是因为msgSubdeployment没有target到msgJMSServer上。

Project下载:shoppingcart.7z

没有评论: