use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class MySqlJdbcMessageStoreTests method testMessagePollingFromTheGroup.
@Test
@Transactional
public void testMessagePollingFromTheGroup() throws Exception {
final String groupX = "X";
messageStore.addMessageToGroup(groupX, MessageBuilder.withPayload("foo").setCorrelationId(groupX).build());
Thread.sleep(100);
messageStore.addMessageToGroup(groupX, MessageBuilder.withPayload("bar").setCorrelationId(groupX).build());
Thread.sleep(100);
messageStore.addMessageToGroup(groupX, MessageBuilder.withPayload("baz").setCorrelationId(groupX).build());
Thread.sleep(100);
messageStore.addMessageToGroup("Y", MessageBuilder.withPayload("barA").setCorrelationId(groupX).build());
Thread.sleep(100);
messageStore.addMessageToGroup("Y", MessageBuilder.withPayload("bazA").setCorrelationId(groupX).build());
Thread.sleep(100);
MessageGroup group = messageStore.getMessageGroup(groupX);
assertEquals(3, group.size());
Message<?> message1 = messageStore.pollMessageFromGroup(groupX);
assertNotNull(message1);
assertEquals("foo", message1.getPayload());
group = messageStore.getMessageGroup(groupX);
assertEquals(2, group.size());
Message<?> message2 = messageStore.pollMessageFromGroup(groupX);
assertNotNull(message2);
assertEquals("bar", message2.getPayload());
group = messageStore.getMessageGroup(groupX);
assertEquals(1, group.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testExpireMessageGroupOnCreateOnly.
@Test
public void testExpireMessageGroupOnCreateOnly() throws Exception {
final String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
final CountDownLatch groupRemovalLatch = new CountDownLatch(1);
messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> {
messageGroupStore.removeMessageGroup(group.getGroupId());
groupRemovalLatch.countDown();
});
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
JdbcTemplate template = new JdbcTemplate(this.dataSource);
template.afterPropertiesSet();
template.update("UPDATE INT_MESSAGE_GROUP set CREATED_DATE=? where GROUP_KEY=? and REGION=?", (PreparedStatementSetter) ps -> {
ps.setTimestamp(1, new Timestamp(System.currentTimeMillis() - 10000));
ps.setString(2, UUIDConverter.getUUID(groupId).toString());
ps.setString(3, "DEFAULT");
});
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertTrue(groupRemovalLatch.await(10, TimeUnit.SECONDS));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testMessagePollingFromTheGroup.
@Test
public void testMessagePollingFromTheGroup() throws Exception {
String groupId = "X";
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("foo").setCorrelationId(groupId).build());
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("baz").setCorrelationId(groupId).build());
messageStore.addMessagesToGroup("Y", MessageBuilder.withPayload("barA").setCorrelationId(groupId).build(), MessageBuilder.withPayload("bazA").setCorrelationId(groupId).build());
MessageGroup group = messageStore.getMessageGroup("X");
assertEquals(3, group.size());
Message<?> message1 = messageStore.pollMessageFromGroup("X");
assertNotNull(message1);
assertEquals("foo", message1.getPayload());
group = messageStore.getMessageGroup("X");
assertEquals(2, group.size());
Message<?> message2 = messageStore.pollMessageFromGroup("X");
assertNotNull(message2);
assertEquals("bar", message2.getPayload());
group = messageStore.getMessageGroup("X");
assertEquals(1, group.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testRemoveMessageGroup.
@Test
public void testRemoveMessageGroup() throws Exception {
JdbcTemplate template = new JdbcTemplate(this.dataSource);
template.afterPropertiesSet();
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
messageStore.removeMessageGroup(groupId);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
String uuidGroupId = UUIDConverter.getUUID(groupId).toString();
assertTrue(template.queryForList("SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = ?", uuidGroupId).size() == 0);
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testExpireMessageGroupOnIdleOnly.
@Test
public void testExpireMessageGroupOnIdleOnly() throws Exception {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.setTimeoutOnIdle(true);
messageStore.addMessagesToGroup(groupId, message);
messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> messageGroupStore.removeMessageGroup(group.getGroupId()));
JdbcTemplate template = new JdbcTemplate(this.dataSource);
template.afterPropertiesSet();
updateMessageGroup(template, groupId, 1000);
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
updateMessageGroup(template, groupId, 2000);
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
group = messageStore.getMessageGroup(groupId);
assertEquals(2, group.size());
updateMessageGroup(template, groupId, 2000);
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
}
Aggregations