I need to queue commands in such a way to avoid conflict, during commands execution. Commands are received in order. A command operate on specific entity, so I want to queue the commands based on the entities they are intended to operate on. For example, commands c1 and c3 operate on entity-id 5, so they need to go in the order they are received into q5. At the same time, commands c2, and c4 operate on entity-id 6, so they need to go on the queue specific to that entity (q-6). I am not sure sure if spring-integration is best option for this use case, but here's what I have so far:
@Bean
public IntegrationFlow commands() {
return f -> f .<Command>split()
.enrichHeaders(h -> {
h.headerExpression("objectId", "payload.objectId.toString() ");
})
.route("@channelResolver.resolve(headers['objectId'])") // how to create channels dynamically
.handle(mySingletonBeanHandler); // how to use singleton bean here
}
Problems I am facing is using Dynamic Router. Since I don't know the entities Ids in advance, I would like those queues to be created dynamically. The exception I am getting is:
The 'currentComponent' (org.springframework.integration.router.ExpressionEvaluatingRouter@3e134896) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
So, my questions are:
- How to construct queues dynamically (with auto cleaning) for each entity/object-Id.
- How to pass the messages after routing, to a singleton handler, ensuring the processing is parallel for all queues, but sequential per queue.
I am new to spring-integration, and hoping to continue using java DSL if possible to avoid confusion.