【问题标题】:spring amqp outbound gateway no output-channel or replyChannel header availablespring amqp出站网关没有可用的输出通道或replyChannel标头
【发布时间】:2018-04-10 18:55:11
【问题描述】:

在将 Spring-AMQP 与 oubound-gateway 集成时遇到困难..

错误: 原因:org.springframework.messaging.core.DestinationResolutionException:没有可用的输出通道或replyChannel标头

集成xml

<int:gateway id="outboundGateway" service-interface="com.amqp.outbound.gateway.OutboundGateway"     
                    default-reply-channel="defaultReplyChannel" >
    <int:method name="process"   request-channel="inboundRequestChannel"/>
</int:gateway>

<int:channel id="defaultReplyChannel"/>
<int:channel id="inboundRequestChannel"/>
<int:channel id="enrichedInboundRequestChannel"/>
<int:channel id="processAuthRequestChannel"/>

<int:chain input-channel="inboundRequestChannel" output-channel="enrichedInboundRequestChannel">
    <int:service-activator id="serviceActivator"
                   ref="ouboundService"  method="createRequest"/>
</int:chain>

<int-amqp:outbound-gateway id="outboundGtwyId" header-mapper="headerMapper"
                    request-channel="enrichedInboundRequestChannel"
                    reply-channel="defaultReplyChannel"
                    amqp-template="template" 
                    reply-timeout="30000"
                    exchange-name="request_exchange" 
                    routing-key="request_exchange_queue" />

<int-amqp:inbound-channel-adapter id="amqpMessageDriven"  queue-names="request_queue" 
                             connection-factory="rabbitConnectionFactory"  channel="processAuthRequestChannel"/>

<int:service-activator id="serviceActivator"
                   ref="ouboundService" input-channel="processAuthRequestChannel"
                   method="processRequest"/>

配置

@Bean
public RabbitTemplate template(ConnectionFactory rabbitConnectionFactory){
    final RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory);
    return template;
}


@Bean
public Binding binding(){
    return BindingBuilder.bind(this.queue()).to(this.exchange()).with("request_exchange_queue");
}

@Bean
public DirectExchange exchange(){
    return new DirectExchange("request_exchange");
}

@Bean
public Queue queue(){
    return new Queue("request_queue", true, false, true);
}

服务类

@Service
public final class OuboundService {



    public Message createRequest(String message){
        System.out.println("Inside createRequest : "+ message);
        final Message builtMessage = MessageBuilder.withBody(message.getBytes())
                .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
                .setCorrelationIdString("123456").build();
        return builtMessage;
    }


    public Message processRequest(Message message){
        System.out.println("Inside process Request : "+ message.getBody());
        final Message result = MessageBuilder.withBody("Successful".getBytes()).copyProperties(message.getMessageProperties())
                                .copyHeaders(message.getMessageProperties().getHeaders()).build();
        return result;
    }

}

有人可以帮助这里缺少什么,为什么出站网关没有产生回复?仅供参考 - 我是 AMQP 的新手。任何帮助将不胜感激。

【问题讨论】:

    标签: spring-integration spring-amqp


    【解决方案1】:

    您的问题不在出站网关上,而恰恰在 processRequest 服务激活器上。仅仅因为您在那里使用&lt;int-amqp:inbound-channel-adapter&gt; 而这个绝对不会填充replyChannel 标头 - 它只是不期望任何回复。因此,尝试从上述服务激活器发送它失败,并返回 DestinationResolutionException

    如果您真的打算从那里发送回复,请考虑改用 AMQP 入站网关。

    【讨论】:

    • 感谢 Artem 的回复,有没有办法我可以从不同的线程将响应发送到出站网关(如 jms 出站网关,具有不同的队列,使用关联键关联请求/响应) ?.这意味着在我们的例子中 processRequest 将通过进行 restcall(Async) 处理到外部系统。他们将再次对该应用进行后调用以响应出站网关。
    • 嗯,这是可能的。但这是完全不同的故事,与主题中的问题无关。您可以随意提出一个新的 SO 线程,我们会回复您。
    猜你喜欢
    • 2018-06-12
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 2022-01-17
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    相关资源
    最近更新 更多