Skip to content

SQSMessage: do not parse ReceiveCount attribute if it is not set #35

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 @@ -113,9 +113,10 @@ public class SQSMessage implements Message {
sqsMessageID = sqsMessage.getMessageId();
this.messageID = String.format(MESSAGE_ID_FORMAT,sqsMessageID);
Map<String,String> systemAttributes = sqsMessage.getAttributes();
int receiveCount = Integer.parseInt(systemAttributes.get(APPROXIMATE_RECEIVE_COUNT));
String receiveCountAttrib = systemAttributes.get(APPROXIMATE_RECEIVE_COUNT);
int receiveCount = receiveCountAttrib == null ? 0 : Integer.parseInt(receiveCountAttrib);

/**
/*
* JMSXDeliveryCount is set based on SQS ApproximateReceiveCount
* attribute.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

import javax.jms.JMSException;

import com.amazon.sqs.javamessaging.acknowledge.Acknowledger;
import org.junit.Test;

import com.amazon.sqs.javamessaging.message.SQSTextMessage;
Expand Down Expand Up @@ -49,6 +51,22 @@ public void testCreateMessageWithText() throws JMSException {
assertEquals(expectedPayload, actualPayload);
}

/**
* Test create message from SQS Message
*/
@Test
public void testCreateMessageFromSQSMessage() throws JMSException {
String messageBody = "theBody";
com.amazonaws.services.sqs.model.Message message =
new com.amazonaws.services.sqs.model.Message().withBody(messageBody);
Acknowledger acknowledger = mock(Acknowledger.class);

SQSTextMessage sqsTextMessage = new SQSTextMessage(acknowledger, "theQueueUrl", message);

assertEquals(messageBody, sqsTextMessage.getText());
}


/**
* Test create message and setting text
*/
Expand Down