Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 integration spring集成终点_Spring Integration - Fatal编程技术网

Spring integration spring集成终点

Spring integration spring集成终点,spring-integration,Spring Integration,第一个帖子。我是Spring集成新手,有以下场景: 我有一个服务“xyzSearchService.getXYZ”,它是作为http入站请求的结果调用的。 它做了一些逻辑,然后调用“routingChannel”,后者又调用google地理编码服务 我希望google的响应返回到xyzSearchService.getXYZ,但我不确定如何在“outboundGateway”中配置replyChannel。现在我让它转到同一服务中的另一个方法,在那里我可以看到结果,但我希望它返回到调用它的服务/

第一个帖子。我是Spring集成新手,有以下场景: 我有一个服务“xyzSearchService.getXYZ”,它是作为http入站请求的结果调用的。 它做了一些逻辑,然后调用“routingChannel”,后者又调用google地理编码服务

我希望google的响应返回到xyzSearchService.getXYZ,但我不确定如何在“outboundGateway”中配置replyChannel。现在我让它转到同一服务中的另一个方法,在那里我可以看到结果,但我希望它返回到调用它的服务/方法。不确定如何配置最终出站通道适配器

   <int-http:inbound-gateway id="inboundXYZSearchRequestGateway"
                              supported-methods="GET, POST"
                              request-channel="xyzSearchRequest"
                              reply-channel="xyzSearchResponse"
                              mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
                              view-name="/xyz"
                              path="/services/xyz/zip/{zipcode}/search"
                              reply-timeout="50000">

        <int-http:header name="zipcode" expression="#pathVariables.zipcode"/>
    </int-http:inbound-gateway>

    <int:service-activator id="xyzServiceActivator"
                           input-channel="xyzSearchRequest"
                           output-channel="xyzSearchResponse"
                           ref="xyzSearchService"
                           method="getXYZ"
                           requires-reply="true"
                           send-timeout="60000"/>

//the service activator method does some logic and invokes the "routingChannel"

    <int:chain input-channel="routingChannel">
        <int:router  
                    expression="payload.serviceType"  
                    default-output-channel="channel_default"  
                    resolution-required="false">
        </int:router>
    </int:chain>

    <int-http:outbound-gateway  id="outboundGateway"
                                url="http://maps.googleapis.com/maps/api/geocode/json?address={zipCode}"
                                http-method="GET"
                                request-factory="requestFactory"
                                request-channel="restchannel"
                                reply-channel="channel2"
                                expected-response-type="java.lang.String">
        <int-http:uri-variable name="zipCode" `enter code `enter code here`here`expression="payload.data['zipcode']"/>
    </int-http:outbound-gateway>


    <int:channel id="channel2"/>
    <int:outbound-channel-adapter channel="channel2" ref="xyzSearchService" method="routeUnit" />

我使用了前者:

Message<?> reply = toHttp.callHttp(inMessage);
Message reply=toHttp.callHttp(inMessage);

但是,我不认为它正在接收路由通道。

正确的解决方案是不直接发送到路由通道,而是使用a并让
发送到路由通道

由于可能返回结果,也可能不返回结果(取决于路由),因此应设置
默认回复超时=0
,在这种情况下,网关方法将返回null

或者,使用
MessagingTemplate
及其
sendAndReceive()
方法之一发送到路由通道-如果您可能无法获得回复,您同样需要回复超时为零

编辑:

不,我是建议

<gateway id="toHttp" service-interface="foo.MyGW
     default-request-channel="routingChannel"
     default-reply-timeout="0" />
或者


(后者让框架负责与消息之间的转换)。

正确的解决方案是不直接发送到路由通道,而是使用a并让
发送到路由通道

由于可能返回结果,也可能不返回结果(取决于路由),因此应设置
默认回复超时=0
,在这种情况下,网关方法将返回null

或者,使用
MessagingTemplate
及其
sendAndReceive()
方法之一发送到路由通道-如果您可能无法获得回复,您同样需要回复超时为零

编辑:

不,我是建议

<gateway id="toHttp" service-interface="foo.MyGW
     default-request-channel="routingChannel"
     default-reply-timeout="0" />
或者


(后者让框架负责与消息的转换)。

您是否建议我按如下方式配置入站网关:请不要在注释中添加代码;正如你所看到的,它是不可读的。请改为编辑问题,然后我将处理您的评论。让它工作-必须删除回复频道=“channel2”。帮个大忙,加里!!您是否建议我按如下方式配置入站网关:请不要在注释中添加代码;正如你所看到的,它是不可读的。请改为编辑问题,然后我将处理您的评论。让它工作-必须删除回复频道=“channel2”。帮个大忙,加里!!您是否建议我按如下方式配置入站网关:请不要在注释中添加代码;正如你所看到的,它是不可读的。请改为编辑问题,然后我将处理您的评论。让它工作-必须删除回复频道=“channel2”。帮个大忙,加里!!
@Autowired
private MyGW gateway;
Message<?> reply = toHttp.callHttp(inMessage);
<gateway id="toHttp" service-interface="foo.MyGW
     default-request-channel="routingChannel"
     default-reply-timeout="0" />
public interface MyGW {
    public Message<?> callHttp(Message<?> message);
}
@Autowired
private MyGW gateway;

...

    Message<?> reply = myGW.callHttp(m);
...
@Autowired
private MessageChannel routerChannel;


...
    MessagingTemplate template = new MessagingTemplate(routerChannel);
    template.setReceiveTimeout(0);
...
    Message<?> reply = template.sendAndReceive(m);
    Object reply = template.convertSendAndReceive(somePayload);