admin管理员组

文章数量:1026989

I'm trying to create an implementation of the IntegrationFlowAdapter class that would allow me to take a push notification, copy it for each device token, split the push notification list and have it routed to the correct handler based on the platform, then take the results to process them (log them or possibly create business logic). The flow stops after handling by the subflow, how can I continue the flow?

This is my code:

public class PushSendFlowAdapter extends IntegrationFlowAdapter {

    private final String inputChannel;

    DeviceTokenManagerService<?> deviceTokenManagerService;

    private final FirebaseSender firebaseSender;

    private final ApnsSender apnsSender;

    private final HuaweiSender huaweiSender;




    @Override
    protected IntegrationFlowDefinition<?> buildFlow() {
        return IntegrationFlows.from(this.inputChannel)
                .handle((pushNotification, headers) -> deviceTokenManagerService.clonePushNotificationForEachDeviceToken((PushNotification) pushNotification))
                .split()
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.headerExpression(TracingConstants.PLATFORM, "payload.getDeviceToken().getPlatform()"))
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header(TracingConstants.CORRELATION_ID, UUID.randomUUID()))
                .route(Message.class, h -> h.getHeaders().get(TracingConstants.PLATFORM, Platform.class),
                        routerSpec -> routerSpec
                                .subFlowMapping(Platform.ANDROID, androidFlow -> androidFlow.handle(PushNotification.class, firebaseSender::sendPush))
                                .subFlowMapping(Platform.IOS, iosFlow -> iosFlow.handle(PushNotification.class, apnsSender::sendPush))
                                .subFlowMapping(Platform.HUAWEI, huaweiFlow -> huaweiFlow.handle(PushNotification.class, huaweiSender::sendPush))
                )
                .aggregate(aggregatorSpec -> aggregatorSpec.correlationStrategy(message -> message.getHeaders().get(TracingConstants.CORRELATION_ID)))
                .handle((p,h) -> {
                     log.info("log: {}", p);
                     //handling logic
                     return null;
                });
    }
}

I'm trying to create an implementation of the IntegrationFlowAdapter class that would allow me to take a push notification, copy it for each device token, split the push notification list and have it routed to the correct handler based on the platform, then take the results to process them (log them or possibly create business logic). The flow stops after handling by the subflow, how can I continue the flow?

This is my code:

public class PushSendFlowAdapter extends IntegrationFlowAdapter {

    private final String inputChannel;

    DeviceTokenManagerService<?> deviceTokenManagerService;

    private final FirebaseSender firebaseSender;

    private final ApnsSender apnsSender;

    private final HuaweiSender huaweiSender;




    @Override
    protected IntegrationFlowDefinition<?> buildFlow() {
        return IntegrationFlows.from(this.inputChannel)
                .handle((pushNotification, headers) -> deviceTokenManagerService.clonePushNotificationForEachDeviceToken((PushNotification) pushNotification))
                .split()
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.headerExpression(TracingConstants.PLATFORM, "payload.getDeviceToken().getPlatform()"))
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header(TracingConstants.CORRELATION_ID, UUID.randomUUID()))
                .route(Message.class, h -> h.getHeaders().get(TracingConstants.PLATFORM, Platform.class),
                        routerSpec -> routerSpec
                                .subFlowMapping(Platform.ANDROID, androidFlow -> androidFlow.handle(PushNotification.class, firebaseSender::sendPush))
                                .subFlowMapping(Platform.IOS, iosFlow -> iosFlow.handle(PushNotification.class, apnsSender::sendPush))
                                .subFlowMapping(Platform.HUAWEI, huaweiFlow -> huaweiFlow.handle(PushNotification.class, huaweiSender::sendPush))
                )
                .aggregate(aggregatorSpec -> aggregatorSpec.correlationStrategy(message -> message.getHeaders().get(TracingConstants.CORRELATION_ID)))
                .handle((p,h) -> {
                     log.info("log: {}", p);
                     //handling logic
                     return null;
                });
    }
}
Share Improve this question asked Nov 25, 2024 at 15:40 Simone FranchinaSimone Franchina 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

It is not clear what Spring Integration version you use, but try to add .defaultOutputToParentFlow() to that routerSpec configuration.

Also would be great to know a signature of your sendPush and if it really returns something what should go down to the aggregate.

I'm trying to create an implementation of the IntegrationFlowAdapter class that would allow me to take a push notification, copy it for each device token, split the push notification list and have it routed to the correct handler based on the platform, then take the results to process them (log them or possibly create business logic). The flow stops after handling by the subflow, how can I continue the flow?

This is my code:

public class PushSendFlowAdapter extends IntegrationFlowAdapter {

    private final String inputChannel;

    DeviceTokenManagerService<?> deviceTokenManagerService;

    private final FirebaseSender firebaseSender;

    private final ApnsSender apnsSender;

    private final HuaweiSender huaweiSender;




    @Override
    protected IntegrationFlowDefinition<?> buildFlow() {
        return IntegrationFlows.from(this.inputChannel)
                .handle((pushNotification, headers) -> deviceTokenManagerService.clonePushNotificationForEachDeviceToken((PushNotification) pushNotification))
                .split()
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.headerExpression(TracingConstants.PLATFORM, "payload.getDeviceToken().getPlatform()"))
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header(TracingConstants.CORRELATION_ID, UUID.randomUUID()))
                .route(Message.class, h -> h.getHeaders().get(TracingConstants.PLATFORM, Platform.class),
                        routerSpec -> routerSpec
                                .subFlowMapping(Platform.ANDROID, androidFlow -> androidFlow.handle(PushNotification.class, firebaseSender::sendPush))
                                .subFlowMapping(Platform.IOS, iosFlow -> iosFlow.handle(PushNotification.class, apnsSender::sendPush))
                                .subFlowMapping(Platform.HUAWEI, huaweiFlow -> huaweiFlow.handle(PushNotification.class, huaweiSender::sendPush))
                )
                .aggregate(aggregatorSpec -> aggregatorSpec.correlationStrategy(message -> message.getHeaders().get(TracingConstants.CORRELATION_ID)))
                .handle((p,h) -> {
                     log.info("log: {}", p);
                     //handling logic
                     return null;
                });
    }
}

I'm trying to create an implementation of the IntegrationFlowAdapter class that would allow me to take a push notification, copy it for each device token, split the push notification list and have it routed to the correct handler based on the platform, then take the results to process them (log them or possibly create business logic). The flow stops after handling by the subflow, how can I continue the flow?

This is my code:

public class PushSendFlowAdapter extends IntegrationFlowAdapter {

    private final String inputChannel;

    DeviceTokenManagerService<?> deviceTokenManagerService;

    private final FirebaseSender firebaseSender;

    private final ApnsSender apnsSender;

    private final HuaweiSender huaweiSender;




    @Override
    protected IntegrationFlowDefinition<?> buildFlow() {
        return IntegrationFlows.from(this.inputChannel)
                .handle((pushNotification, headers) -> deviceTokenManagerService.clonePushNotificationForEachDeviceToken((PushNotification) pushNotification))
                .split()
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.headerExpression(TracingConstants.PLATFORM, "payload.getDeviceToken().getPlatform()"))
                .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header(TracingConstants.CORRELATION_ID, UUID.randomUUID()))
                .route(Message.class, h -> h.getHeaders().get(TracingConstants.PLATFORM, Platform.class),
                        routerSpec -> routerSpec
                                .subFlowMapping(Platform.ANDROID, androidFlow -> androidFlow.handle(PushNotification.class, firebaseSender::sendPush))
                                .subFlowMapping(Platform.IOS, iosFlow -> iosFlow.handle(PushNotification.class, apnsSender::sendPush))
                                .subFlowMapping(Platform.HUAWEI, huaweiFlow -> huaweiFlow.handle(PushNotification.class, huaweiSender::sendPush))
                )
                .aggregate(aggregatorSpec -> aggregatorSpec.correlationStrategy(message -> message.getHeaders().get(TracingConstants.CORRELATION_ID)))
                .handle((p,h) -> {
                     log.info("log: {}", p);
                     //handling logic
                     return null;
                });
    }
}
Share Improve this question asked Nov 25, 2024 at 15:40 Simone FranchinaSimone Franchina 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

It is not clear what Spring Integration version you use, but try to add .defaultOutputToParentFlow() to that routerSpec configuration.

Also would be great to know a signature of your sendPush and if it really returns something what should go down to the aggregate.

本文标签: spring integrationSplitrouteaggregation logic doesn39t workStack Overflow