spring amqp outbound gateway没有输出通道或replyChannel标头可用

时间:2017-10-29 19:25:41

标签: spring-integration spring-amqp

面对将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的新手。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您的问题不在出站网关上,而是在processRequest服务激活器上。仅仅因为你在那里使用<int-amqp:inbound-channel-adapter>并且这个肯定没有填充replyChannel标题 - 它只是不期望任何回复。因此,尝试从提到的服务激活器发送它失败了DestinationResolutionException

如果您确实打算从那里发送回复,请考虑切换到AMQP入站网关。