Ali
Ali

Reputation: 450

Pass a message from ServiceActivator to new InboundChannelAdapter

I have implemented Spring (boot) integration, i have a InboundChannelAdapter and this method sending a web request via RestTemplate, and pass result to Splitter, Filter, And finally to a ServiceActivator, ServiceActivator saving the data into database. I want to pass message to a new "InboundChannelAdapter" in order to some additional process on the message after saving data into database, What should i do in order to implement this?
Is my solution right solution?

@InboundChannelAdapter(value = "channel1", poller = @Poller("downloadTrigger"))
public ResponseEntity<AppsItemParser[]> download()
{
    String url = config.getUrl();
    // Call a rest webservice
    return responseEntity;
}

@Splitter(inputChannel = "channel1", outputChannel = "channel2")
public List<AppsItemParser> scrape(ResponseEntity<AppsItemParser[]> payload)
{
    return new ArrayList<AppsItemParser>(Arrays.asList(payload.getBody()));
}

@Transformer(inputChannel = "channel2", outputChannel = "channel3")
public App convert(AppsItemParser payload)
{
    App app = new App();
    app.setAddDate(payload.getAddDate());
    app.setSize(payload.getSize());

    return app;
}

@Filter(inputChannel = "channel3", outputChannel = "channel4")
public boolean filter(App app)
{
    final Set<ConstraintViolation<App>> violations = validator.validate(app);
    if (violations != null && !violations.isEmpty())
    {
        return false;
    }
    return true;
}

  @ServiceActivator(inputChannel = "channel4")
    public void save(App app)
    {
        appRepository.save(app);
        //Send message to another spring integration flow
    }

Upvotes: 0

Views: 574

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

Inbound channel adapters define the start of a flow; they do not receive messages from other components; instead, have your service return a result...

@ServiceActivator(inputChannel = "channel4", outputChannel="next")
public App save(App app)
{
    appRepository.save(app);
    return app;
}

or

@ServiceActivator(inputChannel = "channel4", outputChannel="next")
public SomeResult save(App app)
{
    appRepository.save(app);
    return new SomeResult(...);
}

Upvotes: 2

Related Questions