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

11.6 使用拦截器插件 扩展ActiveMQ代理功能

11.6 Extending functionality with interceptor plug-ins

ActiveMQ provides the ability to supply custom code to supplement broker functionality.To do so requires a good understanding of the ActiveMQ broker internals, which isunfortunately outside the scope of this book. But some ActiveMQ broker interceptorplug-ins are provided with the ActiveMQ distribution; some we’ve already covered,such as the authentication plug-in, in chapter 6. There are some additional miscellaneousplug-ins, and for completeness, it’s worth looking at those now.

11.6 使用拦截器插件 扩展ActiveMQ代理功能

ActiveMQ支持使用第三方代码来扩充代理的功能.为此,需要深入了解ActiveMQ代理的内部机制,很不幸,这已经超出了本书的范围.但是,ActiveMQ版本中自带了一些代理拦截器插件,其中一些我们已经接触过了,比如第6章中的认证插件.为了完整起见,还有一些插件,值得一看.

We’ll start with visualization, which uses two different plug-ins that generate graphicalrepresentations of connections and destinations.

我们从可视化开始,可视化提供两个不同的插件用来生成图像代表连接和消息目的地.

11.6.1 Visualization

Visualization  can be  useful for  identifying usage  patterns for  an ActiveMQbroker. For example, being able to see a diagram of all the connections and  thedestinations  that  they’re consuming  messages  from can  help  identify rogueclients in production environments that have been erroneously consuming messagesfrom the wrong queue.

11.6.1 可视化

可视化可用于识别ActiveMQ代理的使用模式.比如,使用可视化可以通过查看所有连接和该连接接收的消息的消息目的地图表,以便帮助识别生产环境中接收了错误队列消息的非法客户端.

You can use two visualization plug-ins that generate a graph visualization file, whichcontains structural information for viewing structured data. You can use several toolsto visualize the generated files, such as Graphviz (http://www.graphviz.org).

你可以使用两种可视化插件来生成可视化图表文件,该文件包含结构化信息用于展示结构化数据.你可以说哟个集中工具来将生成的文件以图表的形式呈现,例如可以使用Graphviz(http://www.graphviz.org).

Two types  of visualization  plug-ins are  available, one  for connections  (andassociated consumers and producers) called connectionDotFilePlugin, and one  forgenerating a  destination hierarchy  of all  the queues  and topics  used in theActiveMQ  Broker,  called  destinationDotFilePlugin.  When  these  plug-ins  areenabled, they generate a  DOT file on disk.  A DOT file contains  the structuralinformation  in  a directed  graph  notation, suitable  to  be read  by  a graphvisualization tool.

有两个可视化插件可供使用,一个是针对连接的(同样也关联消息消费者和生产者),名称为connectionDotFilePlugin;另一个是用于为ActiveMQ代理中所有队列和主题生成等级结构,名称为destinationDotFilePlugin.当启动这些插件后,它们会生成DOT文件存储到磁盘上.DOT文件包含以直接图片格式存储的结构化信息,这些信息适用于可视化工具.

The  connectionDotFilePlugin  writes information  about  the client  connectionsattached to the ActiveMQ broker  to a DOT file on  disk. By default the file  iswritten into the current directory the  ActiveMQ broker was started from and  iscalled  ActiveMQConnections.dot.  Information  about  each  client   connection,including which  destinations the  client connection  is sending  messages to orreceiving messages from, is also written to the DOT file. Every time there’s  achange  to  a client  connection  (for example,  it  starts or  stops  a messageconsumer), a new  client connection starts,  or an old  one stops, the  DOT filewill be overwritten.

connectionDotFilePlugin插件将客户端连接信息写入磁盘中的DOT文件.默认情况下,该文件被写入到启动ActiveMQ代理的当前目录,文件名为: ActiveMQConnections.dot.每个客户端的连接信息,包括接收客户端发送消息的消息目的,或客户端接收消息的消息目的地等信息也同样被写入到这个DOT文件.每当客户端连接有变化时(比如,客户端启动或停止一个消息消费者),或启动了一个新客户端连接后,或者一个老客户端停止后,这个DOT文件都会被新生成的文件覆盖.

The connectionDotFilePlugin has only one property: the name of the file to writethe state information into, as shown in table 11.2.

connectionDotFilePlugin插件只有一个属性:保存状态信息的DOT文件的名称,如表11.2所示:

Table 11.2 Properties for the connection DOT plug-in

Property name Default value Description
file  ActiveMQDestinations.dot The path name to write state information in DOT format
for connections to the ActiveMQ broker

 表11.2 用于连接的DOT插件属性

属性名称 默认值 描述
 file  ActiveMQDestinations.dot  dot格式文件路径,用来记录到ActiveMQ代理的连接状态信息

The destinationDotFilePlugin is similar to the connectionDotFilePlugin. When thisplug-in is enabled, it will write state information about the current destinations in useby the ActiveMQ broker to a DOT file that’s by default called ActiveMQDestinations.dot. Whenever the state information of destinations changes within the broker, thisDOT file will be updated. An example of the rendered DOT file for the destination-DotFilePlugin is shown in figure 11.2.

destinationDotFilePlugin与connectionDotFilePlugin类似.当启用这个插件后,该插件会记录当前ActiveMQ代理中使用的消息目的地信息到一个DOT文件,默认情况下,该文件名称为:ActiveMQDestinations.dot.当该代理中的消息目的地信息有变化时,该DOT文件就会被更新.一个destinationDotFilePlugin插件生成的已经解析过的DOT文件例子如图11.2所示.

The destinationDotFilePlugin has only one property: the name of file to write thestate information into, as shown in table 11.3.

destinationDotFilePlugin也只有一属性:保存状态信息的DOT文件的名称,如表11.3所示

Table 11.3 Properties for the destination DOT plug-in

Property name Default value Description
file  ActiveMQDestinations.dot The path name to write state information in DOT format
for destinations to the ActiveMQ broker

 表11.3 用于消息目的地可视化的DOT插件属性

属性名称 默认值 描述
 file  ActiveMQDestinations.dot  dot格式文件路径,用来记录ActiveMQ代理目的地状态信息

All ActiveMQ broker plug-ins can be enabled within the configuration file for the broker.Here’s an example of an ActiveMQ broker configuration file which has the connectionDotFilePluginand destinationDotFilePlugin enabled.
Listing 11.3 Configuring visualization plug-ins for the ActiveMQ broker

ActiveMQ代理中所有的插件都可以在代理的配置文件中配置成启用.下面是一个配置ActiveMQ代理的示例配置文件,该配置文件中配置启用了connectionDotFilePlugin和destinationDotFilePlugin插件.
代码情况 11.3 为ActiveMQ代理配置可视化插件

The next plug-in we’ll look at was developed by one of ActiveMQ’s many users toenhance the logging available for the ActiveMQ broker.

下一节我们将看到为增强ActiveMQ代理的日志功能而开发的插件.

11.6.2 Enhanced logging

The logging interceptor (loggingInterceptor), if configured, allows you to log messagesthat are sent or acknowledged on an ActiveMQ broker, in addition to the normallogging done by ActiveMQ. This plug-in can be useful for tracing problems or auditingmessages. A few properties for the logging interceptor can be configured, as shown intable 11.4.

11.6.2 日志功能增强插件

日志插件(loggingInterceptor),如果配置启用的话,除了可以允许使用ActiveMQ常规的日志外,还允许你记录发送到ActiveMQ代理的消息,或者由ActiveMQ代理确认的消息.此插件可用于追踪问题或审计有用消息.日志连接器插件的属性如表11.4所示:

Table 11.4 Properties for the logging interceptor

Property name Default value Description
logAll false Log all the events
logMessageEvents false Log events associated with messages
logConnectionEvents true Log events associated with connections
logConsumerEvents false Log events associated with producers
logProducerEvents false The maximum size of the message journal data files before a new one is used
logInternalEvents false Detailed information of workings of the broker

 表11.4 日志拦截器插件属性

属性名称 默认值 描述
logAll false 是否为所有事件记录日志
logMessageEvents false 是否记录与消息相关的事件日志
logConnectionEvents true 是否记录与连接相关的事件日志
logConsumerEvents false 是否记录与生产者相关的事件日志
logProducerEvents false 单个日志文件的最大尺寸(译注:貌似这个参数名称不对,原书就是这样的)
logInternalEvents false 是否记录代理的所有事务详细日志

11.6.3 Central timestamp messages with the timestamp interceptor plug-in

The timestamp plug-in (timestampingBrokerPlugin), if configured, updates the timestampon messages as they arrive at the broker. This can be useful when there’s a difference(however small) between the system clocks on a computer sending messagesto an ActiveMQ broker and the computer the broker resides on.

11.6.3 中央时间戳消息和时间戳拦截器插件

时间戳插件(timestampingBrokerPlugin),如果启用,会在消息到达代理时更新消息时间戳.当代理所在机器的系统时间和发送消息的机器的时间不同(尽管差别很小)时,这个插件会很有用.

When messages are sent with the timeToLive property set, it’s important thatthe system clocks between the sending machine and the broker are in sync;otherwise messages may get expired erroneously. A few properties for thetimestamp plug-in can be configured, as shown in table 11.5.

当发送一个设置了timeToLive属性的消息时,发送消息的机器和代理所在机器的系统时间的同步非常重要.否则,消息过期判断会产生异常.时间戳插件的可配置属性如表11.5所示:

Table 11.5 Properties for the message timestamp plug-in

Property name Default value Description
zeroExpirationOverride 0 When not zero, will override the expiration date for messages that currently don’t have an expiration set
ttlCeiling 0 When not zero, will limit the expiration time
futureOnly false If true, won’t update the timestamp of messages to past values

 表11.5 消息时间戳插件属性

属性名称 默认值 描述
zeroExpirationOverride 0 配置为非0时,配置的值会被设置成为当前没有配置过期时间的消息的过期时间
ttlCeiling 0 配置为非0时,会限制过期时间
futureOnly false 如果设置为true,将不会更新消息时间戳为一个过去的值

It’s recommend that the timestampingBrokerPlugin be enabled on the ActiveMQ brokerif you’re using the timeToLive property on messages.

The next interceptor plug-in is used for generating messages about managementstatistics for the ActiveMQ broker.

如果使用了消息的timeToLive属性,推荐启用ActiveMQ代理的timestampingBrokerPlugin插件.

下一个拦截器插件用于为ActiveMQ代理生成管理统计数据的消息.

11.6.4 Statistics

The statisticsBrokerPlugin will send MapMessages containing information about thestatistics of the running of the ActiveMQ broker. There are two types of message: onefor destinations and one that gives an overview of the broker itself.

11.6.4 统计插件

statisticsBrokerPlugin插件会发送Map格式的包含ActiveMQ代理的运行时信息的消息.有两种格式的消息:一种是消息目的地相关的,另一种消息包含了代理本身概况.

To retrieve the statistics of the running broker with the statisticsBrokerPluginenabled, send an empty message to the destination (queue or topic—it doesn’t matter)called ActiveMQ.Statistics.Broker. The JMSReplyTo header names the destinationwhere the statistics message is sent.

启用statisticsBrokerPlugin插件后,为了获取运行中的代理的统计信息,需要发送一个空消息到一个命名为ActiveMQ.Statistics.Broker的消息目的地(队列或主题都可以,这个不重要).消息头中的JMSReplyTo字段表明统计消息将要发往的目的地.

Similarly, to retrieve information about a destination, send an empty message tothe name of the destination, prepended with ActiveMQ.Statistics.Destination. For example,to retrieve statistics for the destination Topic.Foo, send a message to the destinationActiveMQ.Statistics.DestinationTopic.Foo.

类似地,为了获取消息目的地相关的统计信息,需要发送一个空消息到已ActiveMQ.Statistics.Destination作为前缀的消息目的地.例如,为了获取消息目的地Topic.Foo的统计信息,需要发送一个空消息到以ActiveMQ.Statistics.DestinationTopic.Foo命名的目的地

You enable an ActiveMQ broker plug-in by including it in the broker configurationfile, as shown:
Listing 11.4 Configuring plugins for the broker

可以使用如下代码中的配置方式启用ActiveMQ代理插件:
代码清单11.4 为代理配置插件

Broker interceptors are a useful addition for extending the functionality of ActiveMQ.But you can provide more features and flexibility by embedding Apache Camel, thepowerful integration framework, in the ActiveMQ broker. We’ll look at Apache Camelintegration next.

代理拦截器是有用的扩展,可以扩充ActiveMQ代理的功能.但是,你可以使用嵌入的功能强大的集成插件Apache Camel为ActiveMQ代理提供更多的功能和灵活性.下面我们将看到如何集成Apache Camel到ActiveMQ代理中.

打个赏呗

   微信打赏  支付宝打赏


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

该日志由 边城网事 于2013年12月18日发表在 ActiveMQ in Action 读书笔记 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 11.6 使用拦截器插件 扩展ActiveMQ代理功能 | 边城网事

11.6 使用拦截器插件 扩展ActiveMQ代理功能 暂无评论

发表评论

快捷键:Ctrl+Enter