0

안녕하세요 Spring 통합을 사용하고 및 RestControllerSpring RestController에서 비동기 게이트웨이를 시작한 다음 메시지를 다음 채널로 전달하는 방법은 무엇입니까?

<int:gateway id="reportsService" 
    service-interface="me.service.MyReportingGateway" 
    default-request-channel="reportsRequestChannel" /> 

<int:channel id="reportsRequestChannel" > 
    <int:dispatcher task-executor="reportServiceExecutor" /></int:channel> 

<task:executor id="reportServiceExecutor" pool-size="5" /> 

<int:service-activator input-channel="reportsRequestChannel" output-channel="reportRouterChannel"> 
    <bean id="reportServiceExecutor" class="me.service.SpecReporting"/> 
</int:service-activator> 

<int:channel id="reportRouterChannel" /> 

<int:router input-channel="reportRouterChannel" method="routeReport" ref="reportRouter"></int:router> 

<bean class="me.service.ReportRequestRouter" id="reportRouter"> 
</bean> 

    <int:channel id="report01Channel"> 
    <int:queue capacity="10"></int:queue> 
    </int:channel> 

    <int:channel id="report02Channel"> 
    <int:queue capacity="10"></int:queue> 
    </int:channel> 

    <!-- for the channels --> 
    <int:poller default="true" fixed-delay="1000" id="poller"></int:poller> 

    <int:service-activator input-channel="report01Channel" 
    output-channel="CallbackChannel" ref="filewriter" method="writeFile"> 
    </int:service-activator> 
    <int:service-activator input-channel="report02Channel" 
    output-channel="CallbackChannel" ref="filewriter" method="writeFile"> 
    </int:service-activator> 

    <bean class="me.service.CsvFileWriter" id="filewriter"></bean> 

    <int:channel id="CallbackChannel" /> 

    <int-http:outbound-gateway id="httpOutbound" 
    request-channel="CallbackChannel" 
    http-method="GET" 
    url="http://localhost:8080/services/ping" /> 

내 RestController에 게이트웨이를 주입 한 게이트웨이 주입 :

@Autowired 
MyReporting reportsService; 

를 상기 제어기에있어서 내부 메소드를 호출

HttpStatus httpStatus = HttpStatus.OK; 
ReportingResponse arr = new ReportingResponse(); 
AppError ae = new AppError(); 
ae.setCode("ANP-SM-1000"); 
ae.setDescription("Everything Criss!!"); 
arr.setErrors(ae); 

logger.debug("Invoking: reportsService.createReport..."); 
// Async - this will start the report generation process 
reportsService.createReport(reportId,rInput); 

return new ResponseEntity<ReportingResponse>(arr, httpStatus); 

void return을 사용하여 executor-executor 채널을 구성한 이래 어떻게해야합니까? 이 스레드는 reportRouterChannel 인 다음 채널로 이동 하시겠습니까?

답변

0

스프링 부트는 멋진 핸들을 제공합니다. @Async 주석을 추가하면 비동기 적으로 메소드가 실행됩니다.

그냥 @Configuration 클래스 중 하나에 @EnableAsync를 추가하는 것을 잊지 마십시오 async

HttpStatus httpStatus = HttpStatus.OK; 
ReportingResponse arr = new ReportingResponse(); 
AppError ae = new AppError(); 
ae.setCode("ANP-SM-1000"); 
ae.setDescription("Everything Criss!!"); 
arr.setErrors(ae); 

logger.debug("Invoking: reportsService.createReport..."); 
asyncMethod(reportId,rInput); 

return new ResponseEntity<ReportingResponse>(arr, httpStatus); 

@Async 
public void asyncMethod(String reportId, File rInput){ 
reportsService.createReport(reportId,rInput); 

} 

에 당신의 방법을 포장. 봄이 당신을 위해 모든 마법을 다할 것입니다.