Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.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
Java Spring Cloud Stream@ServiceActivator未向errorChannel发送异常消息_Java_Spring Cloud Stream - Fatal编程技术网

Java Spring Cloud Stream@ServiceActivator未向errorChannel发送异常消息

Java Spring Cloud Stream@ServiceActivator未向errorChannel发送异常消息,java,spring-cloud-stream,Java,Spring Cloud Stream,我正在使用SpringCloudStream,使用SpringCloudStarterStreamKafka。我已在应用程序.properties中将频道绑定到卡夫卡主题,如下所示: spring.cloud.stream.bindings.gatewayOutput.destination=received spring.cloud.stream.bindings.enrichingInput.destination=received spring.cloud.stream.bindings.

我正在使用SpringCloudStream,使用SpringCloudStarterStreamKafka。我已在
应用程序.properties
中将频道绑定到卡夫卡主题,如下所示:

spring.cloud.stream.bindings.gatewayOutput.destination=received
spring.cloud.stream.bindings.enrichingInput.destination=received
spring.cloud.stream.bindings.enrichingOutput.destination=enriched
spring.cloud.stream.bindings.redeemingInput.destination=enriched
spring.cloud.stream.bindings.redeemingOutput.destination=redeemed
spring.cloud.stream.bindings.fulfillingInput.destination=redeemed
spring.cloud.stream.bindings.error.destination=errors12
spring.cloud.stream.bindings.errorInput.destination=errors12
spring.cloud.stream.bindings.errorOutput.destination=errors12
我无法让我的程序向错误通道生成异常消息。令人惊讶的是,它甚至没有尝试生成它,即使我在不同的线程中(我有一个
@MessagingGateway
,它将消息转储到
网关输出中,然后流的其余部分异步发生)。以下是my
ServiceActivator的定义:

@Named
@Configuration
@EnableBinding(Channels.class)
@EnableIntegration
public class FulfillingServiceImpl extends AbstractBaseService implements
        FulfillingService {

    @Override
    @Audit(value = "annotatedEvent")
    @ServiceActivator(inputChannel = Channels.FULFILLING_INPUT, requiresReply = "false")
    public void fulfill(TrivialRedemption redemption) throws Exception {

        logger.error("FULFILLED!!!!!!");

        throw new Exception("test exception");

    }
}
这是生成的日志(我已经截断了完整的异常)。没有

  • 关于errorChannel没有任何订户的投诉
  • Kafka生产者线程日志记录

您不显示您的
频道
类,但活页夹不知道您的“错误”频道是“特殊”频道

活页夹可以配置为重试,并将异常路由到死信主题;请参见1.0.0.0版本中的内容

或者,您可以在service activator之前添加一个“中间流”网关—将其视为Java中的“try/catch”块:

@MessageEndpoint
public static class GatewayInvoker {

    @Autowired
    private ErrorHandlingGateway gw;

    @ServiceActivator(inputChannel = Channels.FULFILLING_INPUT)
    public void send(Message<?> message) {
        this.gw.send(message);
    }

}

@Bean
public GatewayInvoker gate() {
    return new GatewayInvoker();
}

@MessagingGateway(defaultRequestChannel = "toService", errorChannel = Channels.ERRORS)
public interface ErrorHandlingGateway {

    void send(Message<?> message);

}
@MessageEndpoint
公共静态类网关调用程序{
@自动连线
专用错误处理网关;
@ServiceActivator(inputChannel=Channels.INPUT)
公共无效发送(消息){
此.gw.send(消息);
}
}
@豆子
公共网关调用器网关(){
返回新的GatewayInvoker();
}
@MessagingGateway(defaultRequestChannel=“toService”,errorChannel=Channels.ERRORS)
公共接口错误处理网关{
无效发送(消息);
}
将service activator的输入频道更改为
到service

您必须将
@IntegrationComponentScan
添加到配置类中,以便框架可以检测
@MessagingGateway
接口并为其构建代理

编辑


我刚刚建议的另一种选择是在您的service activator的建议链中添加一个
ExpressionEvaluationAdvice

另外,请关注Spring Cloud Stream未来解决方案的进展。感谢您的全面回答,我仍在消化它。我已经添加了Channels.class,并且喜欢采用基于建议的方法的建议,因为我也对有状态重试行为感兴趣。我对你回答的一些问题有点困惑。您提到[该绑定器可以配置为重试,并将异常路由到死信主题;请参阅1.0.0.版本中的此PR。]。我使用的是1.0.0.RC2,它似乎比PR早。1.0.0.RELEASE什么时候发布?是的。我想让你知道,我在使用dlq时得到了这个。谢谢你的帮助@GaryRussell
public interface Channels {

    public static final String GATEWAY_OUTPUT = "gatewayOutput";

    public static final String ENRICHING_INPUT = "enrichingInput";
    public static final String ENRICHING_OUTPUT = "enrichingOutput";

    public static final String REDEEMING_INPUT = "redeemingInput";
    public static final String REDEEMING_OUTPUT = "redeemingOutput";

    public static final String FULFILLING_INPUT = "fulfillingInput";
    public static final String FULFILLING_OUTPUT = "fulfillingOutput";

    @Output(GATEWAY_OUTPUT)
    MessageChannel gatewayOutput();

    @Input(ENRICHING_INPUT)
    MessageChannel enrichingInput();

    @Output(ENRICHING_OUTPUT)
    MessageChannel enrichingOutput();

    @Input(REDEEMING_INPUT)
    MessageChannel redeemingInput();

    @Output(REDEEMING_OUTPUT)
    MessageChannel redeemingOutput();

    @Input(FULFILLING_INPUT)
    MessageChannel fulfillingInput();

    @Output(FULFILLING_OUTPUT)
    MessageChannel fulfillingOutput();
@MessageEndpoint
public static class GatewayInvoker {

    @Autowired
    private ErrorHandlingGateway gw;

    @ServiceActivator(inputChannel = Channels.FULFILLING_INPUT)
    public void send(Message<?> message) {
        this.gw.send(message);
    }

}

@Bean
public GatewayInvoker gate() {
    return new GatewayInvoker();
}

@MessagingGateway(defaultRequestChannel = "toService", errorChannel = Channels.ERRORS)
public interface ErrorHandlingGateway {

    void send(Message<?> message);

}