Search in sources :

Example 36 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class ConfigurableMongoDbMessageStore method getMessageGroup.

@Override
public MessageGroup getMessageGroup(Object groupId) {
    Assert.notNull(groupId, "'groupId' must not be null");
    Query query = groupOrderQuery(groupId);
    MessageDocument messageDocument = this.mongoTemplate.findOne(query, MessageDocument.class, this.collectionName);
    if (messageDocument != null) {
        long createdTime = messageDocument.getGroupCreatedTime();
        long lastModifiedTime = messageDocument.getLastModifiedTime();
        boolean complete = messageDocument.isComplete();
        int lastReleasedSequence = messageDocument.getLastReleasedSequence();
        MessageGroup messageGroup = getMessageGroupFactory().create(this, groupId, createdTime, complete);
        messageGroup.setLastModified(lastModifiedTime);
        messageGroup.setLastReleasedMessageSequenceNumber(lastReleasedSequence);
        return messageGroup;
    } else {
        return new SimpleMessageGroup(groupId);
    }
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 37 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class ConfigurableMongoDbMessageStore method expireMessageGroups.

@Override
@ManagedOperation
public int expireMessageGroups(long timeout) {
    int count = 0;
    long threshold = System.currentTimeMillis() - timeout;
    for (MessageGroup group : this) {
        long timestamp = group.getTimestamp();
        if (this.isTimeoutOnIdle() && group.getLastModified() > 0) {
            timestamp = group.getLastModified();
        }
        if (timestamp <= threshold) {
            count++;
            expire(group);
        }
    }
    return count;
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 38 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MongoDbMessageStore method getMessageGroup.

@Override
public MessageGroup getMessageGroup(Object groupId) {
    Assert.notNull(groupId, "'groupId' must not be null");
    Query query = whereGroupIdOrder(groupId);
    MessageWrapper messageWrapper = this.template.findOne(query, MessageWrapper.class, this.collectionName);
    if (messageWrapper != null) {
        long createdTime = messageWrapper.get_Group_timestamp();
        long lastModifiedTime = messageWrapper.get_Group_update_timestamp();
        boolean complete = messageWrapper.get_Group_complete();
        int lastReleasedSequence = messageWrapper.get_LastReleasedSequenceNumber();
        MessageGroup messageGroup = getMessageGroupFactory().create(this, groupId, createdTime, complete);
        messageGroup.setLastModified(lastModifiedTime);
        messageGroup.setLastReleasedMessageSequenceNumber(lastReleasedSequence);
        return messageGroup;
    } else {
        return new SimpleMessageGroup(groupId);
    }
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 39 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MongoDbMessageStore method iterator.

@Override
public Iterator<MessageGroup> iterator() {
    List<MessageGroup> messageGroups = new ArrayList<>();
    Query query = Query.query(Criteria.where(GROUP_ID_KEY).exists(true));
    @SuppressWarnings("rawtypes") Iterable<String> groupIds = this.template.getCollection(this.collectionName).distinct(GROUP_ID_KEY, query.getQueryObject(), String.class);
    for (Object groupId : groupIds) {
        messageGroups.add(getMessageGroup(groupId));
    }
    return messageGroups.iterator();
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject)

Example 40 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MySqlJdbcMessageStoreTests method testUpdateLastReleasedSequence.

@Test
@Transactional
public void testUpdateLastReleasedSequence() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(groupId, message);
    messageStore.setLastReleasedSequenceNumberForGroup(groupId, 5);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(5, group.getLastReleasedMessageSequenceNumber());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MessageGroup (org.springframework.integration.store.MessageGroup)98 Test (org.junit.Test)79 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)54 GenericMessage (org.springframework.messaging.support.GenericMessage)36 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)25 Message (org.springframework.messaging.Message)20 ArrayList (java.util.ArrayList)19 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)15 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)14 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)13 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)13 MongoClient (com.mongodb.MongoClient)12 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)12 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 List (java.util.List)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 UUID (java.util.UUID)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HashMap (java.util.HashMap)5