I need to use a PayloadTypeRouter
and want to send the routed message directly into a Transformer
, Filter
or ServiceActivator
. All should be configured with Kotlin DSL (or Java DSL).
Currently, a nice looking part of code looks like this:
@Bean
fun routeAzureC2DMessage() = integrationFlow {
channel(IoTHubChannelNames.IOTHUB_TO_DEVICE_CHANNEL)
route<IotHubC2DRequestMessage<IotHubC2DRequest>> {
when (it.payload) {
is IotHubDesiredPropertyUpdate -> IoTHubChannelNames.DESIRED_PROPERTY_UPDATE
is IotHubMessageToDevice -> IoTHubChannelNames.MESSAGE_TO_DEVICE
}
}
}
and then continued by (one side of the routing)
@Bean
fun processMessageToDevice() = integrationFlow {
channel(IoTHubChannelNames.MESSAGE_TO_DEVICE)
filter(StructureFilter())
transform(MessageTransformer())
channel(SharedChannelNames.CLOUD2DEVICE)
}
I would like to get rid of the unneeded channel IoTHubChannelNames.MESSAGE_TO_DEVICE
. I tried several approaches and in another part of the project I figured out something like this (Java DSL)
IntegrationFlows
.from(channelName)
.route({ message: IotHubMessage -> message.javaClass }) { router: RouterSpec<Class<*>?, MethodInvokingRouter?> ->
router
.subFlowMapping(DeviceToCloudMessage::class.java) {
it.handle(gateway, "handleD2CMessage")
}
.subFlowMapping(DeviceTwinUpdateMessage::class.java) {
it.handle(gateway, "handleDeviceTwinReportedProperty")
}
}
.get()
Are subFlowMapping
s the only way to get rid of the channels in between? I would like a solution where I can still use when (it.payload)
and then instead of the channel/channel name could return a new integrationFlow
or some other form of Flow definition.