OPEN - issue INT-1063: MessageStore: correlation and grouping API
https://jira.springsource.org/browse/INT-1063
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -19,6 +17,7 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.jdbc.util.SerializationUtils;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.util.UUIDConverter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
@@ -221,30 +220,7 @@ public class JdbcMessageStore implements MessageStore {
|
||||
}
|
||||
|
||||
private String getKey(Object input) {
|
||||
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (input instanceof UUID) {
|
||||
return input.toString();
|
||||
}
|
||||
|
||||
if (input instanceof String && ((String) input).length() < 100) {
|
||||
return (String) input;
|
||||
}
|
||||
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("MD5 algorithm not available. Fatal (should be in the JDK).");
|
||||
}
|
||||
|
||||
byte[] bytes = digest.digest(SerializationUtils.serialize(input));
|
||||
return String.format("%032x", new BigInteger(1, bytes));
|
||||
|
||||
return input==null ? null : UUIDConverter.getUUID(input).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,4 +241,19 @@ public class JdbcMessageStore implements MessageStore {
|
||||
|
||||
}
|
||||
|
||||
public void add(Object correlationId, Message<?> message) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void add(Object correlationId, Collection<Message<?>> messages) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void deleteAll(Object correlationId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,17 +24,17 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JdbcMessageStoreTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
|
||||
private JdbcMessageStore messageStore;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
messageStore = new JdbcMessageStore(dataSource);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testGetNonExistent() throws Exception {
|
||||
@@ -45,7 +45,7 @@ public class JdbcMessageStoreTests {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndGet() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
Message<String> saved = messageStore.put(message);
|
||||
assertNull(messageStore.get(message.getHeaders().getId()));
|
||||
Message<?> result = messageStore.get(saved.getHeaders().getId());
|
||||
@@ -58,7 +58,8 @@ public class JdbcMessageStoreTests {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndUpdate() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(
|
||||
"X").build();
|
||||
message = messageStore.put(message);
|
||||
message = MessageBuilder.fromMessage(message).setCorrelationId("Y").build();
|
||||
message = messageStore.put(message);
|
||||
@@ -89,15 +90,16 @@ public class JdbcMessageStoreTests {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndListByCorrelationId() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
|
||||
String correlationId = "X";
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(correlationId).build();
|
||||
messageStore.put(message);
|
||||
assertEquals(1, messageStore.list("X").size());
|
||||
assertEquals(1, messageStore.list(correlationId).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndDelete() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
message = messageStore.put(message);
|
||||
assertNotNull(messageStore.delete(message.getHeaders().getId()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user