Search in sources :

Example 1 with FixedSubscriberChannelPrototype

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

the class IntegrationFlowDefinition method register.

@SuppressWarnings("unchecked")
private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) {
    if (endpointConfigurer != null) {
        endpointConfigurer.accept(endpointSpec);
    }
    MessageChannel inputChannel = this.currentMessageChannel;
    this.currentMessageChannel = null;
    if (inputChannel == null) {
        inputChannel = new DirectChannel();
        this.registerOutputChannelIfCan(inputChannel);
    }
    Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get();
    addComponents(endpointSpec.getComponentsToRegister());
    if (inputChannel instanceof MessageChannelReference) {
        factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName());
    } else {
        if (inputChannel instanceof FixedSubscriberChannelPrototype) {
            String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName();
            inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2());
            if (beanName != null) {
                ((FixedSubscriberChannel) inputChannel).setBeanName(beanName);
            }
            registerOutputChannelIfCan(inputChannel);
        }
        factoryBeanTuple2.getT1().setInputChannel(inputChannel);
    }
    return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2());
}
Also used : MessageChannelReference(org.springframework.integration.dsl.support.MessageChannelReference) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) ConsumerEndpointFactoryBean(org.springframework.integration.config.ConsumerEndpointFactoryBean) DirectChannel(org.springframework.integration.channel.DirectChannel) FixedSubscriberChannelPrototype(org.springframework.integration.dsl.support.FixedSubscriberChannelPrototype) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel)

Example 2 with FixedSubscriberChannelPrototype

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

the class IntegrationFlowDefinition method registerOutputChannelIfCan.

private B registerOutputChannelIfCan(MessageChannel outputChannel) {
    if (!(outputChannel instanceof FixedSubscriberChannelPrototype)) {
        this.integrationComponents.put(outputChannel, null);
        if (this.currentComponent != null) {
            String channelName = null;
            if (outputChannel instanceof MessageChannelReference) {
                channelName = ((MessageChannelReference) outputChannel).getName();
            }
            Object currentComponent = this.currentComponent;
            if (AopUtils.isAopProxy(currentComponent)) {
                currentComponent = extractProxyTarget(currentComponent);
            }
            if (currentComponent instanceof MessageProducer) {
                MessageProducer messageProducer = (MessageProducer) currentComponent;
                checkReuse(messageProducer);
                if (channelName != null) {
                    if (messageProducer instanceof AbstractMessageProducingHandler) {
                        ((AbstractMessageProducingHandler) messageProducer).setOutputChannelName(channelName);
                    } else {
                        throw new BeanCreationException("The 'currentComponent' (" + currentComponent + ") must extend 'AbstractMessageProducingHandler' " + "for message channel resolution by name.\n" + "Your handler should extend 'AbstractMessageProducingHandler', " + "its subclass 'AbstractReplyProducingMessageHandler', or you should " + "reference a 'MessageChannel' bean instead of its name.");
                    }
                } else {
                    messageProducer.setOutputChannel(outputChannel);
                }
            } else if (currentComponent instanceof SourcePollingChannelAdapterSpec) {
                SourcePollingChannelAdapterFactoryBean pollingChannelAdapterFactoryBean = ((SourcePollingChannelAdapterSpec) currentComponent).get().getT1();
                if (channelName != null) {
                    pollingChannelAdapterFactoryBean.setOutputChannelName(channelName);
                } else {
                    pollingChannelAdapterFactoryBean.setOutputChannel(outputChannel);
                }
            } else {
                throw new BeanCreationException("The 'currentComponent' (" + currentComponent + ") is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. " + "This is the end of the integration flow.");
            }
            this.currentComponent = null;
        }
    }
    return _this();
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) MessageChannelReference(org.springframework.integration.dsl.support.MessageChannelReference) FixedSubscriberChannelPrototype(org.springframework.integration.dsl.support.FixedSubscriberChannelPrototype) SourcePollingChannelAdapterFactoryBean(org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean) AbstractMessageProducingHandler(org.springframework.integration.handler.AbstractMessageProducingHandler) MessageProducer(org.springframework.integration.core.MessageProducer)

Aggregations

FixedSubscriberChannelPrototype (org.springframework.integration.dsl.support.FixedSubscriberChannelPrototype)2 MessageChannelReference (org.springframework.integration.dsl.support.MessageChannelReference)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 FixedSubscriberChannel (org.springframework.integration.channel.FixedSubscriberChannel)1 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)1 ConsumerEndpointFactoryBean (org.springframework.integration.config.ConsumerEndpointFactoryBean)1 SourcePollingChannelAdapterFactoryBean (org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean)1 MessageProducer (org.springframework.integration.core.MessageProducer)1 AbstractMessageProducingHandler (org.springframework.integration.handler.AbstractMessageProducingHandler)1 MessageChannel (org.springframework.messaging.MessageChannel)1