Search in sources :

Example 1 with FixedSubscriberChannel

use of org.springframework.integration.channel.FixedSubscriberChannel in project spring-integration by spring-projects.

the class ConsumerEndpointFactoryBean method initializeEndpoint.

@SuppressWarnings("unchecked")
private void initializeEndpoint() throws Exception {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        MessageChannel channel = null;
        if (StringUtils.hasText(this.inputChannelName)) {
            channel = this.channelResolver.resolveDestination(this.inputChannelName);
        }
        if (this.inputChannel != null) {
            channel = this.inputChannel;
        }
        Assert.state(channel != null, "one of inputChannelName or inputChannel is required");
        if (channel instanceof SubscribableChannel) {
            Assert.isNull(this.pollerMetadata, "A poller should not be specified for endpoint '" + this.beanName + "', since '" + channel + "' is a SubscribableChannel (not pollable).");
            this.endpoint = new EventDrivenConsumer((SubscribableChannel) channel, this.handler);
            if (logger.isWarnEnabled() && Boolean.FALSE.equals(this.autoStartup) && channel instanceof FixedSubscriberChannel) {
                logger.warn("'autoStartup=\"false\"' has no effect when using a FixedSubscriberChannel");
            }
        } else if (channel instanceof PollableChannel) {
            PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler);
            if (this.pollerMetadata == null) {
                this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
                Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName + "', and no default poller is available within the context.");
            }
            pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
            pollingConsumer.setTrigger(this.pollerMetadata.getTrigger());
            pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain());
            pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());
            pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler());
            pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout());
            pollingConsumer.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory());
            pollingConsumer.setBeanClassLoader(this.beanClassLoader);
            pollingConsumer.setBeanFactory(this.beanFactory);
            this.endpoint = pollingConsumer;
        } else {
            this.endpoint = new ReactiveStreamsConsumer(channel, this.handler);
        }
        this.endpoint.setBeanName(this.beanName);
        this.endpoint.setBeanFactory(this.beanFactory);
        if (this.autoStartup != null) {
            this.endpoint.setAutoStartup(this.autoStartup);
        }
        int phase = this.phase;
        if (!this.isPhaseSet && this.endpoint instanceof PollingConsumer) {
            phase = Integer.MAX_VALUE / 2;
        }
        this.endpoint.setPhase(phase);
        this.endpoint.setRole(this.role);
        if (this.taskScheduler != null) {
            this.endpoint.setTaskScheduler(this.taskScheduler);
        }
        this.endpoint.afterPropertiesSet();
        this.initialized = true;
    }
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel)

Example 2 with FixedSubscriberChannel

use of org.springframework.integration.channel.FixedSubscriberChannel in project spring-integration by spring-projects.

the class FixedSubscriberChannelBeanFactoryPostProcessor method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        if (this.candidateFixedChannelHandlerMap.size() > 0) {
            for (Entry<String, String> entry : this.candidateFixedChannelHandlerMap.entrySet()) {
                String handlerName = entry.getKey();
                String channelName = entry.getValue();
                BeanDefinition handlerBeanDefinition = null;
                if (registry.containsBeanDefinition(handlerName)) {
                    handlerBeanDefinition = registry.getBeanDefinition(handlerName);
                }
                if (handlerBeanDefinition != null && registry.containsBeanDefinition(channelName)) {
                    BeanDefinition inputChannelDefinition = registry.getBeanDefinition(channelName);
                    if (FixedSubscriberChannel.class.getName().equals(inputChannelDefinition.getBeanClassName())) {
                        ConstructorArgumentValues constructorArgumentValues = inputChannelDefinition.getConstructorArgumentValues();
                        Assert.isTrue(constructorArgumentValues.isEmpty(), "Only one subscriber is allowed for a FixedSubscriberChannel.");
                        constructorArgumentValues.addGenericArgumentValue(handlerBeanDefinition);
                    }
                }
            }
        }
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 3 with FixedSubscriberChannel

use of org.springframework.integration.channel.FixedSubscriberChannel 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 4 with FixedSubscriberChannel

use of org.springframework.integration.channel.FixedSubscriberChannel in project spring-integration by spring-projects.

the class ScatterGatherHandler method doInit.

@Override
protected void doInit() {
    if (this.gatherChannel == null) {
        this.gatherChannel = new FixedSubscriberChannel(this.gatherer);
    } else {
        if (this.gatherChannel instanceof SubscribableChannel) {
            this.gatherEndpoint = new EventDrivenConsumer((SubscribableChannel) this.gatherChannel, this.gatherer);
        } else if (this.gatherChannel instanceof PollableChannel) {
            this.gatherEndpoint = new PollingConsumer((PollableChannel) this.gatherChannel, this.gatherer);
            ((PollingConsumer) this.gatherEndpoint).setReceiveTimeout(this.gatherTimeout);
        } else {
            throw new MessagingException("Unsupported 'replyChannel' type [" + this.gatherChannel.getClass() + "]." + "SubscribableChannel or PollableChannel type are supported.");
        }
        this.gatherEndpoint.setBeanFactory(this.getBeanFactory());
        this.gatherEndpoint.afterPropertiesSet();
    }
    ((MessageProducer) this.gatherer).setOutputChannel(new FixedSubscriberChannel(message -> {
        MessageHeaders headers = message.getHeaders();
        if (headers.containsKey(GATHER_RESULT_CHANNEL)) {
            Object gatherResultChannel = headers.get(GATHER_RESULT_CHANNEL);
            if (gatherResultChannel instanceof MessageChannel) {
                messagingTemplate.send((MessageChannel) gatherResultChannel, message);
            } else if (gatherResultChannel instanceof String) {
                messagingTemplate.send((String) gatherResultChannel, message);
            }
        } else {
            throw new MessageDeliveryException(message, "The 'gatherResultChannel' header is required to delivery gather result.");
        }
    }));
    this.replyChannelRegistry = getBeanFactory().getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, HeaderChannelRegistry.class);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) HeaderChannelRegistry(org.springframework.integration.support.channel.HeaderChannelRegistry) ClassUtils(org.springframework.util.ClassUtils) AopUtils(org.springframework.aop.support.AopUtils) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) MessageProducer(org.springframework.integration.core.MessageProducer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) MessageChannel(org.springframework.messaging.MessageChannel) MessageHeaders(org.springframework.messaging.MessageHeaders) IntegrationContextUtils(org.springframework.integration.context.IntegrationContextUtils) Lifecycle(org.springframework.context.Lifecycle) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageHandler(org.springframework.messaging.MessageHandler) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel) Message(org.springframework.messaging.Message) PollableChannel(org.springframework.messaging.PollableChannel) Assert(org.springframework.util.Assert) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) MessagingException(org.springframework.messaging.MessagingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) HeaderChannelRegistry(org.springframework.integration.support.channel.HeaderChannelRegistry) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) MessageProducer(org.springframework.integration.core.MessageProducer) MessageHeaders(org.springframework.messaging.MessageHeaders) SubscribableChannel(org.springframework.messaging.SubscribableChannel) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel)

Example 5 with FixedSubscriberChannel

use of org.springframework.integration.channel.FixedSubscriberChannel in project spring-integration by spring-projects.

the class UdpSyslogReceivingChannelAdapter method onInit.

@Override
protected void onInit() {
    super.onInit();
    if (this.udpAdapter == null) {
        this.udpAdapter = new UnicastReceivingChannelAdapter(getPort());
        this.udpAdapter.setBeanFactory(getBeanFactory());
    } else {
        logger.info("The 'UdpSyslogReceivingChannelAdapter' overrides an 'outputChannel' " + "of the provided 'UnicastReceivingChannelAdapter' to support Syslog conversion " + "for the incoming UDP packets");
    }
    this.udpAdapter.setOutputChannel(new FixedSubscriberChannel(message -> convertAndSend(message)));
    if (!this.udpAdapterSet) {
        this.udpAdapter.afterPropertiesSet();
    }
}
Also used : FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel) UnicastReceivingChannelAdapter(org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter) UnicastReceivingChannelAdapter(org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel)

Aggregations

FixedSubscriberChannel (org.springframework.integration.channel.FixedSubscriberChannel)9 MessageChannel (org.springframework.messaging.MessageChannel)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)3 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)2 ConsumerEndpointFactoryBean (org.springframework.integration.config.ConsumerEndpointFactoryBean)2 MessageChannelReference (org.springframework.integration.dsl.support.MessageChannelReference)2 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)2 MessageHandler (org.springframework.messaging.MessageHandler)2 PollableChannel (org.springframework.messaging.PollableChannel)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 Assert (org.springframework.util.Assert)2 Collection (java.util.Collection)1 AopUtils (org.springframework.aop.support.AopUtils)1