/** * Construct an instance with the provided timeout and default correlation and * output strategies. * @param timeout the timeout in milliseconds. */ public BarrierMessageHandler(long timeout) { this(timeout, new DefaultAggregatingMessageGroupProcessor()); }
@Before public void setup() { this.defaultProcessor.setBeanFactory(mock(BeanFactory.class)); this.methodInvokingProcessor.setBeanFactory(mock(BeanFactory.class)); }
@Test public void testNullHeaderValue() { DefaultAggregatingMessageGroupProcessor processor = new DefaultAggregatingMessageGroupProcessor(); DirectFieldAccessor dfa = new DirectFieldAccessor(processor); dfa.setPropertyValue("messageBuilderFactory", new MutableMessageBuilderFactory()); List<Message<?>> messages = Arrays.asList(message1, message2); MessageGroup group = new SimpleMessageGroup(messages, 1); Object result = processor.processMessageGroup(group); assertNotNull(result); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); messages = Arrays.asList(message1, message2); group = new SimpleMessageGroup(messages, 1); result = processor.processMessageGroup(group); resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertNull(resultMessage.getHeaders().get("k1"));
/** * Construct an instance with the provided timeout and correlation strategy, and default * output processor. * @param timeout the timeout in milliseconds. * @param correlationStrategy the correlation strategy. */ public BarrierMessageHandler(long timeout, CorrelationStrategy correlationStrategy) { this(timeout, new DefaultAggregatingMessageGroupProcessor(), correlationStrategy); }
AggregatorSpec() { super(new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor())); }
@Bean @ServiceActivator(inputChannel = "aggregateChannel") public MessageHandler aggregator() { AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()); handler.setOutputChannel(resultChannel()); return handler; }
@Bean public MessageHandler gatherer2() { return new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor(), new SimpleMessageStore(), new HeaderAttributeCorrelationStrategy(IntegrationMessageHeaderAccessor.CORRELATION_ID), new MessageCountReleaseStrategy(3)); }
/** * Construct an instance with the provided timeout and correlation strategy, and default * output processor. * @param timeout the timeout in milliseconds. * @param correlationStrategy the correlation strategy. */ public BarrierMessageHandler(long timeout, CorrelationStrategy correlationStrategy) { this(timeout, new DefaultAggregatingMessageGroupProcessor(), correlationStrategy); }
/** * Construct an instance with the provided timeout and default correlation and * output strategies. * @param timeout the timeout in milliseconds. */ public BarrierMessageHandler(long timeout) { this(timeout, new DefaultAggregatingMessageGroupProcessor()); }
@Test /* INT-3216 */ public void testDontReapIfAlreadyComplete() throws Exception { MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor(); AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp); handler.setReleaseStrategy(group -> true); QueueChannel outputChannel = new QueueChannel(); handler.setOutputChannel(outputChannel); MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class); mgs.addMessagesToGroup("foo", new GenericMessage<>("foo")); mgs.completeGroup("foo"); mgs = spy(mgs); new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs); Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class); forceComplete.setAccessible(true); MessageGroup group = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class) .get("foo"); assertTrue(group.isComplete()); forceComplete.invoke(handler, group); verify(mgs, never()).getMessageGroup("foo"); assertNull(outputChannel.receive(0)); }
AggregatorSpec() { super(new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor())); }
@Test public void testReapWithChangeInSameMillisecond() throws Exception { MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor(); AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp); handler.setReleaseStrategy(group -> true); QueueChannel outputChannel = new QueueChannel(); handler.setOutputChannel(outputChannel); MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class); Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class); forceComplete.setAccessible(true); GenericMessage<String> secondMessage = new GenericMessage<>("bar"); mgs.addMessagesToGroup("foo", new GenericMessage<>("foo"), secondMessage); MessageGroup group = mgs.getMessageGroup("foo"); // remove a message mgs.removeMessagesFromGroup("foo", secondMessage); // force lastModified to be the same MessageGroup groupNow = mgs.getMessageGroup("foo"); new DirectFieldAccessor(group).setPropertyValue("lastModified", groupNow.getLastModified()); forceComplete.invoke(handler, group); Message<?> message = outputChannel.receive(0); assertNotNull(message); Collection<?> payload = (Collection<?>) message.getPayload(); assertEquals(1, payload.size()); }
@Test @Ignore public void testAggPerf() throws InterruptedException, ExecutionException, TimeoutException { AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()); handler.setCorrelationStrategy(message -> "foo"); handler.setReleaseStrategy(new MessageCountReleaseStrategy(60000));
@Test @Ignore("Time sensitive") public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException, TimeoutException { AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()); handler.setCorrelationStrategy(message -> "foo"); handler.setReleasePartialSequences(true);
@Test public void testDontReapIfNewGroupFoundDuringRefetch() throws Exception { MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor(); AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp); handler.setReleaseStrategy(group -> true); QueueChannel outputChannel = new QueueChannel(); handler.setOutputChannel(outputChannel); MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class); mgs.addMessagesToGroup("foo", new GenericMessage<>("foo")); MessageGroup group = new SimpleMessageGroup(mgs.getMessageGroup("foo")); mgs = spy(mgs); new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs); Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class); forceComplete.setAccessible(true); MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class) .get("foo"); assertFalse(groupInStore.isComplete()); assertFalse(group.isComplete()); DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(group); directFieldAccessor.setPropertyValue("lastModified", groupInStore.getLastModified()); directFieldAccessor.setPropertyValue("timestamp", groupInStore.getTimestamp() - 1); forceComplete.invoke(handler, group); verify(mgs).getMessageGroup("foo"); assertNull(outputChannel.receive(0)); }
@Test public void testDontReapIfAlreadyCompleteAfterRefetch() throws Exception { MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor(); AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp); handler.setReleaseStrategy(group -> true); QueueChannel outputChannel = new QueueChannel(); handler.setOutputChannel(outputChannel); MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class); mgs.addMessagesToGroup("foo", new GenericMessage<>("foo")); MessageGroup group = new SimpleMessageGroup(mgs.getMessageGroup("foo")); mgs.completeGroup("foo"); mgs = spy(mgs); new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs); Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class); forceComplete.setAccessible(true); MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class) .get("foo"); assertTrue(groupInStore.isComplete()); assertFalse(group.isComplete()); new DirectFieldAccessor(group).setPropertyValue("lastModified", groupInStore.getLastModified()); forceComplete.invoke(handler, group); verify(mgs).getMessageGroup("foo"); assertNull(outputChannel.receive(0)); }
@Test public void testInt3483DeadlockOnMessageStoreRemoveMessageGroup() throws InterruptedException { final AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()); handler.setOutputChannel(new QueueChannel()); QueueChannel discardChannel = new QueueChannel();
@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; }
public SpringMessageAggregator(MessageHandler outputHandler, ReleaseStrategy releaseStrategy, CorrelationStrategy correlationStrategy) { super(new DefaultAggregatingMessageGroupProcessor()); //Set up the situation for when aggregation is complete (relies on the ComponentsAndCredentials, like it does in the SimpleMessageAggregator this.setReleaseStrategy(releaseStrategy); //How do we group messages? anything that is x or x$anything is correlated with x this.setCorrelationStrategy(correlationStrategy); //Ignore this coz I haven't figured it out yet. setExpireGroupsUponCompletion(true); setExpireGroupsUponTimeout(true); //TODO: I haven't set a timeout yet because it doesn't seem to work with GroupExpressionTimeOut //setGroupExpressionTimeout(?) incomingMessageChannel = new DirectChannel(); aggregatedMessageOutputChannel = new DirectChannel(); //channel out to MyHandler setOutputChannel(aggregatedMessageOutputChannel); //SpringMessageAggregator listens on this channel for messages incomingMessageChannel.subscribe(this); //DiscoveryHandler subscribes to the output channel. aggregatedMessageOutputChannel.subscribe(outputHandler); }
public SpringMessageAggregator(MessageHandler outputHandler, ReleaseStrategy releaseStrategy, CorrelationStrategy correlationStrategy) { super(new DefaultAggregatingMessageGroupProcessor()); //Set up the situation for when aggregation is complete (relies on the ComponentsAndCredentials, like it does in the SimpleMessageAggregator this.setReleaseStrategy(releaseStrategy); //How do we group messages? anything that is x or x$anything is correlated with x this.setCorrelationStrategy(correlationStrategy); //Ignore this coz I haven't figured it out yet. setExpireGroupsUponCompletion(true); setExpireGroupsUponTimeout(true); //TODO: I haven't set a timeout yet because it doesn't seem to work with GroupExpressionTimeOut //setGroupExpressionTimeout(?) incomingMessageChannel = new DirectChannel(); aggregatedMessageOutputChannel = new DirectChannel(); //channel out to MyHandler setOutputChannel(aggregatedMessageOutputChannel); //SpringMessageAggregator listens on this channel for messages incomingMessageChannel.subscribe(this); //DiscoveryHandler subscribes to the output channel. aggregatedMessageOutputChannel.subscribe(outputHandler); }