当前位置: 首页 > ActiveMQ in Action 读书笔记 > 正文

8 ActiveMQ 与服务器程序的整合

 8 Integrating ActiveMQ with application servers

This chapter covers
 Integrating ActiveMQ with Apache Tomcat
 Integrating ActiveMQ with Jetty
 Integrating ActiveMQ with Apache Geronimo
 Integrating ActiveMQ with JBoss
 Understanding ActiveMQ and JNDI

 8 ActiveMQ与服务器程序的整合

本章内容包括
ActiveMQ 与Apache Tomcat整合
ActiveMQ 与Jetty整合
ActiveMQ 与Apache Geronimo
ActiveMQ 与JBoss整合
理解ActiveMQ和JNDI

Up to this point,  most of the examples  in the book have  utilized a standaloneinstance of ActiveMQ:  ActiveMQ was started  up in its  own JVM. Then  chapter 7demonstrated  multiple  ways  to  embed  ActiveMQ  inside  a  Java  application,including the use of the ActiveMQ Java APIs as well as using a Spring  FrameworkXML configuration.  This style  of integration  is common,  but the  aim of thischapter is different. The goal of this  chapter is to demonstrate the use of  anapplication server’s features tegrating third-party middleware.

到目前为止,本书中的大部分例子里面使用的都是独立的ActiveMQ实例,即ActiveMQ是在它自己独立的虚拟机中启动.第7章中阐述了多种嵌入方法将ActiveMQ嵌入到Java程序中,这些方法包括使用ActiveMQ的Java API和使用Spring 框架的XML配置文件.这是集成ActiveMQ的的普通方法,而本章的目标与此不同,本章内容旨在演示如何使用第三方中间件的应用程序服务器功能.

The term application server is overloaded, but in the most general sense, applicationservers provide a container architecture that accepts the deployment of anapplication and provides an environment in which it can run. This chapter focuseson Java application servers, of which there are two types. The first type of applicationserver implements the Java Servlet specification (http://mng.bz/cmMj) and is knownas a web container. Apache Tomcat and Jetty both fall into the category of web containers.The second type of application server implements the Java EE family of specifications(http://mng.bz/NTSk) and is known as a Java EE container. Apache Geronimoand JBoss both fall into the category of Java EE containers. We chose these four applicationservers for this chapter because they’re popular and freely available. ActiveMQcan also be integrated with commercial application servers such as WebLogic andWebSphere using the same strategies used in this chapter.

应用程序服务器范围很大,而通常意义上,应用程序服务器提供一个容器结构并可以将应用程序部署到其中且提供应用程序的运行环境.本章关注两种类型的Java应用程序服务器.第一种应用程序服务器实现了Java Servlet规范(http://mng.bz/cmMj),即web容器,如Apache Tomcat和Jetty.第二种应用程序服务器实现了Java EE规范族群(http://mng.bz/NTSk),即Java EE容器,如Apache Geronimo和JBoss.本章选择这四种应用程序服务器做介绍是因为它们易于获得并且是免费的.利用本章介绍的方法还可以将ActiveMQ与诸如ActiveMQ和WebSphere这样的商用应用程序服务器进行整合.

When deploying ActiveMQ to an application server, two major tasks need to becompleted—starting the broker and providing access to the JMS destinations. Thereare different approaches to solving both of these problems. One option to handleboth tasks is to use the Spring Framework. The strategy used in chapter 7 demonstratedthat Spring can be used to start ActiveMQ and to provide access to the JMS destinations.But since we already demonstrated that approach, a different approach willbe used this chapter.

将ActiveMQ于应用服务器进行整合需要完成两个任务–启动代理和提供访问JMS消息目的地的方法.完成正两个任务的方法都是多种多样的.使用Spring框架就是完成这两个任务的一个方法.第7章中展示了使用Spring框架可以启动ActiveMQ并且提供了访问JMS消息目的地的方法.因为已经介绍过这种方法了,本章将介绍一种不同的方法.

ActiveMQ provides a unique  feature that allows a  broker to be created  via theActiveMQ  JMS connection  factory. By  creating an  ActiveMQ connection  factoryusing a URI for a broker that doesn’t yet exist, the JMS connection will  createan instance  of the  broker. So  this means  that the  creation of the broker isdependent upon the  ability to create  the ActiveMQ connection.  JMS connectionsare created  from a  connection factory  that’s registered  with the applicationserver. For this purpose, Java  application servers provide a JNDI  (Java Namingand Directory Interface) implementation that can be used to expose objects to beused by applications  deployed to the  container. Objects such  as JDBC drivers,JMS  resources, transaction  managers, and  so forth  can be  configured to  beaccessed using the JNDI API. This is the approach that will be used with the webcontainers.

ActiveMQ提供一种独特的功能,允许使用ActiveMQ  JMS的连接工厂来创建代理.使用一个尚未创建的代理的URI来创建一个ActiveMQ连接工厂后,创建的JMS连接将创建一个代理实例.因而,创建代理取决于创建ActiveMQ连接.JMS连接可以使用在应用程序服务器中注册过的连接工厂来创建.因此,Java应用程序服务器实现了JNDI(Java命名和目录接口)规范以便将一些对象暴露给部署在容器中的应用程序.这些可暴露的对象包括JDBC驱动,JMS资源,事务管理器等.通过配置应用程序服务器,使得容器中部署的应用程序能够使用JNDI访问这些对象.

Both Apache Tomcat and Jetty  support two different styles of  configuration forobjects in JNDI:  local JNDI and  global JNDI. Local  JNDI is used  to configureobjects that will only be exposed to a specific application, whereas global JNDIis used to expose objects to any application in the entire web container.  We’lluse each  style of  JNDI configuration  to demonstrate  the creation  of the JMSresources. To situate these differences in JNDI configuration and to demonstratethe use  of each  in Tomcat  and Jetty,  there are  two different flavors of thesample web application. These are available  in the example source code and  arenamed jms-webapp-local  and jms-webapp-global.  Both Apache  Geronimo and  JBosssupport JNDI,  but this  will only  be used  to register  the JMS resources.

 Apache Tomcat和Jetty都支持配置两种类型的JNDI:本地JNDI和全局JNDI.本地JNDI用来配置只能指定程序使用的JNDI对象,而全局JNDI用于配置供整个容器中所有应用程序使用的JNDI对象. 我们将使用这两种方式配置JNDI以演示如何配置JMS资源.为了说明两种JNDI配置的区别以及演示如何在 Tomcat和Jetty中用这两种方式配置JNDI,我们使用了两种不同风格的web示例程序.你可以在示例程序源码中找到这两个程序,它们的名称为jms-webapp-local和jms-webapp-global.Apache  Geronimo 和JBoss都支持JNDI,但这里JNDI仅用于注册JMS资源.

The ActiveMQ broker won’t be started by  the creation of a JMS connection.  To startup the ActiveMQ broker  and integrate it with  Geronimo and JBoss, this  chapterwill  utilize  a  J2EE  Connector  Architecture  (http://mng.bz/fXU9)   resourceadapter, also  known as  JCA. To  situate the  difference in integration detailsbetween the two Java EE containers  reviewed here, two different flavors of  thesample web application are  available in the example  source code and are  namedjmswebapp- geronimo and jms-webapp-jboss.

创建JMS连接后并不会启动ActiveMQ代理.为了启动ActiveMQ代理并结成到Geronimo和JBoss中本章将使用JCA(J2EE  Connector  Architecture,http://mng.bz/fXU9)资源适配器.为了展示将ActiveMQ JMS集成到Java EE容器的不同点,我们也使用了两种风格的web示例程序.你同样可以在示例程序源码中找到这两个程序,它们的名称为jmswebapp- geronimo和jms-webapp-jboss.

Although four sample web application projects are used in this chapter, the coreof each application is exactly the same. The reason why there are four copies ofthe same application is to  support the different deployment styles  being used.Before proceeding with the actual integrations, it’s a good idea to take a  highlevel look at the sample web application.

虽然本章使用了4个web实例程序,然而他们的核心逻辑都是相同的.之所以使用4个核心逻辑相同的应用,是为了支持不同风格的应用程序部署方式.在进行集成配置之前,先来大体上了解一下示例中的web程序是个不错的主意.

打个赏呗

   微信打赏  支付宝打赏


本文固定链接: https://www.jack-yin.com/coding/translation/activemq-in-action/1583.html | 边城网事

该日志由 边城网事 于2013年11月14日发表在 ActiveMQ in Action 读书笔记 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 8 ActiveMQ 与服务器程序的整合 | 边城网事

8 ActiveMQ 与服务器程序的整合 暂无评论

发表评论

快捷键:Ctrl+Enter