activemq-artemis/docs/user-manual/zh/intercepting-operations.xml

72 lines
4.0 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================================= -->
<!-- Copyright © 2009 Red Hat, Inc. and others. -->
<!-- -->
<!-- The text of and illustrations in this document are licensed by Red Hat under -->
<!-- a Creative Commons AttributionShare Alike 3.0 Unported license ("CC-BY-SA"). -->
<!-- -->
<!-- An explanation of CC-BY-SA is available at -->
<!-- -->
<!-- http://creativecommons.org/licenses/by-sa/3.0/. -->
<!-- -->
<!-- In accordance with CC-BY-SA, if you distribute this document or an adaptation -->
<!-- of it, you must provide the URL for the original version. -->
<!-- -->
<!-- Red Hat, as the licensor of this document, waives the right to enforce, -->
<!-- and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent -->
<!-- permitted by applicable law. -->
<!-- ============================================================================= -->
<chapter id="intercepting-operations">
<title>拦截操作</title>
<para>ActiveMQ支持<emphasis>拦截器</emphasis>。拦截器可以拦截进入服务器的数据包。每进入服务器
一个数据包,拦截器就被调用一次,允许一些特殊和处理,例如对包的审计、过滤等。拦截器可以对数据包
进行改动。</para>
<section>
<title>实现拦截器</title>
<para>拦截器必须要实现<literal>Interceptor接口</literal></para>
<programlisting>
package org.apache.activemq.api.core.interceptor;
public interface Interceptor
{
boolean intercept(Packet packet, RemotingConnection connection)
throws ActiveMQException;
}
</programlisting>
<para>它的方法的返回值是很重要的:</para>
<itemizedlist>
<listitem>
<para>如果返回<literal>true</literal>,处理正常进行下去。</para>
</listitem>
<listitem>
<para>如果返回<literal>false</literal>,则处理被中断,其它的拦截器将不会被调用,数据包将不会
被服务器所处理。</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>配置拦截器</title>
<para>拦截器的配置在<literal>activemq-configuration.xml</literal>文件中:</para>
<programlisting>
&lt;remoting-interceptors&gt;
&lt;class-name&gt;org.apache.activemq.jms.example.LoginInterceptor&lt;/class-name&gt;
&lt;class-name&gt;org.apache.activemq.jms.example.AdditionalPropertyInterceptor&lt;/class-name&gt;
&lt;/remoting-interceptors&gt;
</programlisting>
<para>拦截器的类以及它们依赖的类必须要在服务器的classpath中否则不能被正常初始化及调用。</para>
</section>
<section>
<title>客户端拦截器</title>
<para>在客户端也可以有拦截器来拦截<emphasis>来自服务器</emphasis>的数据包。<code>ClientSessionFactory</code>
<code>addInterceptor()</code>方法可以用来添加拦截器。</para>
<para>同样拦截器的类以及它们依赖的类必须要在客户端的classpath中否则它们不能被正常初始化及调用。</para>
</section>
<section>
<title>例子</title>
<para>参见<xref linkend="examples.interceptor" />。这个例子中展示了如何使用拦截器向发往服务器的消息中
添加属性。</para>
</section>
</chapter>