在Spring集成流中注册相邻HTTP请求的好方法是什么?
我的申请是:
对于每个客户(都有自己的流程,该流程由轮询者安排)
...
操作1、2,...,n必须按顺序
这是我的示例程序(为简单起见,所有REST调用均针对同一类)
@Configuration
public class ApplicationConfiguration {
@Autowired
private IntegrationFlowContext flowContext;
@Bean
public MethodInvokingMessageSource integerMessageSource() {
final MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setObject(new AtomicInteger());
source.setMethodName("getAndIncrement");
return source;
}
@PostConstruct
public void createAndRegisterFlows() {
IntegrationFlowBuilder integrationFlowBuilder = createFlowBuilder();
for (int i = 1; i <= 2; i++) {
integrationFlowBuilder = flowBuilder(integrationFlowBuilder, i);
}
integrationFlowBuilder.handle(CharacterStreamWritingMessageHandler.stdout());
flowContext.registration(integrationFlowBuilder.get()).register();
}
private IntegrationFlowBuilder createFlowBuilder() {
return IntegrationFlows.from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(5000)));
}
private IntegrationFlowBuilder flowBuilder(final IntegrationFlowBuilder integrationFlowBuilder, final int number) {
return integrationFlowBuilder
.handle(Http.outboundGateway("http://localhost:8055/greeting" + number).httpMethod(HttpMethod.GET)
.expectedResponseType(String.class))
.channel("getReceive" + number)
.handle(Http.outboundGateway("http://localhost:8055/greeting" + number).httpMethod(HttpMethod.POST)
.expectedResponseType(String.class))
.channel("postReceive" + number)
.handle(Http.outboundGateway("http://localhost:8055/greeting-final" + number)
.httpMethod(HttpMethod.POST).expectedResponseType(String.class))
.channel("postReceiveFinal" + number);
}
}
该程序运行集成流程
GET http://localhost:8055/greeting1
POST http://localhost:8055/greeting1 (previous result as an input)
POST http://localhost:8055/greeting-final1 (previous result as an input)
GET http://localhost:8055/greeting2
POST http://localhost:8055/greeting2 (previous result as an input)
POST http://localhost:8055/greeting-final2 (previous result as an input)
这按预期工作。但是我想知道这样做的好方法,因为调用POST http://localhost:8055/greeting-final1
中没有使用来自调用GET http://localhost:8055/greeting2
的响应。我只希望这些呼叫按此顺序进行。
答案 0 :(得分:0)
实际上,您拥有该循环所需的一切,可以创建对REST服务的子流调用。 import numpy as np
values = [1,2,3,4,5,6,7,8,9,10,11]
cond = [df['tla']<85000, (df['tla'] >= 850000) & (df['tla'] < 110000), .... ]
df['bid_bucket'] = np.select(cond, values)
只会导致您丢失payload
,而该消息将与消息一起发布到greeting-final1
。第二次迭代会将.channel("postReceiveFinal" + number)
订阅到该频道,并且greeting2"
可在此处进行处理。不确定如何重做payload
方法,但是您只需要使用消息中的flowBuilder()
即可满足您的要求,例如您可以将其用作:
payload
将有效负载注入某些请求参数,因为它只是/**
* Specify an {@link Expression} to evaluate a value for the uri template variable.
* @param variable the uri template variable.
* @param expression the expression to evaluate value for te uri template variable.
* @return the current Spec.
* @see AbstractHttpRequestExecutingMessageHandler#setUriVariableExpressions(Map)
* @see ValueExpression
* @see org.springframework.expression.common.LiteralExpression
*/
public S uriVariable(String variable, Expression expression) {
:
HttpMethod.GET