簡體   English   中英

在 Spring Integration 中使用 Transformer 輪詢 HTTP 服務(出站網關)和流程

[英]Polling HTTP Service(Outbound Gateway) & process using Transformer in Spring Integration

這就是我想要實現的目標。 每 15 分鍾輪詢一次 HTTP API 並處理從中檢索到的數據。 我們計划使用 Spring Integration。 我是新手。 因此,在幾乎沒有理解的情況下,我創建了一個出站網關並為其添加了輪詢器,但出現以下錯誤。

另外,有人可以告訴我如何使用轉換器來處理來自出站網關的數據嗎?

Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0':
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 
A poller should not be specified for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0', 
since 'in' is a SubscribableChannel (not pollable).

我的 int-config.xml 文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:int-http="http://www.springframework.org/schema/integration/http">

    <int:annotation-config/>

    <!-- Inbound/Outbound Channels -->
    <int:channel id="employeeSearchRequest" />
    <int:channel id="employeeSearchResponse" />

    <int:channel id="userSearchRequest" />
    <int:channel id="userSearchResponse" />


    <int-http:inbound-gateway id="inboundEmployeeSearchRequestGateway"
        supported-methods="GET, POST"
        request-channel="employeeSearchRequest"
        reply-channel="employeeSearchResponse"      
        mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
        view-name="/employee"
        path="/services/employee/{id}/search"
        reply-timeout="50000">

        <int-http:header name="employeeId" expression="#pathVariables.id"/>

    </int-http:inbound-gateway>

    <int-http:inbound-gateway id="inboundUserSearchRequestGateway"
        supported-methods="GET, POST"
        request-channel="userSearchRequest"
        reply-channel="userSearchResponse"      
        mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
        view-name="/users"
        path="/users/{id}/search"
        reply-timeout="50000">

        <int-http:header name="userId" expression="#pathVariables.id"/>

    </int-http:inbound-gateway>

    <!-- Consume WS Sample -->
    <int:channel id="in" />
    <int:channel id="out" />

     <int-http:outbound-gateway request-channel="in" reply-channel="out"
        url="http://echo.jsontest.com/key/value/one/two" http-method="GET" 
        expected-response-type="java.lang.String">
        <int:poller fixed-rate="20000"/>
    </int-http:outbound-gateway>

    <int:transformer input-channel="in"
    output-channel="out" ref="hTTPTransformer" />

    <!-- Consume WS Sample Ends -->


    <!-- Note: The default parameter name for favorParameter is "format". For instance, when this flag is true, a request for /services/employee/{id}/search?format=json will result
            in an MappingJacksonJsonView being resolved, while the Accept header can be the browser-defined text/html,application/xhtml+xml  -->

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
                <property name="defaultContentType" value="application/json"/>
                <property name="favorParameter" value="true"/>
                <property name="ignoreAcceptHeader" value="true" />
                <property name="mediaTypes">
                    <map>
                        <entry key="json" value="application/json" />
                        <entry key="xml" value="application/xml" />
                    </map>
                </property>
            </bean>
        </property>
        <property name="defaultViews">
            <list>
                <bean
                    class="org.springframework.integration.samples.rest.json.view.ExtendedMappingJacksonJsonView" >
                    <property name="objectMapper" ref="jaxbJacksonObjectMapper"/>
                </bean>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg ref="marshaller"/>
                </bean>
            </list>
        </property>
    </bean>

    <oxm:jaxb2-marshaller id="marshaller" context-path="org.springframework.integration.samples.rest.domain" />

    <int:service-activator id="employeeServiceActivator"
                    input-channel="employeeSearchRequest"
                    output-channel="employeeSearchResponse"
                    ref="employeeSearchService"
                    method="getEmployee"
                    requires-reply="true"
                    send-timeout="60000"/>

    <int:service-activator id="userServiceActivator"
                    input-channel="userSearchRequest"
                    output-channel="userSearchResponse"
                    ref="userSearchService"
                    method="getUsers"
                    requires-reply="true"
                    send-timeout="60000"/>                  

    <bean id="jaxbJacksonObjectMapper" class="org.springframework.integration.samples.rest.json.JaxbJacksonObjectMapper"/>

</beans>

有人能告訴我為什么我會收到這個錯誤嗎? 在此先感謝各位!

第一次更新:對於輪詢,添加入站通道適配器工作

<int-http:outbound-gateway request-channel="in" reply-channel="out"
        url="http://echo.jsontest.com/key/value/one/two" http-method="GET" 
        expected-response-type="java.lang.String">
    </int-http:outbound-gateway>

<int:inbound-channel-adapter channel="in" expression="''">
        <int:poller fixed-delay="60000"></int:poller>
    </int:inbound-channel-adapter>

第二次更新:為了將響應轉換為 bean,添加了此代碼

<int:json-to-object-transformer input-channel="out" 
output-channel="testChannel" type="org.springframework.integration.samples.rest.domain.PlaceholderBean"/>

<int:service-activator method="dummyMethod" input-channel="testChannel" ref="dummyService"/> 

最后,我可以輪詢 HTTP 服務,獲取數據並對其進行處理! 感謝@JensKrogsboell 提供的所有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM