Skip to content

Wrong functionType is determined for the FunctionInvocationWrapper #409

Closed
@artembilan

Description

@artembilan

We have a bean like this:

@Bean
Scheduler reactiveScheduler() {
	return Schedulers.elastic();
}

where a target instance is a Supplier, according Schedulers.CachedScheduler extension. And this one is registered in the FunctionCatalog as a Supplier.
But at the same time it looks like functionType for the FunctionInvocationWrapper is determined from the bean definition type.
And in this case we have a plain:

public interface Scheduler extends Disposable {

so, that Disposable is set into the functionType, which leads to an exception like this when we perform function lookup:

Caused by: java.lang.IllegalArgumentException: Must be one of Supplier, Function, Consumer or FunctionRegistration. Was interface reactor.core.Disposable
    at org.springframework.util.Assert.isTrue(Assert.java:118)
    at org.springframework.cloud.function.context.catalog.FunctionTypeUtils.assertSupportedTypes(FunctionTypeUtils.java:390)
    at org.springframework.cloud.function.context.catalog.FunctionTypeUtils.getInputType(FunctionTypeUtils.java:176)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionChannelBindingInitializer.bindSimpleFunctions(FunctionConfiguration.java:377)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionChannelBindingInitializer.bindOrComposeSimpleFunctions(FunctionConfiguration.java:353)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionChannelBindingInitializer.lambda$afterPropertiesSet$0(FunctionConfiguration.java:261)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionChannelBindingInitializer.afterPropertiesSet(FunctionConfiguration.java:251)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
    ... 64 common frames omitted

For me it sounds like we really need to check a bean definition type (not the target object) before registering into the FunctionCatalog.

Also would be great to improve that exception message to let us know which bean is guilty.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions