Java Code Examples for org.springframework.cloud.function.context.FunctionRegistration#type()
The following examples show how to use
org.springframework.cloud.function.context.FunctionRegistration#type() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KotlinLambdaToFunctionAutoConfiguration.java From spring-cloud-function with Apache License 2.0 | 6 votes |
@Override public FunctionRegistration getObject() throws Exception { String name = this.name.endsWith(FunctionRegistration.REGISTRATION_NAME_SUFFIX) ? this.name.replace(FunctionRegistration.REGISTRATION_NAME_SUFFIX, "") : this.name; Type functionType = FunctionContextUtils.findType(name, this.beanFactory); FunctionRegistration<?> registration = new FunctionRegistration<>(this, name); Type[] types = ((ParameterizedType) functionType).getActualTypeArguments(); if (functionType.getTypeName().contains("Function0")) { functionType = ResolvableType.forClassWithGenerics(Supplier.class, ResolvableType.forType(types[0])) .getType(); } else if (functionType.getTypeName().contains("Function1")) { functionType = ResolvableType.forClassWithGenerics(Function.class, ResolvableType.forType(types[0]), ResolvableType.forType(types[1])).getType(); } else { throw new UnsupportedOperationException("Multi argument Kotlin functions are not currently supported"); } registration = registration.type(functionType); return registration; }
Example 2
Source File: FunctionExporterAutoConfiguration.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(prefix = "spring.cloud.function.web.export.source", name = "url") public FunctionRegistration<Supplier<Flux<?>>> origin(WebClient.Builder builder) { HttpSupplier supplier = new HttpSupplier(builder.build(), this.props); FunctionRegistration<Supplier<Flux<?>>> registration = new FunctionRegistration<>(supplier); FunctionType type = FunctionType.supplier(this.props.getSource().getType()).wrap(Flux.class); if (this.props.getSource().isIncludeHeaders()) { type = type.message(); } registration = registration.type(type); return registration; }
Example 3
Source File: AbstractComposableFunctionRegistry.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Override public FunctionRegistration<?> getRegistration(Object function) { String functionName = function == null ? null : this.lookupFunctionName(function); if (StringUtils.hasText(functionName)) { FunctionRegistration<?> registration = new FunctionRegistration<Object>( function, functionName); FunctionType functionType = this.findType(registration, functionName); return registration.type(functionType.getType()); } return null; }
Example 4
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void dynamicBindingTestWithFunctionRegistrationAndExplicitDestination() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(EmptyConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.function-in-0.destination=input")) { InputDestination input = context.getBean(InputDestination.class); try { input.send(new GenericMessage<byte[]>("hello".getBytes())); fail(); // it should since there are no functions and no bindings } catch (Exception e) { // good, we expected it } Function<byte[], byte[]> function = v -> v; FunctionRegistration functionRegistration = new FunctionRegistration(function, "function"); functionRegistration = functionRegistration.type(FunctionType.from(byte[].class).to(byte[].class)); FunctionBindingTestUtils.bind(context, functionRegistration); input.send(new GenericMessage<byte[]>("hello".getBytes()), "input"); OutputDestination output = context.getBean(OutputDestination.class); assertThat(output.receive(1000, "function-out-0").getPayload()).isEqualTo("hello".getBytes()); } }