@Bean public QueueChannel replies() { return new QueueChannel(); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(stepName, "A step name must be provided for the remote workers."); Assert.state(messagingGateway != null, "The MessagingOperations must be set"); pollRepositoryForResults = !(dataSource == null && jobExplorer == null); if(pollRepositoryForResults) { logger.debug("MessageChannelPartitionHandler is configured to poll the job repository for slave results"); } if(dataSource != null && jobExplorer == null) { JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean(); jobExplorerFactoryBean.setDataSource(dataSource); jobExplorerFactoryBean.afterPropertiesSet(); jobExplorer = jobExplorerFactoryBean.getObject(); } if (!pollRepositoryForResults && replyChannel == null) { replyChannel = new QueueChannel(); }//end if }
@Test public void testPreReceive() throws Exception { MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(new TestMessageSource("foo")); QueueChannel channel = new QueueChannel(); assertTrue(interceptor.preReceive(channel)); assertEquals("foo", channel.receive(10L).getPayload()); }
PollableChannel replies = new QueueChannel(); partitionHandler.setReplyChannel(replies); StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows
@Bean @MyBridgeFrom public QueueChannel metaBridgeOutput() { return new QueueChannel(); }
@Bean @BridgeFrom(value = "pollableBridgeInput", poller = @Poller(fixedDelay = "1000")) public QueueChannel pollableBridgeOutput() { return new QueueChannel(); }
@Bean @BridgeFrom("toBridgeChannel") @IdempotentReceiver("idempotentReceiverInterceptor") public PollableChannel bridgePollableChannel() { return new QueueChannel(); }
@Test public void testClearEmptyChannel() { QueueChannel channel = new QueueChannel(); List<Message<?>> clearedMessages = channel.clear(); assertNotNull(clearedMessages); assertEquals(0, clearedMessages.size()); }
@Test public void asyncReceiveAndConvertWithExplicitChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Future<?> result = template.asyncReceiveAndConvert(channel); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertEquals("test", result.get()); assertTrue(elapsed >= 200 - safety); }
@Test public void testReplyingMessageHandlerWithOtherMethod() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); this.replyingHandlerWithOtherMethodTestInputChannel.send(message); Message<?> reply = replyChannel.receive(0); assertEquals("bar", reply.getPayload()); assertEquals("replyingHandlerWithOtherMethodTestInputChannel,replyingHandlerWithOtherMethodTestService", reply.getHeaders().get("history").toString()); }
@Test public void splitter() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestBean1("splitter-test")) .setReplyChannel(replyChannel).build(); this.splitterChannel.send(message); Message<?> result = replyChannel.receive(0); assertNotNull(result); assertNotNull(result.getPayload()); assertEquals(TestBean2.class, result.getPayload().getClass()); assertEquals("SPLITTER-TEST", ((TestBean2) result.getPayload()).text); }
@Test public void replyChannelExplicitOverwriteFalse() { MessageChannel inputChannel = this.context.getBean("replyChannelExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); inputChannel.send(message); Message<?> result = replyChannel.receive(0); assertNotNull(result); assertEquals("TEST", result.getPayload()); assertEquals(replyChannel, result.getHeaders().getReplyChannel()); }
@Test public void asyncConvertAndSendWithDefaultChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setDefaultDestination(channel); Future<?> future = template.asyncConvertAndSend("test"); assertNull(future.get(10000, TimeUnit.MILLISECONDS)); Message<?> result = channel.receive(0); assertEquals("test", result.getPayload()); }
@Test(expected = TimeoutException.class) public void asyncConvertAndSendWithTimeoutException() throws Exception { QueueChannel channel = new QueueChannel(1); channel.send(MessageBuilder.withPayload("blocker").build()); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Future<?> result = template.asyncConvertAndSend(channel, "test"); result.get(100, TimeUnit.MILLISECONDS); }
@Test public void testMultipleSelectorsAccept() { final AtomicInteger counter = new AtomicInteger(); MessageSelector selector1 = new TestMessageSelector(true, counter); MessageSelector selector2 = new TestMessageSelector(true, counter); MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2); QueueChannel channel = new QueueChannel(); channel.addInterceptor(interceptor); assertTrue(channel.send(new GenericMessage<>("test1"))); assertEquals(2, counter.get()); }
@Test public void asyncSendWithExplicitChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Message<?> message = MessageBuilder.withPayload("test").build(); Future<?> future = template.asyncSend(channel, message); assertNull(future.get(10000, TimeUnit.MILLISECONDS)); Message<?> result = channel.receive(0); assertEquals(message, result); }
@Test(expected = TimeoutException.class) public void asyncSendWithTimeoutException() throws Exception { QueueChannel channel = new QueueChannel(1); channel.send(MessageBuilder.withPayload("blocker").build()); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Future<?> result = template.asyncSend(channel, MessageBuilder.withPayload("test").build()); result.get(100, TimeUnit.MILLISECONDS); }
@Test public void noChannelListPassInitialization() { RecipientListRouter router = new RecipientListRouter(); router.setBeanFactory(mock(BeanFactory.class)); QueueChannel defaultOutputChannel = new QueueChannel(); router.setDefaultOutputChannel(defaultOutputChannel); router.afterPropertiesSet(); router.handleMessage(new GenericMessage<String>("foo")); Message<?> receive = defaultOutputChannel.receive(1000); assertNotNull(receive); }
@Test public void nullOk() { NullOkTestBean testBean = new NullOkTestBean(); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean); QueueChannel outputChannel = new QueueChannel(); serviceActivator.setOutputChannel(outputChannel); serviceActivator.setBeanFactory(mock(BeanFactory.class)); serviceActivator.afterPropertiesSet(); serviceActivator.handleMessage(new GenericMessage<>(new KafkaNull())); Message<?> result = outputChannel.receive(0); assertEquals("gotNull", result.getPayload()); }
@Test public void testPurgeAllWithoutSelector() { QueueChannel channel = new QueueChannel(); channel.send(new GenericMessage<String>("test1")); channel.send(new GenericMessage<String>("test2")); channel.send(new GenericMessage<String>("test3")); ChannelPurger purger = new ChannelPurger(channel); List<Message<?>> purgedMessages = purger.purge(); assertEquals(3, purgedMessages.size()); assertNull(channel.receive(0)); }