spring integration - Multiple @ServiceActivator methods with the same inputChannel and different signature -


i'm trying implement annotation driven event bus (e.g. guava event bus) using spring integration. have publishsubscribechannel publish events , idea use methods annotated @serviceactivator event handlers. each method can have different signature based on event (payload) need handle.

what noticed when event published, all instances of serviceactivatinghandler created serviceactivatorannotationpostprocessor called , exception each method has signature not match payload. e.g.

caused by: org.springframework.expression.spel.spelevaluationexception: el1004e:(pos 8): method call: method handle(model.api.serviceavailableevent) cannot found on service.eai.testserviceactivatorimpl2 type 

is there way define @serviceactivator method specific payload types?

that's correct, subscribers publishsubscribechannel accept same message. , if there no chance convert incoming payload expected method argument type, exception.

if filter unexpected types, have use @filter before @serviceactivator. in other words same now, make flow(s) bit complex front filters subscribers publishsubscribechannel.

you can rely on existing payloadtypeselector:

@bean @filter(inputchannel = "publishsubscribechannel", outputchannel="service1") public messageselector payloadtypeselector() {    return new payloadtypeselector(...); } 

or, yes, simple pojo method checks payload type , marked same @filter.

i guess next question like: why doesn't @serviceactivator ignore types aren't unsuitable target method?

just don't mix concerns. service activator message handling in target business logic. filtering , skipping have difefrent ei pattern - filter.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -