Search in sources :

Example 6 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-integration by spring-projects.

the class MessagingGatewaySupport method registerReplyMessageCorrelatorIfNecessary.

protected void registerReplyMessageCorrelatorIfNecessary() {
    MessageChannel replyChannel = getReplyChannel();
    if (replyChannel != null && this.replyMessageCorrelator == null) {
        boolean shouldStartCorrelator;
        synchronized (this.replyMessageCorrelatorMonitor) {
            if (this.replyMessageCorrelator != null) {
                return;
            }
            AbstractEndpoint correlator;
            BridgeHandler handler = new BridgeHandler();
            if (getBeanFactory() != null) {
                handler.setBeanFactory(getBeanFactory());
            }
            handler.afterPropertiesSet();
            if (replyChannel instanceof SubscribableChannel) {
                correlator = new EventDrivenConsumer((SubscribableChannel) replyChannel, handler);
            } else if (replyChannel instanceof PollableChannel) {
                PollingConsumer endpoint = new PollingConsumer((PollableChannel) replyChannel, handler);
                endpoint.setBeanFactory(getBeanFactory());
                endpoint.setReceiveTimeout(this.replyTimeout);
                endpoint.afterPropertiesSet();
                correlator = endpoint;
            } else if (replyChannel instanceof ReactiveStreamsSubscribableChannel) {
                ReactiveStreamsConsumer endpoint = new ReactiveStreamsConsumer(replyChannel, (Subscriber<Message<?>>) handler);
                endpoint.afterPropertiesSet();
                correlator = endpoint;
            } else {
                throw new MessagingException("Unsupported 'replyChannel' type [" + replyChannel.getClass() + "]." + "SubscribableChannel or PollableChannel type are supported.");
            }
            this.replyMessageCorrelator = correlator;
            shouldStartCorrelator = true;
        }
        if (shouldStartCorrelator && isRunning()) {
            if (isRunning()) {
                this.replyMessageCorrelator.start();
            }
        }
    }
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) MessageChannel(org.springframework.messaging.MessageChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) BridgeHandler(org.springframework.integration.handler.BridgeHandler) MessagingException(org.springframework.messaging.MessagingException) PollableChannel(org.springframework.messaging.PollableChannel) ReactiveStreamsSubscribableChannel(org.springframework.integration.channel.ReactiveStreamsSubscribableChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ReactiveStreamsSubscribableChannel(org.springframework.integration.channel.ReactiveStreamsSubscribableChannel)

Example 7 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-integration by spring-projects.

the class BridgeParserTests method bridgeWithSendTimeout.

@Test
public void bridgeWithSendTimeout() {
    BridgeHandler handler = (BridgeHandler) new DirectFieldAccessor(bridgeWithSendTimeout).getPropertyValue("handler");
    MessagingTemplate template = (MessagingTemplate) new DirectFieldAccessor(handler).getPropertyValue("messagingTemplate");
    assertEquals(new Long(1234), new DirectFieldAccessor(template).getPropertyValue("sendTimeout"));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) BridgeHandler(org.springframework.integration.handler.BridgeHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 8 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-integration by spring-projects.

the class FailoverClientConnectionFactoryTests method testFailoverCachedWithGateway.

@SuppressWarnings("unchecked")
@Test
public void testFailoverCachedWithGateway() throws Exception {
    final TcpNetServerConnectionFactory server = new TcpNetServerConnectionFactory(0);
    server.setBeanName("server");
    server.afterPropertiesSet();
    DirectChannel inChannel = new DirectChannel();
    inChannel.setBeanName("inChannel");
    TcpInboundGateway inbound = new TcpInboundGateway();
    inbound.setConnectionFactory(server);
    inbound.setRequestChannel(inChannel);
    inbound.afterPropertiesSet();
    inChannel.subscribe(new BridgeHandler());
    inbound.start();
    TestingUtilities.waitListening(server, 10000L);
    int port = server.getPort();
    AbstractClientConnectionFactory client = new TcpNetClientConnectionFactory("localhost", port);
    client.setBeanName("client");
    // Cache
    CachingClientConnectionFactory cachingClient = new CachingClientConnectionFactory(client, 2);
    cachingClient.setBeanName("cache");
    cachingClient.afterPropertiesSet();
    // Failover
    List<AbstractClientConnectionFactory> clientFactories = new ArrayList<AbstractClientConnectionFactory>();
    clientFactories.add(cachingClient);
    FailoverClientConnectionFactory failoverClient = new FailoverClientConnectionFactory(clientFactories);
    failoverClient.setSingleUse(true);
    failoverClient.afterPropertiesSet();
    TcpOutboundGateway outbound = new TcpOutboundGateway();
    outbound.setConnectionFactory(failoverClient);
    QueueChannel replyChannel = new QueueChannel();
    replyChannel.setBeanName("replyChannel");
    outbound.setReplyChannel(replyChannel);
    outbound.setBeanFactory(mock(BeanFactory.class));
    outbound.afterPropertiesSet();
    outbound.start();
    outbound.handleMessage(new GenericMessage<String>("foo"));
    Message<byte[]> result = (Message<byte[]>) replyChannel.receive(10000);
    assertNotNull(result);
    assertEquals("foo", new String(result.getPayload()));
    // INT-4024 - second reply had bad connection id
    outbound.handleMessage(new GenericMessage<String>("foo"));
    result = (Message<byte[]>) replyChannel.receive(10000);
    assertNotNull(result);
    assertEquals("foo", new String(result.getPayload()));
    inbound.stop();
    outbound.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) BridgeHandler(org.springframework.integration.handler.BridgeHandler) ArrayList(java.util.ArrayList) TcpOutboundGateway(org.springframework.integration.ip.tcp.TcpOutboundGateway) TcpInboundGateway(org.springframework.integration.ip.tcp.TcpInboundGateway) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 9 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-integration by spring-projects.

the class BridgeFromAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    BridgeHandler handler = new BridgeHandler();
    Object outputChannel = resolveTargetBeanFromMethodWithBeanAnnotation(method);
    Assert.isInstanceOf(MessageChannel.class, outputChannel);
    handler.setOutputChannel((MessageChannel) outputChannel);
    return handler;
}
Also used : BridgeHandler(org.springframework.integration.handler.BridgeHandler)

Example 10 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-integration by spring-projects.

the class BridgeToAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    BridgeHandler handler = new BridgeHandler();
    String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "value", String.class);
    if (StringUtils.hasText(outputChannelName)) {
        handler.setOutputChannelName(outputChannelName);
    }
    return handler;
}
Also used : BridgeHandler(org.springframework.integration.handler.BridgeHandler)

Aggregations

BridgeHandler (org.springframework.integration.handler.BridgeHandler)11 SubscribableChannel (org.springframework.messaging.SubscribableChannel)5 MessageChannel (org.springframework.messaging.MessageChannel)3 Test (org.junit.Test)2 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 Message (org.springframework.messaging.Message)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 Bean (org.springframework.context.annotation.Bean)1 FixedSubscriberChannel (org.springframework.integration.channel.FixedSubscriberChannel)1 PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 ReactiveStreamsSubscribableChannel (org.springframework.integration.channel.ReactiveStreamsSubscribableChannel)1