Search in sources :

Example 21 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class DirectChannelSubscriptionTests method exceptionThrownFromRegisteredEndpoint.

@Test(expected = MessagingException.class)
public void exceptionThrownFromRegisteredEndpoint() {
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            throw new RuntimeException("intentional test failure");
        }
    };
    handler.setOutputChannel(targetChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, handler);
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    try {
        this.sourceChannel.send(new GenericMessage<String>("foo"));
    } finally {
        context.stop();
    }
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Example 22 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class DefaultSplitterTests method correlationIdCopiedFromMessageId.

@Test
public void correlationIdCopiedFromMessageId() {
    Message<String> message = MessageBuilder.withPayload("test").build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    DefaultMessageSplitter splitter = new DefaultMessageSplitter();
    splitter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, splitter);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 23 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class JmsOutboundChannelAdapterParserTests method adapterWithHeaderMapper.

@Test
public void adapterWithHeaderMapper() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundWithHeaderMapper.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
    DirectFieldAccessor accessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
    JmsHeaderMapper headerMapper = (JmsHeaderMapper) accessor.getPropertyValue("headerMapper");
    assertNotNull(headerMapper);
    assertEquals(TestJmsHeaderMapper.class, headerMapper.getClass());
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsHeaderMapper(org.springframework.integration.jms.JmsHeaderMapper) Test(org.junit.Test)

Example 24 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class JmsOutboundChannelAdapterParserTests method adapterWithJmsTemplateQos.

@Test
public void adapterWithJmsTemplateQos() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundWithJmsTemplateQos.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
    JmsTemplate jmsTemplate = (JmsTemplate) handlerAccessor.getPropertyValue("jmsTemplate");
    assertNotNull(jmsTemplate);
    assertEquals(context.getBean("template"), jmsTemplate);
    assertTrue(jmsTemplate.isExplicitQosEnabled());
    assertEquals(7, jmsTemplate.getPriority());
    assertEquals(12345, jmsTemplate.getTimeToLive());
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.Test)

Example 25 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class JmsOutboundChannelAdapterParserTests method qosNotExplicitByDefault.

@Test
public void qosNotExplicitByDefault() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundWithQos.xml", this.getClass());
    EventDrivenConsumer endpoint = context.getBean("defaultAdapter", EventDrivenConsumer.class);
    DirectFieldAccessor accessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler")).getPropertyValue("jmsTemplate"));
    assertEquals(false, accessor.getPropertyValue("explicitQosEnabled"));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5