[英]Multithreading Spring integration DSL
I want to create a simple IntegrationFlow with Spring integration, and I am having difficulties.我想用 Spring 集成创建一个简单的 IntegrationFlow,但遇到了困难。
I want to create an integration flow that takes messages from multiple queues in Rabbit Mq and posts the messages to different Rest endpoints.我想创建一个集成流,从 Rabbit Mq 中的多个队列获取消息并将消息发布到不同的 Rest 端点。
i want to know if i can parallelize this.我想知道我是否可以并行化这个。
i have two scenarios that i want to check the feasibility :我有两种情况要检查可行性:
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
RestTemplate restTemplate = new RestTemplate();
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
container.setQueueNames(BOUTIQUE_QUEUE_NAME);
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
return IntegrationFlows.from(Amqp.inboundAdapter(container)) /* Get Message from RabbitMQ */
.handle(msg ->
{
String msgString = new String((byte[]) msg.getPayload(), StandardCharsets.UTF_8);
HttpEntity<String> requestBody = new HttpEntity<String>(msgString, headers);
restTemplate.postForObject(ENDPOINT_LOCAL_URL, requestBody, String.class);
System.out.println(msgString);
})
.get();
}
For the first scenario, simply configure a inbound adapter for each and set the output channel to a common channel for the downstream flow.对于第一个场景,只需为每个场景配置一个入站适配器,并将输出通道设置为下游流的公共通道。
For the second scenario, simply set the concurrentConsumers
and maxConcurrentConsumers
on the listener container and it will scale up/down the threads as needed.对于第二种情况,只需在侦听器容器上设置
concurrentConsumers
和maxConcurrentConsumers
,它将根据需要扩展/缩小线程。
See the Spring AMQP Documentation .请参阅Spring AMQP 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.