Search in sources :

Example 11 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class RmiOutboundGateway method createProxy.

private RequestReplyExchanger createProxy(String url) {
    RmiProxyFactoryBean proxyFactory = new RmiProxyFactoryBean();
    proxyFactory.setServiceInterface(RequestReplyExchanger.class);
    proxyFactory.setServiceUrl(url);
    proxyFactory.setLookupStubOnStartup(false);
    proxyFactory.setRefreshStubOnConnectFailure(true);
    if (this.configurer != null) {
        this.configurer.configure(proxyFactory);
    }
    proxyFactory.afterPropertiesSet();
    return (RequestReplyExchanger) proxyFactory.getObject();
}
Also used : RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) RmiProxyFactoryBean(org.springframework.remoting.rmi.RmiProxyFactoryBean)

Example 12 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class MiscellaneousTests method testTimeoutHonoringWhenRequestsQueuedUp.

/**
 * Asserts that receive-timeout is honored even if
 * requests (once in process), takes less then receive-timeout value
 * when requests are queued up (e.g., single consumer receiver)
 */
@Test
public void testTimeoutHonoringWhenRequestsQueuedUp() throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("honor-timeout.xml", this.getClass());
    final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
    final CountDownLatch latch = new CountDownLatch(3);
    final AtomicInteger replies = new AtomicInteger();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 3; i++) {
        this.exchange(latch, gateway, replies);
    }
    latch.await();
    stopWatch.stop();
    assertTrue(stopWatch.getTotalTimeMillis() <= 18000);
    assertEquals(1, replies.get());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.springframework.util.StopWatch) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 13 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class RequestReplyScenariosWithCorrelationKeyProvidedTests method messageCorrelationBasedCustomCorrelationKeyDelayedReplies.

@Test
public void messageCorrelationBasedCustomCorrelationKeyDelayedReplies() throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("explicit-correlation-key.xml", this.getClass());
    RequestReplyExchanger gateway = context.getBean("explicitCorrelationKeyGatewayC", RequestReplyExchanger.class);
    for (int i = 0; i < 3; i++) {
        try {
            gateway.exchange(MessageBuilder.withPayload("hello").build());
        } catch (Exception e) {
        // ignore
        }
    }
    JmsOutboundGateway outGateway = TestUtils.getPropertyValue(context.getBean("outGateway"), "handler", JmsOutboundGateway.class);
    outGateway.setReceiveTimeout(5000);
    assertEquals("foo", gateway.exchange(MessageBuilder.withPayload("foo").build()).getPayload());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 14 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class RequestReplyScenariosWithCorrelationKeyProvidedTests method messageCorrelationBasedCustomCorrelationKey.

@Test
public void messageCorrelationBasedCustomCorrelationKey() throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("explicit-correlation-key.xml", this.getClass());
    RequestReplyExchanger gateway = context.getBean("explicitCorrelationKeyGateway", RequestReplyExchanger.class);
    gateway.exchange(MessageBuilder.withPayload("foo").build());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 15 with RequestReplyExchanger

use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.

the class RequestReplyScenariosWithTempReplyQueuesTests method messageCorrelationBasedOnRequestMessageId.

@SuppressWarnings("resource")
@Test
public void messageCorrelationBasedOnRequestMessageId() throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-temp-reply-consumers.xml", this.getClass());
    RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
    CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
    final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    final Destination requestDestination = context.getBean("siOutQueue", Destination.class);
    new Thread(() -> {
        final Message requestMessage = jmsTemplate.receive(requestDestination);
        Destination replyTo = null;
        try {
            replyTo = requestMessage.getJMSReplyTo();
        } catch (Exception e) {
            fail();
        }
        jmsTemplate.send(replyTo, (MessageCreator) session -> {
            try {
                TextMessage message = session.createTextMessage();
                message.setText("bar");
                message.setJMSCorrelationID(requestMessage.getJMSMessageID());
                return message;
            } catch (Exception e) {
            }
            return null;
        });
    }).start();
    gateway.exchange(new GenericMessage<String>("foo"));
    context.close();
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

RequestReplyExchanger (org.springframework.integration.gateway.RequestReplyExchanger)27 Test (org.junit.Test)24 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)21 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)18 GenericMessage (org.springframework.messaging.support.GenericMessage)17 Destination (javax.jms.Destination)11 TextMessage (javax.jms.TextMessage)11 Message (javax.jms.Message)10 JmsTemplate (org.springframework.jms.core.JmsTemplate)10 MessageCreator (org.springframework.jms.core.MessageCreator)10 CachingConnectionFactory (org.springframework.jms.connection.CachingConnectionFactory)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ConnectionFactory (javax.jms.ConnectionFactory)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)5 Message (org.springframework.messaging.Message)5 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)5 Date (java.util.Date)4 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4