10.2 ActiveMQ如何在代理网络间传送消息
10.2 How ActiveMQ passes messages across a network of brokers
10.2 ActiveMQ如何在代理网络间传送消息
?
ActiveMQ supports the concept of linking ActiveMQ message brokers together into
different topologies, or networks of brokers as they’re known. Often it’s a requirement
that geographically dispersed applications need to communicate in a reliable way.
?
ActiveMQ支持将ActiveMQ消息代理链接起来组成不同的拓扑结构,或者组成彼此互通的代理网络.
通常,地理上分散的应用程序彼此间进行可靠的通信是一个需求.
?
This is a situation where having a centralized broker architecture into which all the clients
connect isn’t the optimal messaging paradigm.
存在这样的情况,即,让所有客户端都连接到一个中心代理,而这不是使用消息系统最理想的示例.
?
Through the rest of this section, the ActiveMQ store and forward concept will be
examined in detail. We’ll look at how brokers discover each other in a network and
how to configure an ActiveMQ broker to cooperate in a network.
?
本节的剩余部分将探讨ActiveMQ消息的存储和转发概念的相关细节.我们将看到网络中代理之间
如何发现彼此,以及如何配置一个相互协作的ActiveMQ代理网络.
?
10.2.1 Store and forward
10.2.1 消息存储和转发
?
ActiveMQ networks ?use the ?concept of ?store and ?forward, whereby messages are
always stored in the local broker ?before being forwarded across the network ?to
another ?broker. ?This ?means ?that ?if ?messages ?can’t ?be ?delivered ?due to
connectivity issues, when the connection is reestablished, a broker will be able
to send ?any undelivered ?messages across ?the network ?connection to the remote
broker. ?By default, ?a network ?only operates ?in a ?unidirectional manner ?and
logically pushes ?messages across ?its network ?connection, as ?shown in ?figure
10.4.
?
ActiveMQ代理网络使用存储和转发的概念,即,消息通常被存储在本地代理中,然后才通过网络
转发到其他代理.这就是说,如果因为网络连接问题导致消息不能被及时投送,那么当网络连接
恢复并重建后,代理可以重新发送任何未及时投送的消息到远程代理上.默认情况下,如图10.4
所示,一个消息网络仅以单向方式在通过逻辑上的网络中推送消息.
?
When a network is established from a local broker to a remote broker, the remote
broker will pass information containing all its durable and active consumers’ destinations
to the local broker. The local broker uses this information to determine what
messages the remote broker is interested in and forward them to the remote broker.
It’s possible to define filters on the network connection and to always include or
exclude messages for a particular destination—we’ll cover this in the configuration
section later in this chapter.
?
当本地代理和远程代理之间的网络连接建立之后,远程代理会将其所有消息持久化信息和消息消费者
的消息目的地等相关信息发送给本地代理.本地代理根据这些信息决定那些消息是远程代理感兴趣的
并且将这些消息转发到远程代理.
?
Having networks operate in one direction allows for networks to be configured for
message passing in a one-way fashion. If you want networks to be bidirectional, you
can either configure the remote broker with a network connector to point to the local
broker, or configure a network connector to be duplex so it sends messages in both
directions.
?
单向网络操作允许将网络中消息传递配置成单向的.如果你需要双向网络,你可以配置远程代理使用一个连接到
本地代理的网络连接器,或者给本地代理配置一个双向网络连接器这样本地网络可以向两个方向发送消息.
?
Suppose you have a deployment scenario where you have many supermarkets that
need to connect to a back office order system. It would be hard to configure new
supermarkets and inflexible for the broker(s) at the back office to be aware of all the
remote brokers in each new supermarket. Typically the back office brokers would be
located behind a firewall with only a limited number of ports open to accept connections
inward, as depicted in figure 10.5.
?
设想这样一个部署场景:您有许多超市需要连接到后台订单系统。 这种场景下,配置一个新的超市将会比较困难,并且
让后台订单系统的代理感知所有新增超市的远程代理也变得很不灵活.通常后台系统的代理会受到防火墙保护,并且
只在开放的几个端口上接收连接,如图10.5所示.
?
The diagram of the supermarket broker in figure 10.5 requires that the network connector
be configured in duplex mode. The single network connection, established
from the supermarket broker to the back office, would be able to pass messages in
both directions and would behave in the same way as if the back office broker had
established a normal network connection back to the supermarket broker.
?
图10.5中,超市代理要求将网络连接器配制成双向模式.这样,超市代理到后台的单一网络连接就可以从两个方向
传递消息,就相当于后台代理建立了一个连接到超市代理的正常的网络连接.
?
The configuration for the supermarket broker would include configuration for the
network connector that would look something like the following.
超市代理的配置需要包含网络连接器配置,如下代码片段所示:
?
Listing 10.1 Configuring a store network broker
代码清单10.1?
?
<networkConnectors>
<networkConnector?
uri="static://(tcp://backoffice:61617)" ?
name="bridge"
duplex="true" <!-- 这样远程代理也建立和本地代理的连接 -->
conduitSubscriptions="true"
decreaseNetworkConsumerPriority="false">
</networkConnector>
</networkConnectors>
?
Please be aware that the order in which you specify the network connections and the
persistence you use in the ActiveMQ broker configuration is important. Always configure
networks, persistence, and transports in the following order:
?
1 Networks—They need to be established before the message store.
2 Message store—Should be configured before transports.
3 Transports—Should be the last in the broker configuration.
?
请注意,ActiveMQ代理配置中网络连接器和消息持久化配置的顺序很重要.网络连接,消息持久化和连接器
需要按照下面的顺序配置:
1 网络连接 -- 网络练剑需要在消息存储之前建立好
2 消息存储 -- 需要在传输连接之前配置
3 传输连接 -- 应当是代理配置后最后配置的
?
?
An example broker configuration in the correct order is shown next.
下面代码清单中显示了一个顺序正确的代理配置文件:
?
Listing 10.2 An example of the correct broker configuration order
代码清单10.2 顺序正确的代理配置示例代码
?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://activemq.apache.org/schema/core">
<broker brokerName="receiver" persistent="true" useJmx="true">
?
<networkConnectors>
<networkConnector uri="static:(tcp://backoffice:61617)"/>
</networkConnectors>
?
<persistenceAdapter>
<kahaDB directory = "activemq-data"/>
</persistenceAdapter>
?
<transportConnectors>
<transportConnector uri="tcp://localhost:62002"/>
</transportConnectors>
?
</broker>
</beans>
?
In large deployment scenarios, it makes sense to combine high availability and network
configurations, as shown in figure 10.6.
?
在大型系统的部署场景中,网络配置和高可用性配置联合起来是有意义的,如图10.6所示.
?
In this scenario, the local master and slave brokers both need to be configured to create
network connections to both the remote master and the slave to cater to the possibility
of the remote master failing. Only when a slave becomes active (becomes the
new master) will it start its transports and network connections.
?
图10.6所示的情况下,本地主机和备机代理都需要配置成既俩节到远程的主机代理又要连接到远程的
备机代理,以便应对远程主机代理失效.只有在备机代理激活(变成新主机代理)后,它才会启动自己的网络
连接和传输连接.
?
If a network can’t establish a connection to a remote broker (as in the case of a
remote slave), or the network connection fails, the network will poll the connection
until it can establish a connection.
?
如果不能建立到远程代理的连接(因为远程代理是一个备机代理),或者网络连接失效,那么
该网络将不断尝试连接,直到它可以建立一个连接。?
?
In this section you’ve seen how store and forward works, as well as message passing
over networks, with an example use case of supermarkets communicating with their
back office systems. In the next section, we’ll look at how brokers in a network discover
each other.
?
本节中,通过一个超市与其后台订单系统之间的通信的例子,你已经看到了消息存储和转发是如何工作的,
同时也看到了消息如何在网络中传送.下一节中,我们见看到同一个网络中的是代理如何侦测到彼此的.
?
10.2.2 Network discovery
10.2.2 网络侦测
?
When a network connection is established to a remote broker, that connection uses a
discovery agent to locate the remote broker and (re-)establish that connection. Two
main types of network discovery are provided with ActiveMQ:
?
1 Dynamic—Searches for brokers using multicast or rendezvous
2 Static—Configured with list of broker URLs with which to establish a connection
?
当尝试与远程代理之间的网络连接时,该链接使用一个侦测工具来定位远程代理以便建立(重建)连接.
ActiveMQ提供两种类型的网络侦测:
1 动态网络 -- 使用多点传送与会合协议
2 静态网络 -- 使用一系列的静态的代理URL来建立连接
?
Using multicast discovery to create network connections is straightforward. When you
start an ActiveMQ broker with a multicast transport on a network connector, it will
search for another broker using IP multicast and establish a connection. A network
configuration for multicast discovery is shown in the following listing.
?
使用多点传送侦测来创建网络连接相当简单.在启动一个网络连接器中配置了多点传送的代理时,
该代理会自动搜索其他使用了IP 多点传送协议的代理并与之建立连接.自动侦测的网络配置如下
代码清单所示:
?
Listing 10.3 A network connector using multicast
<networkConnectors>
<networkConnector uri="multicast://default"/>
</networkConnectors>
?
The default name in the multicast:// URI denotes the group to which the broker
belongs. When using multicast discovery, it’s strongly recommended that you use a
unique group name so that your brokers don’t connect to other application brokers
unbeknownst to you. Not only can this lead to surprising results, but you can spend a
great deal of time chasing a red herring!
?
?multicast:// URI中的default表示该代理所属的群组名称.在使用多点传送侦测时,强烈建议使用唯一的
?群组名称,这样你的代理就不会在你不知道的情况下去连接其他应用程序的代理.尽管这个配置会产生令人惊讶
?的结果,你仍然需要花一些时间去看看与之相关的其他配置.
?
There are a couple of limitations with multicast discovery, including the ability to
control which brokers are discovered, and the fact that it’s usually restricted to the discovery
of brokers on the local network segment. This is because IP multicast doesn’t
extend through routers.
?
使用多点传送侦测也有一些限制,比如对于哪些代理是可侦测的控制能力,以及事实上自动侦测只能侦测到本地网段
中的代理.导致这些问题的原因是基于IP地址的多点传送协议不能穿透路由器.
?
Most of the example configurations used previous to this chapter have used static
discovery for establishing networks. Although they require a little more configuration
and they wouldn’t be suitable for a large number of networks, they’re typically used
for most deployments. Static discovery accepts a list of broker URIs and will try to connect
to the remote brokers in the order they’re determined in the list.
?
本章之前使用的示例配置中都是使用静态侦测方式建立网络连接的.尽管这种配置方式要求更多一点的配置
并且这种静态方式可能不适合大型网络,但是通常大部分部署环境中都使用了这种配置.静态侦测需要一个代理
URL列表,然后根据列表中的顺序尝试连接每一远程代理.
?
For example, to configure the local master broker and the local slave broker to
connect to the remote master, but fail over to the remote slave (see figure 10.6), you’d
configure the local brokers as shown next.
例如,可以使用下面的代码示例,配置本地主机代理和本机备机代理连接到远程主机,并且在远程主机代理失效时
连接到远程备机代理(如图10.6所示).
?
Listing 10.4 An example network connector
?
<networkConnectors>
<networkConnector uri="static:(tcp://remote-master:61617,tcp://remote-slave:61617)"/>
</networkConnectors>
?
The static network discovery agent can be configured to control which frequency it
will try to reestablish a connection with on failure. The configuration properties for
the static transport are shown in table 10.3.
?
可以配置静态网络侦测工具在连接失效后尝试重建连接的频率.静态传输配置的属性如表10.3所示.
?
Table 10.3 Configuration properties for a static transport
表10.3 静态网络连接器可配置的属性
?
Property name ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Default value ? ? ? ? ? ? ? ? ? Description
属性名称默认值描述
?
initialReconnectDelay 1000 The time in milliseconds before attempting to reconnect the network.?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? This is only used if useExponentialBackOff isn’t enabled.
initialReconnectDelay 1000 重新建立连接之前等待的时间(毫秒).只在 ? useExponentialBackOff 没有开启时有效.?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
maxReconnectDelay 30000 The maximum time in milliseconds that the network
will wait before trying to establish a connection
after failure. This is only used if useExponentialBackOff is enabled.
maxReconnectDelay 30000 在网络连接失效后,尝试重新建立连接之前的等待时间.只在useExponentialBackOff启用时有效
?
useExponentialBackOff true If this is enabled, the network will increase the
time to wait between each failed attempt to establish a connection.
useExponentialBackOff true 如果启用该参数,从连接失败到重建连接之间的等待时间将增长(即,本次连接失效与尝试重连之间的等待时间比上次长)
?
backOffMultiplier 2 Used in conjunction with useExponentialBackOff, the multiplier to use to increase the
time to wait between each new attempt to establish a network connection.
backOffMultiplier 2 与useExponentialBackOff联合使用,两次连接失效与重建连接之前 的 等待时间的增量
?
A network connection will always try to establish a connection to a remote broker, so
there’s no concept of just giving up! You can set the configuration options for the static
transport as part of the URI. An example of this is provided in the following listing.
?
网络连接总是在尝试连接到远程代理,因而没有放弃连接的概念.你可以在静态网络连接器的URI中
设置上面的连接参数,将这些参数设置为URI的一部分.下面是这种设置的一个示例:
?
Listing 10.5 An example of configuring the static transport
代码清单10.5 配置静态网络连接器的示例代码
?
<networkConnectors>
<networkConnector uri="static:(tcp://remote:61617)?useExponentialBackOff=false"/>
</networkConnectors>
?
The multicast and the static discovery mechanisms are shown here, along with some
of the trade-offs between them. Many configuration options are available when setting
up networks in ActiveMQ; these will be reviewed in more detail in the next section.
?
以上展示了多点传送侦测和静态侦测机制,以及两者之间的一些权衡.设置ActiveMQ 代理网络时,还有喝多
可以配置的选项,这些选项将在下一节中详细介绍.
?
10.2.3 Network configuration
10.2.3 网络配置
?
Networks by default rely on the remote broker to inform them when the broker ?is
interested ?in ?their ?local ?messages. ?For ?existing ?active ?and ?new message
consumers, ?the ?destination ?to ?which the ?message ?consumer ?is ?listening is
propagated ?to ?the ?local ?broker’s ?network ?connection. ?The ?local ?network
connection ?will ?then ?subscribe ?on behalf ?of ?the ?remote ?broker’s message
consumers for messages to be forwarded across the network. In order for networks
to ? function ?properly ? in ?a ? dynamic ?environment, ? the ?broker ? property
advisorySupport ?needs ?to ?be ?enabled (it’s ?possible ?to ?have ?a statically
configured network without enabling advisories). ActiveMQ uses advisory messages
to communicate state between ?brokers (more on this ?in chapter 14). Because ?of
this, advisory messages are used ?to forward information about changing ?message
consumers across broker networks as well as clients.
?
默认情况下,当远程代理对本地消息感兴趣时,本地代理网络会收到远程代理的通知.已有的活动消息消费者和
新增的消息消费者监听的消息目的地会通过网络连接传递到本地代理.网络中本地代理会代表远程代理订阅
通过网络转发过来的消息.为了使代理网络在动态环境中工作正常,需要开启代理的
advisorySupport属性(可以通过配置静态网络,从而避免开启advisory).ActiveMQ使用advisory
消息来交换传送代理的状态(详情请参阅第14章内容).因此,advisory用于转发代理网络和客户端网络
中消息消费者转换的相关消息.
?
There may not be any active durable subscribers or consumers for an existing destination
on the remote broker. So when the network connection is initialized to the
remote broker, the remote broker will read through its message store for existing destinations
and pass those to the local broker. Then the local broker can forward messages
for those destinations as well.
?
远程代理中,对于已有的的消息目的地来说,也许不存在任何持久化的消息订阅者或消费者.因此,当与远程
代理之间的连接初始化时,远程代理会读取其消息存储中已有的消息目的地然后将其传递给本地代理,只有
本地代理可以为这些消息目的地转发消息.
?
It’s important to note that a network will use the name of the broker to create a
unique durable subscription proxy on behalf of a remote broker. Hence, if at a later
point in time you change the name of the broker, you could lose messages over networks
for durable topic subscribers. To avoid this, make sure to use a unique name for
the brokerName attribute on the <broker> element. See the following for a brief
example.
?
有一点很重要需要注意,即,本地网络会使用代理的名称来为远程代理创建一个唯一的持久订阅代理.
因此,如果修改了代理的名称,你可能会丢失持久化主题订阅者的消息.为避免这个问题,请确保
在broker元素中将brokerName属性值设置成唯一的.
?
请参考下面的简要的示例.
?
Listing 10.6 Make sure to use unique names for the broker
代码清单10.6 确保为代理配置唯一的名称(brokerName属性值唯一)
?
<broker xmlns="http://activemq.apache.org/schema/core"
? ? ? brokerName="brokerA"
? ?dataDirectory="${activemq.base}/data">
...
<networkConnectors>
<networkConnector name="brokerA-to-brokerB" uri="tcp://remotehost:61616" />
</networkConnectors>
</broker>
?
With a basic understanding of how networks operate, you’ll be able to comprehend
some of the side effects if you change the default network configuration. A network
has several important configuration properties, in addition to the duplex property.
理解了网络连接的基本操作只有,你将了解一些修改了默认网络配置后对代理产生的影响.
除了duplex属性,网络配置中还有有一些重要的配置属性.
?
NETWORK PROPERTY: DYNAMICONLY
DYNAMICONLY属性
?
All networks are dynamic only in the sense that they depend on advisories. The
dynamicOnly option configures whether inactive durable subs are networked on a
restart; with dynamicOnly=true, a networked durable sub will not be enabled till it is
again activated. The dynamicOnly property is false by default.
?
只有在网络连接依赖advisory消息时,所有网络都是动态的.dynamicOnly属性用于决定在重启时非
活动的订阅者是否网络化.如果dynamicOnly=true,网络化的订阅者将不会启用,直到它被再次
激活.dynamicOnly的默认值是false.
?
NETWORK PROPERTY: PREFETCHSIZE
PREFETCHSIZE属性
The prefetchSize effects message dispatch to forwarding consumers, but message
acknowledgement always uses INDIVIDUAL_ACK mode on each message receipt. The
default value for this property is 1000.
prefetchSize属性影响消息分发到消息消费者,但是每个消息被接收时消息的确认模式通常使用INDIVIDUAL_ACK模式.
prefetchSize属性默认值为1000.
?
NETWORK PROPERTY: CONDUITSUBSCRIPTIONS
CONDUITSUBSCRIPTIONS属性
An ActiveMQ message broker will send a copy of a message to every interested consumer
of which it’s aware, even across networks. But this can be a problem, as the
remote broker will send every message it receives to any of its interested consumers.
So it’s possible to end up with duplicate messages on the remote broker. The
conduitSubscriptions property is used to inform the network connection that it
should treat multiple matching destinations as a single destination to avoid this problem.
The conduitSubscriptions property is true by default.
ActiveMQ消息代理会将消息副本发送给该代理已感知到的每一个对消息感兴趣的消息消费者,即使这些消息消费者是
跨网络的.但是,这样会产生一个问题,因为远程代理会发送其接收到的所有消息给对消息感兴趣的消费者.
因此,远程代理上可能收到重复的消息(译注:一个消息同时发送给好几个远程代理,而远程代理又将消息复制后发给彼此,
造成重复发送).conduitSubscriptions属性用来通知网络连接使用多目的地消息匹配代替单目的地消息匹配,已避免
消息重复发送问题.conduitSubscriptions默认值为true.
?
NETWORK PROPERTY: EXCLUDEDDESTINATIONS
EXCLUDEDDESTINATIONS属性
You can tell the network to exclude certain destinations from passing messages across
a network. This property can be used, for example, to prevent destinations that
should only be used by local consumers from being propagated to a remote broker.
Excluded destinations are denoted inside of the <excludedDestinations> element as
either a <queue> or a <topic> element. Each one uses a physicalName attribute for
the name of the queue or topic to exclude. You can combine a list of excluded destinations,
and use wildcards to denote the names of the destinations to exclude, too.
可以配置代理,告知代理不要将发往一些消息目的地的消息转发到其他代理.例如,可以使用这个属性
将一个消息目的地限制为仅供本地消费者使用,并阻止将该消息目的地同步到其他远程代理上.
需要排除的消息目的地通过<excludedDestinations>元素配置 <queue>或 <topic>子元素.
每一个<queue>或 <topic>子元素使用一个physicalName配置将要被排除的队列或主题的名称.
你可以使用一个排除消息目的地列表,也可以使用通配符来配置这些被排除的消息目的地的名称.
?
Excluded destinations take priority over both the <staticallyIncludedDestinations> element and
?<dynamicallyIncludedDestinations> element. So if you
have matching destinations in either of those lists, they’ll be excluded. Here’s an example
configuration using the <excludedDestinations> element.
排除的消息目的地的优先级比<staticallyIncludedDestinations>和<dynamicallyIncludedDestinations>?
元素优先级高.一次,如果你在排除列表中包含<staticallyIncludedDestinations>和<dynamicallyIncludedDestinations>
元素中配置的消息目的地,那么这些消息目的地将会被排除.下面是一个使用<excludedDestinations>元素的例子.
?
Listing 10.7 Creating a list of excluded destinations
?
<networkConnectors>
<networkConnector uri="static:(tcp://remote:61617)?useExponentialBackOff=false">
<excludedDestinations>
<queue physicalName="audit.queue-1"/>
<queue physicalName="audit.queue-2"/>
<queue physicalName="local.>"/>
<topic physicalName="local.>"/>
</excludedDestinations>
</networkConnector>
</networkConnectors>
?
NETWORK PROPERTY: DYNAMICALLYINCLUDEDDESTINATIONS
DYNAMICALLYINCLUDEDDESTINATIONS属性
You can ask the network to only pass messages to the remote broker for active message
consumers that match the list of destinations for dynamicallyIncludedDestinations.
The format is the same as the excludedDestinations. An empty list denotes that all
messages will be passed to the remote broker, as long as they’re not in the excluded-
Destinations list.
你可以使用dynamicallyIncludedDestinations属性配置包含消息目的地列表,如果消息目的地在这个列表中
并且有活动的消息消费者时,(与下面的STATICALLYINCLUDEDDESTINATIONS区别,这个属性不管有没有活动的
消息消费者,都转发消息)
网络才会转发这个消息.这个属性的配置格式和excludedDestinations类似.如果这个属性配置的列表为空则
表示所有消息都会发送给远程代理,只要这些消息的目的地不再excludedDestinations属性配置的消息目的地
列表中.
?
NETWORK PROPERTY: STATICALLYINCLUDEDDESTINATIONS
STATICALLYINCLUDEDDESTINATIONS属性
You can ask the network to only pass messages to the remote broker if they match the
list of destinations for staticallyIncludedDestinations. The format is the same as
the excludedDestinations; an example is provided in the following listing.
你可以设置网络中只转发目的地匹配由staticallyIncludedDestinations元素配置的消息目的地列表
的消息.该属性的配置格式和excludedDestinations相同.下面是一个配置示例:
?
Listing 10.8 Setting options for included destinations
?
<networkConnectors>
<networkConnector uri="static:(tcp://remote:61617)?useExponentialBackOff=false">
<staticallyIncludedDestinations>
<queue physicalName="management.queue-1"/>
<queue physicalName="management.queue-2"/>
<queue physicalName="global.>"/>
<topic physicalName="global.>"/>
</staticallyIncludedDestinations>
</networkConnector>
</networkConnectors>
?
NETWORK PROPERTY: DECREASENETWORKCONSUMERPRIORITY
DECREASENETWORKCONSUMERPRIORITY属性
The decreaseNetworkConsumerPriority property influences the algorithm used to
determine which message consumer for a queue should receive the next dispatched
message. When enabled, it’ll give a network consumer the lowest priority, meaning
that messages from a local broker queue will only be sent to a remote broker if there
are no local consumers or they’re all busy. But the decrease in priority depends on the
broker path. For example, if a consumer is two hops away from the broker it will be
given the priority of –7, a consumer one hop away will be given the priority of –5, and
a local consumer will be given priority 0. The decreaseNetworkConsumerPriority
property is false by default.
decreaseNetworkConsumerPriority属性影响决定哪一个消息消费者将要接收下一批消息
的算法.如果启用该参数,网络中消息消费者的优先级被调成最低,这样,只有在不存在本地消息
消费者或者本地消息消费者都处于忙碌状态时,才会将本地队列中的消息发送到远程的消息
消费者.但是,优先级下降的等级受到代理的网络路径的影响.比如,如果一个消息消费者离代理的
网络跳度(从一个网络设备,一般为路由器到另一台 为一跳,即1hop)为2个hop,则该消费者的优先级
为-7,离代理的网络跳度为1个hop时,该消费者的优先级
被设置为-5,并且本地消费者优先级为0.decreaseNetworkConsumerPriority的默认值为false.
?
NETWORK PROPERTY: NETWORKTTL
NETWORKTTL属性
The networkTTL property denotes the maximum number of remote brokers a message
can pass through before being discarded. This is useful for ensuring messages
aren’t forwarded needlessly, if you have a cyclic network of connected brokers. The
default value for the networkTTL property is 1.
networkTTL属性设置消息在被丢弃之前最多可以发送的远程代理的数量.假如你使用的是一个循环代理网络,
这个参数可以避免不必要的消息转发.networkTTL的默认值是1.
?
NETWORK PROPERTY: NAME
NAME属性
The default name for a network connector is bridge. It’s a good idea to give this property
a unique value when the broker is first configured, so it can be found easily
from JMX.
网络连接的默认name属性值为bridge.初次配置时将这个属性设置为一个唯一的值是一个不错的选择,因为这样
通过JMX可以很容易发现.
?
There are cases ?when it makes ?sense to have ?more than one ?network connection
between the same local and remote brokers. In this case, each connector requires
a unique name. So why have more than one network connection between the two same
brokers? ?It comes ?down to ?performance. A ?network connection ?uses a ?single
transport connection, and if you’re anticipating a heavy load across a network,
it makes sense ?to have more ?than one transport ?connection. You do ?need to be
careful ?that you ?don’t get ?duplicate messages, ?so you ?have to ?set up ?the
network connections with the appropriate ?filters. Using one for queues ?and one
for topics ?can often ?improve throughput ?for general ?messaging use ?cases, as
depicted in figure 10.7.
对于同一个本地代理和远程代理来说,很多情况下,在它们之间配置超过一个网络连接是有意义的.
这种情况下,每个连接需要一个唯一的name属性.但是,为什么要在连个代理之间配置多个网络连接?
答案是为了性能考虑.一个网络连接使用单一的网络传输,因而娲你需要处理高负载的网络,那么配置
多个网络传输就有意义了.这是你需要十分消息,以确保不能收到重复的消息,因而你需要小心地为网络
连接设置过滤器.在普通的消息场应用景中,为消息队列配置一个网络,为消息主题配置一个网络可以提
高网络吞吐量.
?
The corresponding configuration for figure 10.7 is shown next.
与图10.7对应的配置文件如下所示:
?
Listing 10.9 Setting options for included destinations
代码清单10.9 设置包含目的地选项(译注:配置图10.7所示的的为同一个网配置两个网络连接,
一个用来传送队列中消息,一个用于传送小子主题中消息)
<networkConnectors>
?
<networkConnector uri="static://(tcp://remotehost:61617)"name="queues_only" duplex="true">
<excludedDestinations>
<topic physicalName=">"/>
</excludedDestinations>
</networkConnector>
?
<networkConnector uri="static://(tcp://remotehost:61617)"name="topics_only"duplex="true">
<excludedDestinations>
<queue physicalName=">"/>
</excludedDestinations>
</networkConnector>
</networkConnectors>
?
Having looked at how networks operate and how to configure them, we can now use
this knowledge to help scale your ActiveMQ applications.
连接网络相关的操作和配置后,可以使用这些知识来帮助扩展基于ActiveMQ的应用程序.
1 楼 leaow567 9 小时前 楼主真是有毅力啊