/** * Configure the handler with an {@link ExpressionEvaluatingCorrelationStrategy} * for the given expression. * @param correlationExpression the correlation expression. * @return the handler spec. * @see AbstractCorrelatingMessageHandler#setCorrelationStrategy(CorrelationStrategy) */ public S correlationExpression(String correlationExpression) { return correlationStrategy(new ExpressionEvaluatingCorrelationStrategy(correlationExpression)); }
@Test public void testCorrelationKeyWithMethodInvokingExpression() throws Exception { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression expression = parser.parseExpression("payload.substring(0,1)"); strategy = new ExpressionEvaluatingCorrelationStrategy(expression); strategy.setBeanFactory(mock(BeanFactory.class)); Object correlationKey = strategy.getCorrelationKey(new GenericMessage<String>("bla")); assertThat(correlationKey, is(instanceOf(String.class))); assertThat((String) correlationKey, is("b")); }
@Test(expected = IllegalArgumentException.class) public void testCreateInstanceWithNullExpressionFails() throws Exception { Expression nullExpression = null; strategy = new ExpressionEvaluatingCorrelationStrategy(nullExpression); }
@Test(expected = IllegalArgumentException.class) public void testCreateInstanceWithEmptyExpressionFails() throws Exception { strategy = new ExpressionEvaluatingCorrelationStrategy(""); }
@Bean @ServiceActivator(inputChannel = "aggregatorChannel") public MessageHandler aggregator() { AggregatingMessageHandler handler = new AggregatingMessageHandler(new SimpleMessageGroupProcessor()); handler.setCorrelationStrategy(new ExpressionEvaluatingCorrelationStrategy("1")); handler.setReleaseStrategy(new ExpressionEvaluatingReleaseStrategy("size() == 10")); handler.setOutputChannelName("splitterChannel"); return handler; }
/** * Configure the handler with an {@link ExpressionEvaluatingCorrelationStrategy} * for the given expression. * @param correlationExpression the correlation expression. * @return the handler spec. * @see AbstractCorrelatingMessageHandler#setCorrelationStrategy(CorrelationStrategy) */ public S correlationExpression(String correlationExpression) { return correlationStrategy(new ExpressionEvaluatingCorrelationStrategy(correlationExpression)); }
/** * Configure the handler with an {@link ExpressionEvaluatingCorrelationStrategy} for the * given expression. * @param correlationExpression the correlation expression. * @return the handler spec. * @see AbstractCorrelatingMessageHandler#setCorrelationStrategy(CorrelationStrategy) */ public S correlationExpression(String correlationExpression) { return correlationStrategy(new ExpressionEvaluatingCorrelationStrategy(correlationExpression)); }
@Bean @ConditionalOnProperty(prefix = AggregatorProperties.PREFIX, name = "correlation") @ConditionalOnMissingBean public CorrelationStrategy correlationStrategy() { return new ExpressionEvaluatingCorrelationStrategy(this.properties.getCorrelation()); }
/** * Configure the handler with an {@link ExpressionEvaluatingCorrelationStrategy} for the * given expression. * @param correlationExpression the correlation expression. * @return the handler spec. * @see AbstractCorrelatingMessageHandler#setCorrelationStrategy(CorrelationStrategy) */ public S correlationExpression(String correlationExpression) { return correlationStrategy(new ExpressionEvaluatingCorrelationStrategy(correlationExpression)); }
@Bean @Primary @ServiceActivator(inputChannel= Sink.INPUT) FactoryBean<MessageHandler> aggregatorFactoryBean(MessageChannel toSink, MessageGroupStore messageGroupStore) { AggregatorFactoryBean aggregatorFactoryBean = new AggregatorFactoryBean(); aggregatorFactoryBean.setCorrelationStrategy( new ExpressionEvaluatingCorrelationStrategy("payload.getClass().name")); aggregatorFactoryBean.setReleaseStrategy(new MessageCountReleaseStrategy(properties.getBatchSize())); aggregatorFactoryBean.setMessageStore(messageGroupStore); aggregatorFactoryBean.setProcessorBean(new DefaultAggregatingMessageGroupProcessor()); aggregatorFactoryBean.setExpireGroupsUponCompletion(true); aggregatorFactoryBean.setSendPartialResultOnExpiry(true); aggregatorFactoryBean.setOutputChannel(toSink); return aggregatorFactoryBean; }