List of usage examples for org.springframework.integration.channel QueueChannel QueueChannel
public QueueChannel()
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testClaimCheck() { QueueChannel replyChannel = new QueueChannel(); Message<String> message = MutableMessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build(); this.claimCheckInput.send(message); Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);/*from w ww .j ava 2 s.c o m*/ assertSame(message, receive); assertEquals(1, this.messageStore.getMessageCount()); assertSame(message, this.messageStore.getMessage(message.getHeaders().getId())); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testGatewayFlow() throws Exception { PollableChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build(); this.gatewayInput.send(message); Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);// w w w. j ava2s . c o m assertEquals("FOO", receive.getPayload()); assertNull(this.gatewayError.receive(1)); message = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel).build(); this.gatewayInput.send(message); receive = replyChannel.receive(1); assertNull(receive); receive = this.gatewayError.receive(2000); assertNotNull(receive); assertThat(receive, instanceOf(ErrorMessage.class)); assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class)); assertThat(((Exception) receive.getPayload()).getMessage(), containsString("' rejected Message")); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testJmsPipelineFlow() { PollableChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder.withPayload("hello through the jms pipeline") .setReplyChannel(replyChannel).setHeader("destination", "jmsPipelineTest").build(); this.jmsOutboundGatewayChannel.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive);/* w w w .j a v a 2 s . co m*/ assertEquals("HELLO THROUGH THE JMS PIPELINE", receive.getPayload()); }
From source file:org.springframework.integration.dsl.test.xml.XmlTests.java
@Test public void testHeaderEnricher() { QueueChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder .withPayload("<root><elementOne>1</elementOne><elementTwo>2</elementTwo></root>") .setReplyChannel(replyChannel).build(); try {/*from w w w. j a v a 2 s . c o m*/ this.xpathHeaderEnricherInput.send(message); fail("Expected MessageDispatchingException"); } catch (Exception e) { assertThat(e, instanceOf(MessageDeliveryException.class)); assertThat(e.getCause(), instanceOf(MessageDispatchingException.class)); assertThat(e.getMessage(), containsString("Dispatcher has no subscribers")); } this.controlBusFlowInput.send(new GenericMessage<>("@xpathHeaderEnricher.start()")); this.xpathHeaderEnricherInput.send(message); Message<?> result = replyChannel.receive(2000); assertNotNull(result); MessageHeaders headers = result.getHeaders(); assertEquals("1", headers.get("one")); assertEquals("2", headers.get("two")); assertThat(headers.getReplyChannel(), instanceOf(String.class)); assertFalse(headers.containsKey("foo")); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testCommit() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor(); syncProcessor.setBeanFactory(mock(BeanFactory.class)); PollableChannel queueChannel = new QueueChannel(); syncProcessor.setBeforeCommitExpression(new SpelExpressionParser().parseExpression("#bix")); syncProcessor.setBeforeCommitChannel(queueChannel); syncProcessor.setAfterCommitExpression(new SpelExpressionParser().parseExpression("#baz")); DefaultTransactionSynchronizationFactory syncFactory = new DefaultTransactionSynchronizationFactory( syncProcessor);/*from www.ja v a 2 s .c o m*/ adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); IntegrationResourceHolder holder = (IntegrationResourceHolder) TransactionSynchronizationManager .getResource(this); holder.addAttribute("baz", "qux"); holder.addAttribute("bix", "qox"); return message; } }); MessageChannel afterCommitChannel = TestUtils.getPropertyValue(syncProcessor, "afterCommitChannel", MessageChannel.class); assertThat(afterCommitChannel, Matchers.instanceOf(NullChannel.class)); Log logger = TestUtils.getPropertyValue(afterCommitChannel, "logger", Log.class); logger = Mockito.spy(logger); Mockito.when(logger.isDebugEnabled()).thenReturn(true); DirectFieldAccessor dfa = new DirectFieldAccessor(afterCommitChannel); dfa.setPropertyValue("logger", logger); TransactionSynchronizationManager.initSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(true); doPoll(adapter); TransactionSynchronizationUtils.triggerBeforeCommit(false); TransactionSynchronizationUtils.triggerAfterCommit(); Message<?> beforeCommitMessage = queueChannel.receive(1000); assertNotNull(beforeCommitMessage); assertEquals("qox", beforeCommitMessage.getPayload()); Mockito.verify(logger).debug(Mockito.anyString()); TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED); TransactionSynchronizationManager.clearSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(false); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testTransactionSynchronizationFactoryBean() { ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(TestTxSyncConfiguration.class); TransactionSynchronizationFactory syncFactory = ctx.getBean(TransactionSynchronizationFactory.class); PollableChannel queueChannel = ctx.getBean("outputChannel", PollableChannel.class); SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override/*from w w w . j av a 2 s . c o m*/ public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); IntegrationResourceHolder holder = (IntegrationResourceHolder) TransactionSynchronizationManager .getResource(this); holder.addAttribute("baz", "qux"); holder.addAttribute("bix", "qox"); return message; } }); TransactionSynchronizationManager.initSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(true); doPoll(adapter); TransactionSynchronizationUtils.triggerBeforeCommit(false); TransactionSynchronizationUtils.triggerAfterCommit(); Message<?> beforeCommitMessage = queueChannel.receive(1000); assertNotNull(beforeCommitMessage); assertEquals("qox", beforeCommitMessage.getPayload()); Message<?> afterCommitMessage = queueChannel.receive(1000); assertNotNull(afterCommitMessage); assertEquals("qux", afterCommitMessage.getPayload()); TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED); TransactionSynchronizationManager.clearSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(false); ctx.close(); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testRollback() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor(); syncProcessor.setBeanFactory(mock(BeanFactory.class)); PollableChannel queueChannel = new QueueChannel(); syncProcessor.setAfterRollbackChannel(queueChannel); syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz")); DefaultTransactionSynchronizationFactory syncFactory = new DefaultTransactionSynchronizationFactory( syncProcessor);/* ww w . j a v a 2 s . com*/ adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); ((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this)) .addAttribute("baz", "qux"); return message; } }); TransactionSynchronizationManager.initSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(true); doPoll(adapter); TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK); Message<?> rollbackMessage = queueChannel.receive(1000); assertNotNull(rollbackMessage); assertEquals("qux", rollbackMessage.getPayload()); TransactionSynchronizationManager.clearSynchronization(); TransactionSynchronizationManager.setActualTransactionActive(false); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testCommitWithManager() { final PollableChannel queueChannel = new QueueChannel(); TransactionTemplate transactionTemplate = new TransactionTemplate(new PseudoTransactionManager()); transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor(); syncProcessor.setBeanFactory(mock(BeanFactory.class)); syncProcessor.setBeforeCommitExpression(new SpelExpressionParser().parseExpression("#bix")); syncProcessor.setBeforeCommitChannel(queueChannel); syncProcessor.setAfterCommitChannel(queueChannel); syncProcessor.setAfterCommitExpression(new SpelExpressionParser().parseExpression("#baz")); DefaultTransactionSynchronizationFactory syncFactory = new DefaultTransactionSynchronizationFactory( syncProcessor);/*from www. j av a2 s . c o m*/ adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); IntegrationResourceHolder holder = (IntegrationResourceHolder) TransactionSynchronizationManager .getResource(this); holder.addAttribute("baz", "qux"); holder.addAttribute("bix", "qox"); return message; } }); doPoll(adapter); return null; }); Message<?> beforeCommitMessage = queueChannel.receive(1000); assertNotNull(beforeCommitMessage); assertEquals("qox", beforeCommitMessage.getPayload()); Message<?> afterCommitMessage = queueChannel.receive(1000); assertNotNull(afterCommitMessage); assertEquals("qux", afterCommitMessage.getPayload()); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testRollbackWithManager() { final PollableChannel queueChannel = new QueueChannel(); TransactionTemplate transactionTemplate = new TransactionTemplate(new PseudoTransactionManager()); try {//from www . java2s .c o m transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor(); syncProcessor.setBeanFactory(mock(BeanFactory.class)); syncProcessor.setAfterRollbackChannel(queueChannel); syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz")); DefaultTransactionSynchronizationFactory syncFactory = new DefaultTransactionSynchronizationFactory( syncProcessor); adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); ((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this)) .addAttribute("baz", "qux"); return message; } }); doPoll(adapter); throw new RuntimeException("Force rollback"); }); } catch (Exception e) { assertEquals("Force rollback", e.getMessage()); } Message<?> rollbackMessage = queueChannel.receive(1000); assertNotNull(rollbackMessage); assertEquals("qux", rollbackMessage.getPayload()); }
From source file:org.springframework.integration.endpoint.PseudoTransactionalMessageSourceTests.java
@Test public void testRollbackWithManagerUsingStatus() { final PollableChannel queueChannel = new QueueChannel(); TransactionTemplate transactionTemplate = new TransactionTemplate(new PseudoTransactionManager()); transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor(); syncProcessor.setBeanFactory(mock(BeanFactory.class)); syncProcessor.setAfterRollbackChannel(queueChannel); syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz")); DefaultTransactionSynchronizationFactory syncFactory = new DefaultTransactionSynchronizationFactory( syncProcessor);//from w ww .ja v a 2 s .co m adapter.setTransactionSynchronizationFactory(syncFactory); QueueChannel outputChannel = new QueueChannel(); adapter.setOutputChannel(outputChannel); adapter.setSource(new MessageSource<String>() { @Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); ((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this)) .addAttribute("baz", "qux"); return message; } }); doPoll(adapter); status.setRollbackOnly(); return null; }); Message<?> rollbackMessage = queueChannel.receive(1000); assertNotNull(rollbackMessage); assertEquals("qux", rollbackMessage.getPayload()); }