RESOLVED - issue INT-1102: Add timestamp to JdbcMessageStore
This commit is contained in:
@@ -6,6 +6,7 @@ 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.List;
|
||||
import java.util.UUID;
|
||||
@@ -45,14 +46,14 @@ public class JdbcMessageStore implements MessageStore {
|
||||
*/
|
||||
public static final String DEFAULT_TABLE_PREFIX = "INT_";
|
||||
|
||||
private static final String LIST_MESSAGES_BY_CORRELATION_KEY = "SELECT MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES from %PREFIX%MESSAGE where CORRELATION_KEY=?";
|
||||
private static final String LIST_MESSAGES_BY_CORRELATION_KEY = "SELECT MESSAGE_ID, CREATED_DATE, CORRELATION_KEY, MESSAGE_BYTES from %PREFIX%MESSAGE where CORRELATION_KEY=?";
|
||||
|
||||
private static final String GET_MESSAGE = "SELECT MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES from %PREFIX%MESSAGE where MESSAGE_ID=?";
|
||||
private static final String GET_MESSAGE = "SELECT MESSAGE_ID, CREATED_DATE, CORRELATION_KEY, MESSAGE_BYTES from %PREFIX%MESSAGE where MESSAGE_ID=?";
|
||||
|
||||
private static final String DELETE_MESSAGE = "DELETE from %PREFIX%MESSAGE where MESSAGE_ID=?";
|
||||
|
||||
private static final String CREATE_MESSAGE = "INSERT into %PREFIX%MESSAGE(MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES)"
|
||||
+ " values (?, ?, ?)";
|
||||
private static final String CREATE_MESSAGE = "INSERT into %PREFIX%MESSAGE(MESSAGE_ID, CREATED_DATE, CORRELATION_KEY, MESSAGE_BYTES)"
|
||||
+ " values (?, ?, ?, ?)";
|
||||
|
||||
public static final int DEFAULT_LONG_STRING_LENGTH = 2500;
|
||||
|
||||
@@ -62,6 +63,12 @@ public class JdbcMessageStore implements MessageStore {
|
||||
*/
|
||||
public static final String SAVED_KEY = JdbcMessageStore.class.getSimpleName() + ".SAVED";
|
||||
|
||||
/**
|
||||
* The name of the message header that stores a timestamp for the time the
|
||||
* message was inserted.
|
||||
*/
|
||||
public static final String CREATED_DATE_KEY = JdbcMessageStore.class.getSimpleName() + ".CREATED_DATE";
|
||||
|
||||
private String tablePrefix = DEFAULT_TABLE_PREFIX;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
@@ -192,7 +199,9 @@ public class JdbcMessageStore implements MessageStore {
|
||||
}
|
||||
}
|
||||
|
||||
Message<T> result = MessageBuilder.fromMessage(message).setHeader(SAVED_KEY, Boolean.TRUE).build();
|
||||
final long createdDate = System.currentTimeMillis();
|
||||
Message<T> result = MessageBuilder.fromMessage(message).setHeader(SAVED_KEY, Boolean.TRUE).setHeader(
|
||||
CREATED_DATE_KEY, new Long(createdDate)).build();
|
||||
final String messageId = getKey(result.getHeaders().getId());
|
||||
final String correlationId = getKey(result.getHeaders().getCorrelationId());
|
||||
final byte[] messageBytes = SerializationUtils.serialize(result);
|
||||
@@ -201,8 +210,9 @@ public class JdbcMessageStore implements MessageStore {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
logger.debug("Inserting message with id key=" + messageId);
|
||||
ps.setString(1, messageId);
|
||||
ps.setString(2, correlationId);
|
||||
lobHandler.getLobCreator().setBlobAsBytes(ps, 3, messageBytes);
|
||||
ps.setTimestamp(2, new Timestamp(createdDate));
|
||||
ps.setString(3, correlationId);
|
||||
lobHandler.getLobCreator().setBlobAsBytes(ps, 4, messageBytes);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
CREATE TABLE INT_MESSAGE (
|
||||
MESSAGE_ID VARCHAR(100) NOT NULL PRIMARY KEY,
|
||||
CREATED_DATE TIMESTAMP NOT NULL,
|
||||
CORRELATION_KEY VARCHAR(100),
|
||||
MESSAGE_BYTES BLOB
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.integration.test.matcher.PayloadAndHeaderMatcher.sameExceptImmutableHeaders;
|
||||
import static org.springframework.integration.test.matcher.PayloadAndHeaderMatcher.sameExceptIgnorableHeaders;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -50,7 +50,9 @@ public class JdbcMessageStoreTests {
|
||||
assertNull(messageStore.get(message.getHeaders().getId()));
|
||||
Message<?> result = messageStore.get(saved.getHeaders().getId());
|
||||
assertNotNull(result);
|
||||
assertThat(saved, sameExceptImmutableHeaders(result));
|
||||
assertThat(saved, sameExceptIgnorableHeaders(result));
|
||||
assertNotNull(result.getHeaders().get(JdbcMessageStore.SAVED_KEY));
|
||||
assertNotNull(result.getHeaders().get(JdbcMessageStore.CREATED_DATE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,7 +82,7 @@ public class JdbcMessageStoreTests {
|
||||
Message<String> copy = MessageBuilder.fromMessage(saved).build();
|
||||
Message<String> result = messageStore.put(copy);
|
||||
assertNotSame(copy, result);
|
||||
assertThat(saved, sameExceptImmutableHeaders(result));
|
||||
assertThat(saved, sameExceptIgnorableHeaders(result, JdbcMessageStore.CREATED_DATE_KEY));
|
||||
assertNotNull(messageStore.get(saved.getHeaders().getId()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user