List of usage examples for org.springframework.integration.channel ExecutorChannel subscribe
@Override public boolean subscribe(MessageHandler handler)
From source file:com.apress.prospringintegration.channels.executorchannel.Main.java
public static void main(String[] args) { String contextName = "executor-channel.xml"; ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName); applicationContext.start();// w w w. j a v a2 s. c o m ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class); ExecutorChannel channel = applicationContext.getBean("ticketChannel", ExecutorChannel.class); channel.subscribe(ticketMessageHandler); List<Ticket> tickets = ticketGenerator.createTickets(); for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } }
From source file:nl.rav.comparision.integration.unitofwork.java.UnitOfWorkSpringTest.java
private void createRouteBuilder() { handler = new AbstractReplyProducingMessageHandler() { @Override/*w w w . j a v a 2s. c o m*/ protected Object handleRequestMessage(Message<?> requestMessage) { return "baz"; } }; AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() { @Override protected Object handleRequestMessage(Message<?> requestMessage) { if (doFail.get()) { throw new RuntimeException("qux"); } return requestMessage.getPayload(); } }; SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); taskExecutor.setThreadNamePrefix("test-"); ExecutorChannel intermediate = new ExecutorChannel(taskExecutor); handler.setOutputChannel(intermediate); intermediate.subscribe(handler2); replies = new QueueChannel(); handler2.setOutputChannel(replies); successChannel = new QueueChannel(); failureChannel = new QueueChannel(); ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice(); advice.setBeanFactory(mock(BeanFactory.class)); advice.setSuccessChannel(successChannel); advice.setFailureChannel(failureChannel); advice.setOnSuccessExpression("'foo'"); advice.setOnFailureExpression("'bar:' + #exception.message"); List<Advice> adviceChain = new ArrayList<Advice>(); adviceChain.add(advice); handler.setAdviceChain(adviceChain); handler.afterPropertiesSet(); handler2.setAdviceChain(adviceChain); handler2.afterPropertiesSet(); }
From source file:org.springframework.integration.channel.P2pChannelTests.java
@Test public void testExecutorChannelLoggingWithMoreThenOneSubscriber() { final ExecutorChannel channel = new ExecutorChannel(mock(Executor.class)); channel.setBeanName("executorChannel"); final Log logger = mock(Log.class); when(logger.isInfoEnabled()).thenReturn(true); ReflectionUtils.doWithFields(AbstractMessageChannel.class, new FieldCallback() { public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if ("logger".equals(field.getName())) { field.setAccessible(true); field.set(channel, logger); }/* ww w. jav a 2s . c o m*/ } }); channel.subscribe(mock(MessageHandler.class)); channel.subscribe(mock(MessageHandler.class)); verify(logger, times(2)).info(Mockito.anyString()); }