Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 从全局导线抽头中排除特定通道的模式_Spring_Spring Integration - Fatal编程技术网

Spring 从全局导线抽头中排除特定通道的模式

Spring 从全局导线抽头中排除特定通道的模式,spring,spring-integration,Spring,Spring Integration,我有一个用于审计目的的全局布线接头。由于wire tap没有从通道中获取消息的克隆,因此我从消息中提取某些属性,并将其转发到另一个(异步)通道,在该通道中它将被持久化。所以在某种意义上,导线抽头有它自己的子流。我意识到wire-tap不会点击自身,但我希望它也不会点击属于持久性子流的任何通道 我意识到wire tap有一个模式,但它似乎不接受正则表达式来排除不应全局分接的通道。提供排除模式的格式是什么?来自@GlobalChannelInterceptorJavaDocs: /** * An

我有一个用于审计目的的全局布线接头。由于wire tap没有从通道中获取消息的克隆,因此我从消息中提取某些属性,并将其转发到另一个(异步)通道,在该通道中它将被持久化。所以在某种意义上,导线抽头有它自己的子流。我意识到wire-tap不会点击自身,但我希望它也不会点击属于持久性子流的任何通道


我意识到wire tap有一个模式,但它似乎不接受正则表达式来排除不应全局分接的通道。提供排除模式的格式是什么?

来自
@GlobalChannelInterceptor
JavaDocs:

/**
 * An array of simple patterns against which channel names will be matched. Default is "*"
 * (all channels). See {@link org.springframework.util.PatternMatchUtils#simpleMatch(String, String)}.
 * @return The pattern.
 */
String[] patterns() default "*";
因此,根据
模式匹配utils.simpleMatch
我们可以:

* Match a String against the given pattern, supporting the following simple
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
* arbitrary number of pattern parts), as well as direct equality.
正如你所见,我们不能否定这种模式

从另一方面来说,我认为我们可以克服这个限制。如您所见,
WireTap
使用以下简单逻辑实现
vetocaableinterceptor

public boolean shouldIntercept(String beanName, ChannelInterceptorAware channel) {
    return !this.channel.equals(channel);
}

因此,您可以扩展这个
WireTap
类,并向Overcode方法添加更多逻辑。之后,您应该使用Artem的建议在XML配置中将其注册为

,我能够解决这个问题,但我在这一过程中遇到了一些问题,因此我将在这里留下我的实现的外壳,以防其他人有相同的问题:

我做的第一件事是实现一个扩展WireTap类的类。这个班看起来是这样的-

package org.mycompany.interceptors;

import org.springframework.integration.channel.ChannelInterceptorAware;
import org.springframework.integration.channel.interceptor.WireTap;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.messaging.MessageChannel;

public class GlobalWireTap extends WireTap {

    public GlobalWireTap(MessageChannel channel) {
        super(channel);
    }

    @Override
    public boolean shouldIntercept(String beanName, ChannelInterceptorAware interceptChannel) {
        NamedComponent incomingChannel = (NamedComponent) interceptChannel;
        String channelName = incomingChannel.getComponentName();
        /* logic to determine if this channel should be intercepted */
        if (channelName.startsWith("DNT")) {
            return false;
        }
        return true;
    }
}
如您所见,传入参数的类型为ChannelInterceptorAware。然而,ChannelInterceptorAware并没有告诉我多少有关通道的信息,所以我将其转换为一个命名组件(每种类型的通道都实现了该组件),并检查通道的id以决定是否要拦截该通道。请注意,在WireTap类中,通道属性是私有的,因此您不能在子类中执行类似-this.channel的操作

相应的配置如下所示:

<int:channel-interceptor pattern="*" ref="globalWireTap"></int:channel-interceptor>

<bean id="globalWireTap"
    class="org.mycompany.interceptors.GlobalWireTap">
    <constructor-arg ref="nullChannel" />
</bean> 


目前,我正在将所有消息重定向到nullChannel,但您可以将其转发到任何通道。

@GaryRussell在扩展类以能够传递消息通道时,是否有办法利用wire tap的解析逻辑?M-M-M。对不起,请重新措辞。我不明白。如果您想通过有线抽头通道,那么这可能没有意义,而且更多:您最终会遇到
stackoverflowerrror
将消息从有线抽头发送到有线抽头通道。我理解。我的问题是,当我扩展WireTap类时,比如用我自己的类GlobalWireTap,我如何在配置xml中将输出通道传递给它?例如,当我们直接使用有线抽头时,我们能够将一个输出通道传递给它,它将成为次要目标。我怎样才能在我的GlobalWireTap类中实现同样的效果呢?嗯,看起来我不明白你的意思,因为你使用了一些其他的术语。。。让我猜猜。“通过输出通道”表示“注入导线抽头通道”。不确定什么是“次要目标”,但任何组件都可以使用常规的
定义在XML中进行配置。由于注释的长度限制,我将用我在实施方面的经验来回答这个问题。谢谢你抽出时间。