List of usage examples for org.springframework.integration.store MessageGroup getMessages
Collection<Message<?>> getMessages();
From source file:com.qpark.eip.core.spring.AbstractAggregator.java
/** * @param group//from w ww. j a v a 2 s.c o m * @return */ public boolean canRelease(final MessageGroup group) { boolean canRelease = false; this.logger.trace("+canRelease group messages.size={}, sequenceSize={}", group.getMessages().size(), group.getSequenceSize()); if (group.getSequenceSize() > 0 && group.getSequenceSize() == group.getMessages().size()) { canRelease = true; } this.logger.trace("-canRelease group canRelease={}", canRelease); return canRelease; }
From source file:org.springframework.integration.aggregator.AbstractAggregatingMessageGroupProcessor.java
/** * This default implementation simply returns all headers that have no conflicts among the group. An absent header * on one or more Messages within the group is not considered a conflict. Subclasses may override this method with * more advanced conflict-resolution strategies if necessary. *//*from www . j a v a2s .co m*/ protected Map<String, Object> aggregateHeaders(MessageGroup group) { Map<String, Object> aggregatedHeaders = new HashMap<String, Object>(); Set<String> conflictKeys = new HashSet<String>(); for (Message<?> message : group.getMessages()) { MessageHeaders currentHeaders = message.getHeaders(); for (String key : currentHeaders.keySet()) { if (MessageHeaders.ID.equals(key) || MessageHeaders.TIMESTAMP.equals(key) || MessageHeaders.SEQUENCE_SIZE.equals(key) || MessageHeaders.SEQUENCE_NUMBER.equals(key)) { continue; } Object value = currentHeaders.get(key); if (!aggregatedHeaders.containsKey(key)) { aggregatedHeaders.put(key, value); } else if (!value.equals(aggregatedHeaders.get(key))) { conflictKeys.add(key); } } } for (String keyToRemove : conflictKeys) { if (logger.isDebugEnabled()) { logger.debug("Excluding header '" + keyToRemove + "' upon aggregation due to conflict(s) " + "in MessageGroup with correlation key: " + group.getGroupId()); } aggregatedHeaders.remove(keyToRemove); } return aggregatedHeaders; }
From source file:org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.java
private void expireGroup(Object correlationKey, MessageGroup group) { if (logger.isInfoEnabled()) { logger.info("Expiring MessageGroup with correlationKey[" + correlationKey + "]"); }/*from w ww. j av a 2 s. com*/ if (sendPartialResultOnExpiry) { if (logger.isDebugEnabled()) { logger.debug("Prematurely releasing partially complete group with key [" + correlationKey + "] to: " + outputChannel); } completeGroup(correlationKey, group); } else { if (logger.isDebugEnabled()) { logger.debug("Discarding messages of partially complete group with key [" + correlationKey + "] to: " + discardChannel); } for (Message<?> message : group.getMessages()) { discardChannel.send(message); } } }
From source file:org.springframework.integration.aggregator.CorrelatingMessageBarrier.java
public Message<Object> receive() { for (Object key : correlationLocks.keySet()) { Object lock = getLock(key); synchronized (lock) { MessageGroup group = store.getMessageGroup(key); //group might be removed by another thread if (group != null) { if (releaseStrategy.canRelease(group)) { Message<?> nextMessage = null; Iterator<Message<?>> messages = group.getMessages().iterator(); if (messages.hasNext()) { nextMessage = messages.next(); store.removeMessageFromGroup(key, nextMessage); if (log.isDebugEnabled()) { log.debug(String.format("Released message for key [%s]: %s.", key, nextMessage)); }/* www . j a va 2 s . co m*/ } else { remove(key); } @SuppressWarnings("unchecked") Message<Object> result = (Message<Object>) nextMessage; return result; } } } } return null; }
From source file:org.springframework.integration.aggregator.SequenceSizeReleaseStrategy.java
public boolean canRelease(MessageGroup messageGroup) { boolean canRelease = false; Collection<Message<?>> messages = messageGroup.getMessages(); if (releasePartialSequences && !messages.isEmpty()) { if (logger.isTraceEnabled()) { logger.trace("Considering partial release of group [" + messageGroup + "]"); }/*from ww w .ja v a 2 s .c o m*/ List<Message<?>> sorted = new ArrayList<Message<?>>(messages); Collections.sort(sorted, comparator); int nextSequenceNumber = sorted.get(0).getHeaders().getSequenceNumber(); int lastReleasedMessageSequence = messageGroup.getLastReleasedMessageSequenceNumber(); if (nextSequenceNumber - lastReleasedMessageSequence == 1) { canRelease = true; ; } } else { int size = messages.size(); if (size == 0) { canRelease = true; } else { int sequenceSize = messageGroup.getOne().getHeaders().getSequenceSize(); // If there is no sequence then it must be incomplete.... if (sequenceSize == size) { canRelease = true; } } } return canRelease; }
From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java
@Test @Transactional//w w w .j a v a 2 s. c o m public void testCompletedNotExpiredGroupINT3037() throws Exception { /* * based on the aggregator scenario as follows; * * send three messages in * 1 of 2 * 2 of 2 * 2 of 2 (last again) * * expected behavior is that the LAST message (2 of 2 repeat) should be on the discard channel * (discard behavior performed by the AbstractCorrelatingMessageHandler.handleMessageInternal) */ final JdbcMessageStore messageStore = new JdbcMessageStore(dataSource); //init String groupId = "group"; //build the messages Message<?> oneOfTwo = MessageBuilder.withPayload("hello").setSequenceNumber(1).setSequenceSize(2) .setCorrelationId(groupId).build(); Message<?> twoOfTwo = MessageBuilder.withPayload("world").setSequenceNumber(2).setSequenceSize(2) .setCorrelationId(groupId).build(); //add to the messageStore messageStore.addMessageToGroup(groupId, oneOfTwo); messageStore.addMessageToGroup(groupId, twoOfTwo); //check that 2 messages are there assertTrue(messageStore.getMessageGroupCount() == 1); assertTrue(messageStore.getMessageCount() == 2); //retrieve the group (like in the aggregator) MessageGroup messageGroup = messageStore.getMessageGroup(groupId); //'complete' the group messageStore.completeGroup(messageGroup.getGroupId()); //now clear the messages for (Message<?> message : messageGroup.getMessages()) { messageStore.removeMessageFromGroup(groupId, message); } //end for //'add' the other message --> emulated by getting the messageGroup messageGroup = messageStore.getMessageGroup(groupId); //should be marked 'complete' --> old behavior it would not assertTrue(messageGroup.isComplete()); }