0

I am trying to store the log information in the database in spring integration. code below..

Main flow:

  @Bean
    public IntegrationFlow httpReq() {
            return IntegrationFlows.from(Http.inboundGateway("/foo")
                            .requestMapping(m -> m.methods(HttpMethod.POST)
                                   ).errorChannel("errorhandler.input")
                            .validator(new Validator()))
                    .transform(Transformers.objectToString())
                    .transform(new ObjectToXMlTransformer()).wireTap("subscribeChannel").bridge()
                    .get();
       
    }

storing flow

   @Bean
    public IntegrationFlow dbHandler(EntityManagerFactory entity) {
        return f -> f
                .transform(new AbstractPayloadTransformer<String,EntityClass>() {

                    @Override
                    protected EntityClass transformPayload(String payload) {
                        return new EntityClass(payload);

                    }
                })
                .handle(Jpa.outboundAdapter(entity)
                        .entityClass(EntityClass.class)
                        .persistMode(PersistMode.PERSIST), e -> e.transactional(true));
    }

This is my channel:


  @Bean
    public SubscribableChannel subscribeChannel() {
        return MessageChannels.publishSubscribe("subscribeChannel")
                .get();
    }
 @Autowired
    private EntityManagerFactory entityManagerFactory;

   @Bean
    public IntegrationFlow subscribeFlow() {
        return IntegrationFlows.from("subscribeChannel")
                .bridge().handle(logger()).handle(dbHandler(entityManagerFactory)).get();
    }

I am getting an error that the there is an ambiguous parameter type found. This is the error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subscribeFlow' defined in class path resource [com/example/demo/configuration/IntegrationConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'subscribeFlow' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Void] for method match: [public abstract void org.springframework.integration.dsl.IntegrationFlow.configure(org.springframework.integration.dsl.IntegrationFlowDefinition), public default org.springframework.messaging.MessageChannel org.springframework.integration.dsl.IntegrationFlow.getInputChannel()]

any ideas for a solution? Thanks.

Bash
  • 101
  • 11

1 Answers1

0

The IntegrationFlow is not a service to be called from the handle().

I don't see a reason in that subscribeFlow in your case. Just consider to start your dbHandler flow like that one - IntegrationFlows.from("subscribeChannel").

If you still insist to have it divided to so many flows, consider to use a to(IntegrationFlow) operator:

/**
 * Finish this flow with delegation to other {@link IntegrationFlow} instance.
 * @param other the {@link IntegrationFlow} to compose with.
 * @return The {@link IntegrationFlow} instance based on this definition.
 * @since 5.5.4
 */
public IntegrationFlow to(IntegrationFlow other) {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • i have tried to do this ```return IntegrationFlows.from(subscribeFlow())``` In the dbHandler flow but i got this error ```The 'IntegrationFlow' to start from must end with a 'MessageChannel' or reply-producing endpoint to let the result from that flow to be processed in this instance. The provided flow ends with: bean 'subscribeFlow``` Did i get your point wrong ? – Bash Apr 05 '22 at 19:02
  • I'm not sure why do you need to do that. Why just don't have that `wireTap("subscribeChannel")` and `IntegrationFlows.from("subscribeChannel")` in the `dbHandler`? That `subscribeFlow` must go altogether. I fully don't see reason in it . – Artem Bilan Apr 05 '22 at 19:10
  • I have tried that as well but i got an error which says ```The 'currentComponent' (org.springframework.integration.handler.LoggingHandler@b1d7b09) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'``` – Bash Apr 05 '22 at 19:17
  • 1
    You probably still refer to that `subscribeFlow` which I'm asking you to remove. Of course that `.handle(logger())` has to be the last component in the flow. It does not return anything to produce a message for the next `handle()` endpoint. But if you stop using this `subscribeFlow`, there won't be a question like that. – Artem Bilan Apr 05 '22 at 19:20