WebSphere Application Server V5(以下称为 Application Server)提供了一个新的消息传递功能,该功能包括对 Java Messaging Service (JMS) 提供程序的支持。Application Server 包括一个称为嵌入式 JMS 提供程序的内部 JMS 提供程序。该提供程序依赖于 IBM 消息传递技术的子集,即用于点到点消息传递的 WebSphere MQ V5.3 和用于发布/订阅消息传递的 WebSphere MQ Event Broker V2.1。Application Server V5 还支持 WebSphere MQ 作为 JMS 提供程序。
本文描述了如何启用 JMS Java 2 Platform Enterprise Edition (J2EE) 应用程序以在 Application Server 中使用嵌入式 JMS 提供程序或者 MQ JMS 提供程序。
下面的部分描述了如何安装嵌入式 JMS 提供程序或者 MQ JMS 提供程序。
要使用嵌入式 JMS 支持,请在安装 Application Server V5 时选择 Embedded Messaging Client 和 Embedded Messaging Server 选项。嵌入式消息传递客户机启用运行在 Application Server 上的应用程序,以与 WebSphere JMS 提供程序进行通信。嵌入式消息传递服务器包含 WebSphere JMS 提供程序的消息传递服务器的功能,并提供点到点和发布/订阅消息传递功能。如果系统上已存在 Websphere MQ,则 Application Server 可以将其作为 JMS 提供程序,但是您必须确保安装了正确的 WebSphere MQ 版本以及功能,如下一部分所述。
Application Server V5 支持 WebSphere MQ 作为备用 JMS 提供程序。要安装 MQ JMS 提供程序,请执行以下操作:
- 如 WebSphere MQ 附带的安装说明所述,安装具有 Application Server V5 支持的所需 MQ 功能的 WebSphere MQ V5.3。这将启用点到点消息传递支持。
- 如果您需要发布/订阅消息传递支持,则还必须安装一个发布/订阅代理。确保发布/订阅代理支持所安装的 Websphere MQ。IBM 提供三个发布/订阅代理:
- WebSphere MQ Event Broker V2.1
- WebSphere Business Integration(以下称为 BI )Event Broker V5
- WebSphere Business Integration Message Broker V5
在本文中,我们将 BI Message Broker V5 作为发布/订阅代理。
下面的部分描述如何配置和启动嵌入式 JMS 提供程序和 MQ JMS 提供程序。
一旦安装了 Application Server 以使用嵌入式 JMS 提供程序,就转到管理控制台并完成下面的步骤,以便启用将由 JMS J2EE 应用程序使用的 JMS 资源:
- 在 Application Server 管理控制台中,选择 Resources => WebSphere JMS Provider 并创建由 JMS J2EE 应用程序使用的 JMS 资源(即,Queue Connection Factories、Queue Destinations、TopicConnectionFactories 和 Topic Destinations)。创建 Queue Connection Factories 和 Queue destinations 以用于点到点消息传递应用程序。创建 Topic Connection Factories 和 Topic destinations 以用于发布/订阅消息传递应用程序。
图 1. Websphere JMS 提供程序
- 创建示例 JMS 资源
SmQueueConnectionFactory、SmTopicConnectionFactory和SmQueueSub,如下面的示例所示:
图 2. Queue Connection Factory 示例
图 3. Topic Connection Factory 示例
图 4. Queue Destination 示例
- 要确保将 JMS 资源正确地绑定到 Java 命名和目录接口 (JNDI) 名称空间,在运行 JMS J2EE 应用程序的 Application Server
SystemOut.log中查找下面的关键消息。将资源绑定到名称空间,这样应用程序就可以动态地对其进行查找。使用 javax.naming.InitialContext 类查找方法以定位资源。另外,在创建 JMS 资源时管理员必须为它配置一个范围。这决定了 JMS 资源可以由一个应用服务器使用,还是由运行在节点上的所有应用服务器或运行在网络部署单元 (Network Deployment cell) 的所有应用服务器使用。[10/5/04 16:11:40:062 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmQueueConnectionFactory as jms/SmQueueConnectionFactory [10/5/04 16:11:40:062 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmQueueSub as jms/SmQueueSub [10/5/04 16:11:40:109 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmTopicConnectionFactory as jms/SmTopicConnectionFactory
- 在管理控制台中,将 JMS Queue 和 Topic 目的资源添加到运行 JMS J2EE 应用程序的 Application Server 的 JMS 服务器。并且,将 JMS 服务器的初始状态属性设置为 started,以便确保在 Application Server 启动时 JMS 服务器可以自动启动。
例如,添加 JMS Queue 目的资源,SmQueueSub,并将 JMS 服务器的初始状态属性设置为 started,如下面的示例所示:
- 选择 Servers => Application Servers。这将显示有关管理域中应用服务器的一个表。
- 在内容窗格中,单击 Application Server 的名称(例如,
MYServer)。这将显示内容窗格中 Application Server 的属性。 - 在内容窗格中,在 Additional Properties 下,选择 Server components => JMS Servers。这将显示内容窗格中 JMS 服务器的属性。
- 将所创建的 Queue 和 Topic 目的资源添加到 JMS 服务器的 Queue names 属性中。
- 确保将 JMS 服务器 Initial State 属性设置为 started。
图 5. JMS 服务器属性
- 在运行 JMS J2EE 应用程序的 Application Server
SystemOut.log中查找下面的关键消息,以确保嵌入式 JMS 服务器正常启动:[5/11/04 11:28:51:234 EDT] 4dc429c9 JMSEmbeddedPr A MSGS0050I: Starting the Queue Manager [5/11/04 11:28:52:953 EDT] 4dc429c9 JMSEmbeddedPr A MSGS0051I: Queue Manager open for business [5/11/04 11:28:52:953 EDT] 4dc429c9 JMSEmbeddedPr A MSGS0052I: Starting the Broker [5/11/04 11:28:55:453 EDT] 4dc429c9 JMSEmbeddedPr A MSGS0053I: Broker open for business
- 如果 JMS J2EE 应用程序使用 Message Driver Bean,则需要在管理控制台创建侦听器端口。侦听器端口允许 JMS 应用程序异步侦听消息。Message Driver Bean 所使用的侦听器端口在运行 JMS J2EE 应用程序的 Application Server 的消息侦听器服务 (Message Listener Service) 中创建。下面的 JMS J2EE 应用程序描述符展示了侦听器端口的示例定义(重点突出部分):
<?xml version="1.0" encoding="UTF-8"?> <ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbbnd="ejbbnd.xmi" xmlns:ejb="ejb.xmi" xmi:id="EJBJarBinding_1055163252462" currentBackendId="DB2UDBNT_V72_1"> <ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/> <ejbBindings xmi:id="EnterpriseBeanBinding_1055163252462" jndiName="ejb/com/ibm/pvc/ins/sm/server/SubscriptionServiceHome"> <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#SubscriptionService"/> </ejbBindings> <ejbBindings xmi:id="EnterpriseBeanBinding_1055197456298" jndiName="ejb/com/ibm/websphere/startupservice/SubscriptionStartUpBean"> <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#AppStartUp"/> </ejbBindings> <ejbBindings xmi:id="EnterpriseBeanBinding_1056144206631" jndiName="ejb/com/ibm/pvc/ins/sm/database/Triggers"> <enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#Triggers"/> </ejbBindings> <ejbBindings xmi:type="ejbbnd:MessageDrivenBeanBinding" xmi:id="MessageDrivenBeanBinding_1060968316889" listenerInputPortName="SmLpSub"> <enterpriseBean xmi:type="ejb:MessageDriven" href="META-INF/ejb-jar.xml#MessageDriven_1060968316889"/> </ejbBindings> <ejbBindings xmi:id="EnterpriseBeanBinding_1062106510434" jndiName="ejb/com/ibm/pvc/ins/sm/server/SubscriptionAdminServiceHome"> <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#SubscriptionAdminService"/> </ejbBindings> <ejbBindings xmi:id="EnterpriseBeanBinding_1082140050533" jndiName="ejb/com/ibm/pvc/ins/sm/database/SubOwner"> <enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#SubOwner"/> </ejbBindings> <defaultCMPConnectionFactory xmi:id="CMPConnectionFactoryBinding_1056146794783" jndiName="jdbc/insdb" resAuth="Container"/> </ejbbnd:EJBJarBinding>
例如,要为 JMS J2EE 应用程序定义侦听器端口SmLpSub,请执行以下操作:- 在管理控制台的导航窗格中,选择 Servers => Application Servers。
- 单击包含应用程序的服务器(例如,
MYServer)。 - 选择 Configuration 选项卡。
- 在 Additional Properties 部分中,选择 Message Listener Service。
- 在 Additional Properties 部分中,选择 Listener Ports。
- 单击 New,添加侦听器端口
SmLpSub。 - 在 Name 中,指定 SmLpSub
- 在 Connection Factory jndi name 字段中,指定 jms/SmQueueConnectionFactory
- 在 Destination jndi name 字段中,指定 jms/SmQueueSub
图 6. 侦听器端口 SmLpSub 示例
- 在运行 JMS J2EE 应用程序的 Application Server
SystemOut.log中查找下面的关键消息,以确保对侦听器端口进行正确定义:[10/5/04 16:11:55:859 EDT] 4d253026 MDBListenerIm I WMSG0042I: MDB Listener SmLpSub started successfully for JMSDestination jms/SmQueueSub
- 完成了上述步骤后,启动 Application Server,然后在管理控制台部署并启动 JMS J2EE 应用程序,以便对其进行验证。
一旦安装了 WebSphere MQ、BI Message Broker 和 Application Server 以使用 MQ JMS 提供程序,就执行下面的步骤,以便启用将由 JMS J2EE 应用程序使用的 JMS 资源:
- 在 WebSphere MQ 中,创建一个队列管理器。在创建队列管理器时,记录队列管理器的名称、主机以及端口,在 Application Server 中设置 JMS 资源时需要使用它们。下面的 WebSphere MQ 命令展示了如何创建一个示例队列管理器
WAS_mytest1_MYServer:crtmqm WAS_mytest1_MYServer
有关创建队列管理器的详细信息,请参阅 WebSphere MQ 文档。 - 在 BI Message Broker 中,为与创建的队列管理器相关的 JMS 发布/订阅消息传递创建一个代理。该代理与队列管理器相关,并且可以只与一个队列管理器相关。下面的 BI Message Broker 命令展示了如何创建一个与队列管理器
WAS_mytest1_MYServer相关的示例代理MYBroker1:mqsicreatebroker MYBroker1 -i <service_id> -a <service_pswd> -q WAS_mytest1_MYServer -n <broker_db> <db> -u <db_id> -p <db_pswd>
其中:- <service_id> 必须是本地组
mqbrkrs的成员,并且有权访问安装 BI Message Broker 的主机目录 - <service_pwsd> 是与 service_id 相关的密码
- <broker_db> 是在其中创建代理表的数据库的 ODBC 数据源名称 (DSN)
- <db> 是在其中创建代理表的数据库的 ODBC 数据源名称 (DSN)
- <db_id> 是数据库用户 ID
- <db_pwsd> 是与 db_id 相关的数据库密码
- <service_id> 必须是本地组
- 在 Application Server 管理控制台中,配置 Application Server 以使用 MQ JMS 提供程序。导航到 Environment => Manage WebSphere Variables,并且将 MQJMS_LIB_ROOT 环境变量设置为安装 WebSphere MQ 的目录,如下所示:
图 7. 管理 WebSphere 变量
- 在 Application Server 管理控制台中,选择 Resources => WebSphere MQ JMS Provider,并创建 JMS J2EE 应用程序使用的 MQ JMS 资源(即,Queue Connection Factories、Queue Destinations、TopicConnectionFactories 和 Topic Destinations)。
图 8. WebSphere MQ JMS 提供程序
创建示例 MQ JMS 资源SmQueueConnectionFactory、SmTopicConnectionFactory和SmQueueSub,如下面的示例所示:
图 9. Queue Connection Factory 示例
图 10. Topic Connection Factory 示例
图 11. Topic Connection Factory 示例(继续)
图 12. Queue Destination 示例
图 13. Queue Destination 示例(继续)
- 下面是一个这样的示例:在运行 JMS J2EE 应用程序的 Application Server
SystemOut.log中查找关键消息,以确保 MQ JMS 资源被正确地绑定到 JNDI 名称空间:[10/5/04 16:11:40:062 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmQueueConnectionFactory as jms/SmQueueConnectionFactory [10/5/04 16:11:40:062 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmQueueSub as jms/SmQueueSub [10/5/04 16:11:40:109 EDT] 4d253026 ResourceMgrIm I WSVR0049I: Binding SmTopicConnectionFactory as jms/SmTopicConnectionFactory
- 在 Application Server 管理控制台中,选择 Servers => Application Servers,并在运行 JMS J2EE 应用程序的 Application Server 的消息侦听器服务中创建侦听器端口。该步骤与嵌入式 JMS 提供程序中的步骤相同。
- 在 Websphere MQ 中,在队列管理器上创建与在 Application Server 中创建的 JMS Queue 目的资源对应的队列。下面的 WebSphere MQ 命令在队列管理器
WAS_mytest1_MYServer上创建示例队列SmQueueSub:strmqm WAS_mytest1_MYServer runmqsc WAS_mytest1_MYServer < sm_mq.mqsc end endmqm WAS_mytest1_MYServer
其中文件sm_mq.mqsc的内容为:********************************************************************/ * */ * SM Subscriber Queue */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SmQueueSub) REPLACE + DESCR(Subscription Manager Subscriber Queue) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000)
- 在 WebSphere MQ 中,在 WebSphere MQ 队列管理器中创建内部 JMS 发布/订阅队列,以进行 JMS 发布/订阅消息传递。下面的 WebSphere MQ 命令为示例队列管理器
WAS_mytest1_MYServer创建内部 JMS 发布/订阅队列:strmqm WAS_mytest1_MYServer runmqsc WAS_mytest1_MYServer < mq_jms.mqsc end endmqm WAS_mytest1_MYServer
其中文件mq_jms.mqsc的内容为:********************************************************************/ * */ * JMS Publish/Subscribe Administration Queue */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.ADMIN.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - admin queue) + * Persistent messages OK DEFPSIST(YES) + * Non-Shareable NOSHARE ********************************************************************/ * */ * JMS Publish/Subscribe Subscriber Status Queue */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.PS.STATUS.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - PS status queue) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) ********************************************************************/ * */ * JMS Publish/Subscribe Report Queue */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.REPORT.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - Report queue) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) ********************************************************************/ * */ * JMS Publish/Subscribe Subscribers Model Queue */ * */ * Create model queue used by subscribers to create a permanent */ * queue for subsciptions */ * */ ********************************************************************/ * General reply queue */ DEFINE QMODEL(SYSTEM.JMS.MODEL.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - Model queue) + * Queue Definition Type DEFTYPE(PERMDYN) + * Shareable SHARE DEFSOPT(SHARED) ********************************************************************/ * */ * JMS Publish/Subscribe Default Non-Durable Shared Queue */ * */ * Create local queue used as the default shared queue by */ * non-durable subscribers */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.ND.SUBSCRIBER.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - PS ND shared queue) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000) ********************************************************************/ * */ * JMS Publish/Subscribe Default Non-Durable Shared Queue for */ * ConnectionConsumer functionality */ * */ * Create local queue used as the default shared queue by */ * non-durable connection consumers */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.ND.CC.SUBSCRIBER.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - PS ND CC shared q) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000) ********************************************************************/ * */ * JMS Publish/Subscribe Default Durable Shared Queue */ * */ * Create local queue used as the default shared queue by durable */ * subscribers */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.D.SUBSCRIBER.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - PS D shared queue) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000) ********************************************************************/ * */ * JMS Publish/Subscribe Default Durable Shared Queue for */ * ConnectionConsumer functionality */ * */ * Create local queue used as the default shared queue by durable */ * connection consumers */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.JMS.D.CC.SUBSCRIBER.QUEUE) REPLACE + DESCR(Websphere MQ - JMS Classes - PS D CC shared q) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000) ********************************************************************/ * */ * WAS Subscription Manager Publication Queue */ * */ ********************************************************************/ ** Create a local queue DEFINE QLOCAL(SYSTEM.BROKER.DEFAULT.STREAM) REPLACE + DESCR(Websphere MQ - Broker Deafult Stream) + * Persistent messages OK DEFPSIST(YES) + * Shareable SHARE DEFSOPT(SHARED) + * Maximum queue depth MAXDEPTH(100000)
- 在 BI Message Broker 工具包中,创建消息流 (
MYPubSub.msgflow) 以处理发布消息。然后将消息流保存到一个称为 BAR (Broker Archive) 文件的文件中。在部署消息流时使用该 BAR 文件。下面是一个简单的消息流示例,一旦部署了该消息流,就允许代理接收输入发布消息以及将其传送到对特定主题感兴趣的订户。该简单消息流示例包括一个 MQ 输入节点
SmPublication和一个发布节点SmPublishResults。MQInputNode 允许代理使用缺省的代理队列SYSTEM.BROKER.DEFAULT.STREAM来接受发布消息。发布节点允许代理将消息传送到对该主题感兴趣的订户。
图 15. Message Broker 工具包
创建消息流后,要确保启动队列管理器和代理,然后将消息流部署到该代理,以便允许此代理处理发布消息。下面的 BI Message Broker 命令将一个消息流部署到示例代理
MYBroker1中:strmqm WAS_mytest1_MYServer mqsistart MYBroker1 mqsideploy -b MYBroker1 -e <execution_group_name> -bar <broker_archive_file_name>
其中:
- <execution_group_name> 是部署到的代理执行组的名称
- <broker_archive_file_name> 是在创建消息流的步骤中创建的 BAR 文件的名称
有关部署消息流的详细信息,请参阅 WebSphere Business Integration Message Broker 文档。
- 完成这些任务后,启动 WebSphere MQ、BI Message Broker 和 Application Server,然后在管理控制台部署并启动 JMS J2EE 应用程序,以验证该应用程序。
本文介绍了如何使用嵌入式 JMS 提供程序或 MQ JMS 提供程序以让应用程序能够运行在 Application Server V5 上,作为一个 JMS 应用程序开发人员或管理员,您需要了解这些。文中描述了如何安装这两种 JMS 提供程序、如何为 JMS 应用程序配置 JMS 资源和侦听器端口,以及如何验证配置设置。还提供了使用 MQ JMS 提供程序时所需的 WebSphere MQ 和 BI Message Broker 命令以及设置代码。
- 您可以参阅本文在 developerWorks 全球站点上的 英文原文。
- 有关 WebSphere Application Server V5 的详细信息,请参阅 WebSphere Application Server InfoCenter。
- 有关 WebSphere MQ 的详细信息,请参阅 MQ library。
- 有关 WebSphere Event Broker 的详细信息,请参阅 Event Broker MQ library。
- 有关 WebSphere BI Message Broker 的详细信息,请参阅 BI Message Broker library。
-
developerWorks Wireless with WebSphere 专区。请参看 Wireless with WebSphere 的“How to”文章、下载、教程、培训资料和产品信息等等。
-
Developer Bookstore。数百种供开发人员使用的技术书籍,最多可获得 35% 的零售折扣,其中有许多是关于
WebSphere Application Server 产品的。
-
WebSphere 论坛。特定于产品的论坛,可以在这里提出您的问题并与其他 WebSphere 用户分享您的观点。
-
developerWorks 博客。软件专家提供的各种形式的专栏,实时动态更新,您可以在其中添加您个人的评论。欢迎访问 Grady Booch 关于软件体系结构和软件工程的博客。
