activemq 实战三 了解连接器的URI-Understanding connector URIs

Before discussing the details of connectors and their role in the overall ActiveMQ

architecture, it’s important to understand connector URIs. Uniform resource identifiers

(URIs), as a concept, aren’t new, and you’ve probably used them over and over again

without realizing it. URIs were first introduced for addressing resources on the World

Wide Web. The specification (http://mng.bz/8iPP) defines the URI as “a compact

string of characters for identifying an abstract or physical resource.” Because of the

simplicity and flexibility of the URI concept, they found their place in numerous internet

services. Web URLs and email addresses we use every day are just some common

examples of URIs in practice.

在详细介绍连接器及其在整个ActiveMQ体系中所扮演的角色之前,弄清URI的概念是非常重要的.

统一资源标识符(URI)不是一个新的概念,你可能已经用过他们好多次了,只是你还没有意识到.

URI首先在WWW网中用来定义资源.URI规范(参加http://mng.bz/8iPP)中对RUI的定义:

一串用于定位抽象资源或物理资源的紧凑字符.URI因其简单和灵活,而被广泛用于各种各样的因特网服务中.

我们天天使用的web地址和email地址就是URI的普通列子.

Without going too deep into discussing URIs, let’s briefly summarize the URI structure.

This will serve as an ideal introduction to URI usage in ActiveMQ in regard to

connectors.

Basically, every URI has the following string format:

<scheme>:<scheme-specific-part>

这里不打算深入讨论URI,而是简要介绍URI的结构,这将成为阐明URI在ActiveMQ连接器(connector)中用处的理想方法.

通常,每个URI都有如下结构:

<协议>:<协议-细节-部分>

Consider the following URI:

mailto:users@activemq.apache.org

Note that the mailto scheme is used, followed by an email address to uniquely identify

both the service we’re going to use and the particular resource within that service.

The most common form of URIs are hierarchical URIs, which take the following

form:

<scheme>://<authority><path><?query>

This kind of URI is used by web browsers to identify websites. It’s a type of URI known

as a URL (Uniform Resource Locator).

请看如下URI示例:

mailto:users@activemq.apache.org

注意,这个URI使用了mailto协议(mailto后面是是email地址),该协议既说明了我们使用的服务同时也指定了

该服务中所需的特定的资源.

格式:

<协议>://<授权认证><路径><?查询字符串>

这种URI是web浏览器使用的.它是URI的一种,即我们常说的URL(统一资源定位器).

Below is an example:

This URL uses the http scheme and contains both path and query elements which are

used to specify additional parameters.

Because of their flexibility and simplicity, URIs are used in ActiveMQ to address specific

brokers through different types of connectors. If we go back to the examples discussed

in chapter 3, you can see that the following URI was used to create a

connection to the broker:

tcp://localhost:61616

This is a typical hierarchical URI used in ActiveMQ, which translates to “create a TCP

connection to the localhost on port 61616.”

ActiveMQ connectors using this kind of simple hierarchical URI pattern are sometimes

referred to as low-level connectors and are used to implement basic network communication

protocols. Connector URIs use the scheme part to identify the underlying

network protocol, the path element to identify a network resource (usually host and

port), and the query element to specify additional configuration parameters for the

connector. The anatomy of a URI is shown in figure4.1.

下面是一个例子:

这个URL使用http协议,包含路径元素(path)和查询字符串元素(query),其中查询字符串元素用来指定额外的参数.

因为简单灵活,ActiveMQ通过不同的连接器(connector)使用URI来标识给定的代理(broker).回到第三章中导论的

例子,你可以但看到下面的URI创建了一个连接到代理的连接.:

tcp://localhost:61616

tcp://localhost:61616?trace=true

scheme path query

Figure 4.1 Anatomy of a URI

This URI extends the previous example by also telling the broker to log all commands

sent over this connector (the trace=true part).

This is just one example of an option that’s available on the TCP transport.

这个URI是上面的例子的扩展,通过传递一个参数(trace=true部分)

告知代理(broker)需要给所有通过连接器(connector)执行的命令记录日志.

The failover transport in ActiveMQ supports automatic reconnection as well as the

ability to connect to another broker just in case the broker to which a client is currently

connected becomes unavailable. As will be discussed in chapter 10, ActiveMQ makes

this easy to use and configure through the use of composite URIs. These composite URIs

are used to configure such automatic reconnection. In figure 4.2, you can see an example

of a typical composite URI.

static:(tcp://host1:61616,tcp://host2:61616)

scheme   path1             path2

ActiveMQ提供一种失效自动转移的传输连接器.如果当前客户端与代理(broker)之间的连接变得不可用,

这种连接器支持自动重新建立连接,或者自动连接到其他的代理(broker).正如你将在第十章中看到的,

ActiveMQ使用一种复合URI,因而这种失效自动转移的传输连接器的使用和配置都很简答.这种复合URI正是

用了配置这种自动重连的. 图4.2是一个复合URI的一个典型实例.

Note that the scheme part or the URI now identifies the protocol being used (the

static protocol will be described later in this chapter) and the scheme-specific part

contains one or more low-level URIs that will be used to create a connection. Of

course, every low-level URI and the larger composite URI can contain the query part

providing specific configuration options for the particular connector.

注意,URI的协议部分(scheme)指定了使用的协议(本章稍后将讨论static协议),协议说明部分通常包含

1个或多个次级URI(low-level URIs)用来创建连接.

(译注: 比如static:(tcp://host1:61616,tcp://host2:61616)中,static是协议部分,

tcp://host1:61616,tcp://host2:61616是两个次级URI用来创建连接)

NOTE Since composite URIs tend to be complex, users are often tempted to

insert white spaces to make them more readable. Such white space is not

allowed, since the URI specification (and its standard Java implementation)

doesn’t allow it. This is a common ActiveMQ configuration mistake, so be

careful not to put white space in your URIs.

注意: 因为复合RUI通常比较复杂,用户经常会插入一些空格是的符合URI可读性更好些.但是,

这些空格是不合法的,因为URI规范(以及该规范的Java实现)不允许URI中的非法空格.

这是在配置ActiveMQ时的一个常见错误,所以在配置时需要十分小心,不要在URI中添加不必要的空格.

Now that you have some familiarity with ActiveMQ URI basics, let’s move on to discuss

various connectors supported by ActiveMQ. In the rest of this chapter, we’ll discuss

transport connectors and network connectors and how to configure them.

现在,你应该对ActiveMQ URI的基础知识有些熟悉了,

让我们开始讨论ActiveMQ支持的各种连接器.在本章的剩余部分,我们将讨论传输连接器(transport connector)

和网络连接器(network connector)以及如何配置他们.

原文地址:https://www.cnblogs.com/yudar/p/4635186.html