Skip to content

Set JMSDeliveryTime to ApproximateFirstReceiveTimestamp #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ protected jakarta.jms.Message convertToJMSMessage(Message message) throws JMSExc
}

jmsMessage.setJMSTimestamp(getJMSTimestamp(message));
jmsMessage.setJMSDeliveryTime(getApproximateFirstReceiveTimestamp(message));
return jmsMessage;
}

Expand All @@ -395,6 +396,16 @@ private long getJMSTimestamp(Message message) {
}
}

private long getApproximateFirstReceiveTimestamp(Message message) {
Map<String, String> systemAttributes = message.attributesAsStrings();
String timestamp = systemAttributes.get(SQSMessagingClientConstants.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP);
if (timestamp != null) {
return Long.parseLong(timestamp);
} else {
return 0L;
}
}

protected void nackQueueMessages() {
// Also nack messages already in the messageQueue
synchronized (stateLock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class SQSMessagingClientConstants {

public static final String SEQUENCE_NUMBER = "SequenceNumber";

public static final String APPROXIMATE_FIRST_RECEIVE_TIMESTAMP = "ApproximateFirstReceiveTimestamp";

static final String APPENDED_USER_AGENT_HEADER_VERSION;
static {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class SQSMessage implements Message {
private String type;
private SQSQueueDestination replyTo;
private Destination destination;
private long deliveryTime;

private final Map<String, JMSMessagePropertyValue> properties = new HashMap<>();

Expand Down Expand Up @@ -422,13 +423,12 @@ public void setJMSExpiration(long expiration) throws JMSException {

@Override
public long getJMSDeliveryTime() throws JMSException {
// FIXME
return 0;
return deliveryTime;
}

@Override
public void setJMSDeliveryTime(long deliveryTime) throws JMSException {
// FIXME
this.deliveryTime = deliveryTime;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ public void testConvertToJMSMessageTextTypeAttribute(int numberOfMessagesToPrefe
long now = System.currentTimeMillis();
Map<String, String> mapAttributes = Map.of(
SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1",
SQSMessagingClientConstants.SENT_TIMESTAMP, Long.toString(now));
SQSMessagingClientConstants.SENT_TIMESTAMP, Long.toString(now),
SQSMessagingClientConstants.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP, Long.toString(now));

// Return message attributes with message type 'TEXT'
Message message = Message.builder()
Expand All @@ -1017,6 +1018,7 @@ public void testConvertToJMSMessageTextTypeAttribute(int numberOfMessagesToPrefe
assertTrue(jsmMessage instanceof SQSTextMessage);
assertEquals(message.body(), "MessageBody");
assertEquals(jsmMessage.getJMSTimestamp(), now);
assertEquals(jsmMessage.getJMSDeliveryTime(), now);
}

/**
Expand Down Expand Up @@ -1830,7 +1832,7 @@ public void testRequestedMessageTracking(int numberOfMessagesToPrefetch) throws

// Wait to make sure the received calls have gotten far enough to
// wait on the message queue
allReceivesWaiting.await();
allReceivesWaiting.await(1000, TimeUnit.MILLISECONDS);

assertEquals(concurrentReceives, consumerPrefetch.messagesRequested);

Expand Down