Home > Blockchain >  Spring Integration storing data
Spring Integration storing data

Time:04-07

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.

CodePudding user response:

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) {
  • Related