@Test public void splitWithMassiveReplyMessages_allMessagesSent() { final int messageQuantity = 100000; MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity)); splitter.setBeanFactory(mock(BeanFactory.class)); DirectChannel replyChannel = new DirectChannel(); splitter.setOutputChannel(replyChannel); splitter.afterPropertiesSet(); final AtomicInteger receivedMessageCounter = new AtomicInteger(0); new EventDrivenConsumer(replyChannel, message -> { assertThat("Failure with msg: " + message, message.getPayload(), is(notNullValue())); receivedMessageCounter.incrementAndGet(); }).start(); splitter.handleMessage(this.message); assertThat(receivedMessageCounter.get(), is(messageQuantity)); }
private void logComponentSubscriptionEvent(boolean add) { if (this.handler instanceof NamedComponent && this.inputChannel instanceof NamedComponent) { String channelName = ((NamedComponent) this.inputChannel).getComponentName(); String componentType = ((NamedComponent) this.handler).getComponentType(); componentType = StringUtils.hasText(componentType) ? componentType : ""; String componentName = getComponentName(); componentName = (StringUtils.hasText(componentName) && componentName.contains("#")) ? "" : ":" + componentName; StringBuffer buffer = new StringBuffer(); buffer.append("{" + componentType + componentName + "} as a subscriber to the '" + channelName + "' channel"); if (add) { buffer.insert(0, "Adding "); } else { buffer.insert(0, "Removing "); } logger.info(buffer.toString()); } } }
@Test public void testGateway() throws Exception { this.whichTest = 0; GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class); gpfb.setBeanFactory(mock(BeanFactory.class)); DirectChannel input = new DirectChannel(); gpfb.setDefaultRequestChannel(input); gpfb.setDefaultReplyTimeout(10000L); gpfb.afterPropertiesSet(); Foo foo = (Foo) gpfb.getObject(); this.handler.setOutputChannel(null); EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler); consumer.afterPropertiesSet(); consumer.start(); this.latch.countDown(); String result = foo.exchange("foo"); assertEquals("reply", result); }
@Override protected Binding<MessageChannel> doBindProducer(String name, MessageChannel channel, ProducerProperties properties) { Assert.isInstanceOf(SubscribableChannel.class, channel); logger.debug("Binding Consul client to eventName " + name); ConsulSendingHandler sendingHandler = new ConsulSendingHandler(this.eventService.getConsulClient(), name); EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) channel, sendingHandler); consumer.setBeanFactory(getBeanFactory()); consumer.setBeanName(String.format(BEAN_NAME_TEMPLATE, name)); consumer.afterPropertiesSet(); consumer.start(); return new DefaultBinding<>(name, null, channel, consumer); } }
protected AbstractEndpoint doCreateEndpoint(MessageHandler handler, MessageChannel inputChannel, List<Annotation> annotations) { AbstractEndpoint endpoint; if (inputChannel instanceof PollableChannel) { PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler); configurePollingEndpoint(pollingConsumer, annotations); endpoint = pollingConsumer; } else { Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class); Assert.state(ObjectUtils.isEmpty(pollers), "A '@Poller' should not be specified for Annotation-based " + "endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable)."); if (inputChannel instanceof Publisher) { endpoint = new ReactiveStreamsConsumer(inputChannel, handler); } else { endpoint = new EventDrivenConsumer((SubscribableChannel) inputChannel, handler); } } return endpoint; }
@Test public void targetOnly() { String beanName = "outboundWithImplicitChannel"; Object channel = this.applicationContext.getBean(beanName); assertTrue(channel instanceof DirectChannel); BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext); assertNotNull(channelResolver.resolveDestination(beanName)); Object adapter = this.applicationContext.getBean(beanName + ".adapter"); assertNotNull(adapter); assertTrue(adapter instanceof EventDrivenConsumer); assertFalse(((EventDrivenConsumer) adapter).isAutoStartup()); assertEquals(-1, ((EventDrivenConsumer) adapter).getPhase()); TestConsumer consumer = (TestConsumer) this.applicationContext.getBean("consumer"); assertNull(consumer.getLastMessage()); Message<?> message = new GenericMessage<String>("test"); try { ((MessageChannel) channel).send(message); fail("MessageDispatchingException is expected."); } catch (Exception e) { assertThat(e, Matchers.instanceOf(MessageDeliveryException.class)); assertThat(e.getCause(), Matchers.instanceOf(MessageDispatchingException.class)); } ((EventDrivenConsumer) adapter).start(); ((MessageChannel) channel).send(message); assertNotNull(consumer.getLastMessage()); assertEquals(message, consumer.getLastMessage()); }
public EventDrivenConsumer buildContext(String routerDef) { appContext = TestXmlApplicationContextHelper.getTestAppContext(channelConfig + routerDef); appContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("router"); consumer.start(); return consumer; }
.isSameAs(this.resourceIdResolver); assertThat(this.s3OutboundChannelAdapter.getPhase()).isEqualTo(100); assertThat(this.s3OutboundChannelAdapter.isAutoStartup()).isFalse(); assertThat(this.s3OutboundChannelAdapter.isRunning()).isFalse(); assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapter, "inputChannel")) .isSameAs(this.errorChannel);
@Test public void testJobLaunchingGatewayIsRunning() throws Exception { setUp("JobLaunchingGatewayParserTestsRunning-context.xml", getClass()); assertTrue(this.consumer.isRunning()); final MessagingTemplate messagingTemplate = TestUtils.getPropertyValue(this.consumer, "handler.messagingTemplate", MessagingTemplate.class); final Long sendTimeout = TestUtils.getPropertyValue(messagingTemplate, "sendTimeout", Long.class); assertEquals("Wrong sendTimeout", Long.valueOf(-1L), sendTimeout); }
@Test public void testPrototypeIsNotOverridden() { assertNotSame(this.flow1WithPrototypeHandlerConsumer.getHandler(), this.flow2WithPrototypeHandlerConsumer.getHandler()); }
@Test public void testConsumerEndpointFactoryBeanDefaultPhase() { assertEquals(Integer.MIN_VALUE, this.testAliasEndpoint.getPhase()); }
@Override protected Binding<MessageChannel> doBindProducer(String name, MessageChannel channel, ProducerProperties properties) { Assert.isInstanceOf(SubscribableChannel.class, channel); logger.debug("Binding Consul client to eventName " + name); ConsulSendingHandler sendingHandler = new ConsulSendingHandler(this.eventService.getConsulClient(), name); EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) channel, sendingHandler); consumer.setBeanFactory(getBeanFactory()); consumer.setBeanName(String.format(BEAN_NAME_TEMPLATE, name)); consumer.afterPropertiesSet(); consumer.start(); return new DefaultBinding<>(name, null, channel, consumer); } }
@Bean public EventDrivenConsumer foreignMessageHandlerNoStats() { return new EventDrivenConsumer(three(), new BareHandler()); }
@Test public void testtCPOrder() { this.outGateway.start(); this.testOutTcpNio.start(); @SuppressWarnings("unchecked") Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils .getPropertyValue( TestUtils.getPropertyValue(this.tcpChannel, "dispatcher"), "handlers"); Iterator<MessageHandler> iterator = handlers.iterator(); assertSame(this.tcpNewOut2, iterator.next()); //15 assertSame(this.tcpOutboundGateway, iterator.next()); //24 assertSame(this.tcpNewOut1, iterator.next()); //25 assertSame(this.tcpOut, iterator.next()); //35 }
"queueExpression.literalValue")) .isEqualTo("foo"); assertThat(this.sqsOutboundChannelAdapter.getPhase()).isEqualTo(100); assertThat(this.sqsOutboundChannelAdapter.isAutoStartup()).isFalse(); assertThat(this.sqsOutboundChannelAdapter.isRunning()).isFalse(); assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapter, "inputChannel")) .isSameAs(this.errorChannel);
@Test public void testGatewayParser() throws Exception { setUp("JobLaunchingGatewayParserTests-context.xml", getClass()); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("requestChannel", inputChannel.getComponentName()); final JobLaunchingMessageHandler jobLaunchingMessageHandler = TestUtils.getPropertyValue(this.consumer, "handler.jobLaunchingMessageHandler", JobLaunchingMessageHandler.class); assertNotNull(jobLaunchingMessageHandler); final MessagingTemplate messagingTemplate = TestUtils.getPropertyValue(this.consumer, "handler.messagingTemplate", MessagingTemplate.class); final Long sendTimeout = TestUtils.getPropertyValue(messagingTemplate, "sendTimeout", Long.class); assertEquals("Wrong sendTimeout", Long.valueOf(123L), sendTimeout); assertFalse(this.consumer.isRunning()); }
@Test @MongoDbAvailable public void testCollectionCallback() throws Exception { EventDrivenConsumer consumer = context.getBean("gatewayCollectionCallback", EventDrivenConsumer.class); PollableChannel outChannel = context.getBean("out", PollableChannel.class); Message<String> message = MessageBuilder .withPayload("") .setHeader("collectionName", "data") .build(); consumer.getHandler().handleMessage(message); Message<?> result = outChannel.receive(10000); long personsCount = (Long) result.getPayload(); assertEquals(4, personsCount); }
@Test public void splitToIterator_allMessagesContainSequenceNumber() { final int messageQuantity = 5; MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity)); splitter.setBeanFactory(mock(BeanFactory.class)); DirectChannel replyChannel = new DirectChannel(); splitter.setOutputChannel(replyChannel); splitter.afterPropertiesSet(); new EventDrivenConsumer(replyChannel, message -> assertThat("Failure with msg: " + message, message.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Integer.class), is(Integer.valueOf((String) message.getPayload())))).start(); splitter.handleMessage(this.message); }
private void bindProducerDirectly(String name, SubscribableChannel producerChannel, MessageChannel consumerChannel, AbstractBusPropertiesAccessor properties) { DirectHandler handler = new DirectHandler(consumerChannel); EventDrivenConsumer consumer = new EventDrivenConsumer(producerChannel, handler); consumer.setBeanFactory(getBeanFactory()); consumer.setBeanName("outbound." + name); consumer.afterPropertiesSet(); Binding binding = Binding.forDirectProducer(name, producerChannel, consumer, properties); addBinding(binding); binding.start(); if (logger.isInfoEnabled()) { logger.info("Producer bound directly: " + binding); } }
this.gatherEndpoint = new EventDrivenConsumer((SubscribableChannel) this.gatherChannel, this.gatherer);