Search in sources :

Example 1 with IntegrationFlowBuilder

use of org.springframework.integration.dsl.IntegrationFlowBuilder in project spring-cloud-stream by spring-cloud.

the class FunctionConfiguration method integrationFlowFromProvidedSupplier.

@SuppressWarnings({ "rawtypes", "unchecked" })
private IntegrationFlowBuilder integrationFlowFromProvidedSupplier(Supplier<?> supplier, Publisher<Object> beginPublishingTrigger, PollableBean pollable, GenericApplicationContext context, TaskScheduler taskScheduler, ProducerProperties producerProperties, String bindingName) {
    IntegrationFlowBuilder integrationFlowBuilder;
    boolean splittable = pollable != null && (boolean) AnnotationUtils.getAnnotationAttributes(pollable).get("splittable");
    FunctionInvocationWrapper function = (supplier instanceof PartitionAwareFunctionWrapper) ? (FunctionInvocationWrapper) ((PartitionAwareFunctionWrapper) supplier).function : (FunctionInvocationWrapper) supplier;
    boolean reactive = FunctionTypeUtils.isPublisher(function.getOutputType());
    if (pollable == null && reactive) {
        Publisher publisher = (Publisher) supplier.get();
        publisher = publisher instanceof Mono ? ((Mono) publisher).delaySubscription(beginPublishingTrigger).map(this::wrapToMessageIfNecessary) : ((Flux) publisher).delaySubscription(beginPublishingTrigger).map(this::wrapToMessageIfNecessary);
        integrationFlowBuilder = IntegrationFlows.from(publisher);
        // see https://github.com/spring-cloud/spring-cloud-stream/issues/1863 for details about the following code
        // will keep AC alive
        taskScheduler.schedule(() -> {
        }, Instant.now());
    } else {
        // implies pollable
        boolean autoStartup = producerProperties != null ? producerProperties.isAutoStartup() : true;
        integrationFlowBuilder = IntegrationFlows.fromSupplier(supplier, spca -> spca.id(bindingName + "_spca").autoStartup(autoStartup));
        // only apply the PollableBean attributes if this is a reactive function.
        if (splittable && reactive) {
            integrationFlowBuilder = integrationFlowBuilder.split();
        }
    }
    return integrationFlowBuilder;
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) Arrays(java.util.Arrays) BindingCreatedEvent(org.springframework.cloud.stream.binder.BindingCreatedEvent) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) IntegrationFlowBuilder(org.springframework.integration.dsl.IntegrationFlowBuilder) BindingServiceConfiguration(org.springframework.cloud.stream.config.BindingServiceConfiguration) Tuples(reactor.util.function.Tuples) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ContextFunctionCatalogAutoConfiguration(org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) RoutingFunction(org.springframework.cloud.function.context.config.RoutingFunction) Map(java.util.Map) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageUtils(org.springframework.cloud.function.context.message.MessageUtils) Method(java.lang.reflect.Method) ClassUtils(org.springframework.util.ClassUtils) MethodMetadata(org.springframework.core.type.MethodMetadata) AbstractSubscribableChannel(org.springframework.integration.channel.AbstractSubscribableChannel) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Set(java.util.Set) TaskScheduler(org.springframework.scheduling.TaskScheduler) Instant(java.time.Instant) MessageChannel(org.springframework.messaging.MessageChannel) SupportedBindableFeatures(org.springframework.cloud.stream.binding.SupportedBindableFeatures) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Type(java.lang.reflect.Type) Environment(org.springframework.core.env.Environment) CollectionUtils(org.springframework.util.CollectionUtils) LogFactory(org.apache.commons.logging.LogFactory) FunctionCatalog(org.springframework.cloud.function.context.FunctionCatalog) IntegrationReactiveUtils(org.springframework.integration.util.IntegrationReactiveUtils) CloudEventMessageUtils(org.springframework.cloud.function.cloudevent.CloudEventMessageUtils) FunctionInvocationWrapper(org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) ApplicationContextAware(org.springframework.context.ApplicationContextAware) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) MessagingException(org.springframework.messaging.MessagingException) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) SubscribableChannel(org.springframework.messaging.SubscribableChannel) MonoSink(reactor.core.publisher.MonoSink) PollableBean(org.springframework.cloud.function.context.PollableBean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InitializingBean(org.springframework.beans.factory.InitializingBean) ArrayList(java.util.ArrayList) AutoConfigureAfter(org.springframework.boot.autoconfigure.AutoConfigureAfter) MessageBuilder(org.springframework.integration.support.MessageBuilder) NewDestinationBindingCallback(org.springframework.cloud.stream.binding.NewDestinationBindingCallback) BinderFactoryAutoConfiguration(org.springframework.cloud.stream.config.BinderFactoryAutoConfiguration) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) FunctionTypeUtils(org.springframework.cloud.function.context.catalog.FunctionTypeUtils) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) IntegrationFlows(org.springframework.integration.dsl.IntegrationFlows) Nullable(org.springframework.lang.Nullable) Message(org.springframework.messaging.Message) BindableProxyFactory(org.springframework.cloud.stream.binding.BindableProxyFactory) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Iterator(java.util.Iterator) Publisher(org.reactivestreams.Publisher) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) ObjectUtils(org.springframework.util.ObjectUtils) Import(org.springframework.context.annotation.Import) Mono(reactor.core.publisher.Mono) BeansException(org.springframework.beans.BeansException) AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) Field(java.lang.reflect.Field) FunctionProperties(org.springframework.cloud.function.context.FunctionProperties) ApplicationContext(org.springframework.context.ApplicationContext) MessageHeaders(org.springframework.messaging.MessageHeaders) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Flux(reactor.core.publisher.Flux) ParameterizedType(java.lang.reflect.ParameterizedType) FunctionContextUtils(org.springframework.cloud.function.context.config.FunctionContextUtils) EnvironmentAware(org.springframework.context.EnvironmentAware) ReflectionUtils(org.springframework.util.ReflectionUtils) Log(org.apache.commons.logging.Log) FunctionRegistry(org.springframework.cloud.function.context.FunctionRegistry) Bean(org.springframework.context.annotation.Bean) AutoConfigureBefore(org.springframework.boot.autoconfigure.AutoConfigureBefore) Collections(java.util.Collections) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) FunctionInvocationWrapper(org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper) Mono(reactor.core.publisher.Mono) Publisher(org.reactivestreams.Publisher) IntegrationFlowBuilder(org.springframework.integration.dsl.IntegrationFlowBuilder)

Example 2 with IntegrationFlowBuilder

use of org.springframework.integration.dsl.IntegrationFlowBuilder in project spring-integration by spring-projects.

the class AmqpTests method testTemplateChannelTransacted.

@Test
public void testTemplateChannelTransacted() {
    IntegrationFlowBuilder flow = IntegrationFlows.from(Amqp.channel("testTemplateChannelTransacted", this.rabbitConnectionFactory).autoStartup(false).templateChannelTransacted(true));
    assertTrue(TestUtils.getPropertyValue(flow, "currentMessageChannel.amqpTemplate.transactional", Boolean.class));
}
Also used : IntegrationFlowBuilder(org.springframework.integration.dsl.IntegrationFlowBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Field (java.lang.reflect.Field)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Test (org.junit.jupiter.api.Test)1 Publisher (org.reactivestreams.Publisher)1