首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

八 ActiveMQ与服务器程序的整合

2013-11-18 
8 ActiveMQ与服务器程序的整合8 Integrating ActiveMQ with application servers8 ActiveMQ与服务器程序的

8 ActiveMQ与服务器程序的整合

8 Integrating ActiveMQ with application servers

8 ActiveMQ与服务器程序的整合

?

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

?

本章内容包括

? ? 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 standalone

instance of ActiveMQ: ?ActiveMQ was started ?up in its ?own JVM. Then ?chapter 7

demonstrated ?multiple ?ways ?to ?embed ?ActiveMQ ?inside ?a ?Java ?application,

including the use of the ActiveMQ Java APIs as well as using a Spring ?Framework

XML configuration. ?This style ?of integration ?is common, ?but the ?aim of this

chapter is different. The goal of this ?chapter is to demonstrate the use of ?an

application 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, application

servers provide a container architecture that accepts the deployment of an

application and provides an environment in which it can run. This chapter focuses

on Java application servers, of which there are two types. The first type of application

server implements the Java Servlet specification (http://mng.bz/cmMj) and is known

as 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 Geronimo

and JBoss both fall into the category of Java EE containers. We chose these four application

servers for this chapter because they’re popular and freely available. ActiveMQ

can also be integrated with commercial application servers such as WebLogic and

WebSphere 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 be

completed—starting the broker and providing access to the JMS destinations. There

are different approaches to solving both of these problems. One option to handle

both tasks is to use the Spring Framework. The strategy used in chapter 7 demonstrated

that 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 will

be used this chapter.

?

将ActiveMQ于应用服务器进行整合需要完成两个任务--启动代理和提供访问JMS消息目的地的方法.

完成正两个任务的方法都是多种多样的.使用Spring框架就是完成这两个任务的一个方法.第7章中

展示了使用Spring框架可以启动ActiveMQ并且提供了访问JMS消息目的地的方法.因为已经介绍过

这种方法了,本章将介绍一种不同的方法.

?

ActiveMQ provides a unique ?feature that allows a ?broker to be created ?via the

ActiveMQ ?JMS connection ?factory. By ?creating an ?ActiveMQ connection ?factory

using a URI for a broker that doesn’t yet exist, the JMS connection will ?create

an instance ?of the ?broker. So ?this means ?that the ?creation of the broker is

dependent upon the ?ability to create ?the ActiveMQ connection. ?JMS connections

are created ?from a ?connection factory ?that’s registered ?with the application

server. For this purpose, Java ?application servers provide a JNDI ?(Java Naming

and Directory Interface) implementation that can be used to expose objects to be

used by applications ?deployed to the ?container. Objects such ?as JDBC drivers,

JMS ?resources, transaction ?managers, and ?so forth ?can be ?configured to ?be

accessed using the JNDI API. This is the approach that will be used with the web

containers.

?

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 for

objects in JNDI: ?local JNDI and ?global JNDI. Local ?JNDI is used ?to configure

objects that will only be exposed to a specific application, whereas global JNDI

is used to expose objects to any application in the entire web container. ?We’ll

use each ?style of ?JNDI configuration ?to demonstrate ?the creation ?of the JMS

resources. To situate these differences in JNDI configuration and to demonstrate

the use ?of each ?in Tomcat ?and Jetty, ?there are ?two different flavors of the

sample web application. These are available ?in the example source code and ?are

named jms-webapp-local ?and jms-webapp-global. ?Both Apache ?Geronimo and ?JBoss

support 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 start

up the ActiveMQ broker ?and integrate it with ?Geronimo and JBoss, this ?chapter

will ?utilize ?a ?J2EE ?Connector ?Architecture ?(http://mng.bz/fXU9) ? resource

adapter, also ?known as ?JCA. To ?situate the ?difference in integration details

between the two Java EE containers ?reviewed here, two different flavors of ?the

sample web application are ?available in the example ?source code and are ?named

jmswebapp- 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 core

of each application is exactly the same. The reason why there are four copies of

the 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 ?high

level look at the sample web application.

?

虽然本章使用了4个web实例程序,然而他们的核心逻辑都是相同的.之所以使用4个核心逻辑相同的

应用,是为了支持不同风格的应用程序部署方式.在进行集成配置之前,先来大体上了解一下示例

中的web程序是个不错的主意.

热点排行