softwaremill / elasticmq

In-memory message queue with an Amazon SQS-compatible interface. Runs stand-alone or embedded.
https://softwaremill.com/open-source/
Apache License 2.0
2.51k stars 194 forks source link

Feature Request: support SentTimestamp attribute #27

Closed AveryRegier closed 9 years ago

AveryRegier commented 9 years ago

I am using ElasticMQ to test a monitoring tool for SQS. The intent of the tool is to look at the age of the oldest items in the queue (or at least the first ones found by SQS) and alert if those messages are beyond a certain age.

ElasticMQ doesn't set this attribute (or any others that SQS may set) when messages are added to a queue. I have been able to work around it by adding a String attribute called SentTimestamp myself, however I'm unsure at this point how SQS itself will respond to that, especially since I think this should be a Number data type. When I try to add SentTimestamp with a Number data type as follows, I get this error:

public void put(Message message) {
    client.sendMessage(new SendMessageRequest(getQueueURL(), message.getContent())
            .withMessageAttributes(sentTimestamp()));
}

private Map<String, MessageAttributeValue> sentTimestamp() {
    Map<String,MessageAttributeValue> toReturn = new LinkedHashMap<String, MessageAttributeValue>();
    toReturn.put("SentTimestamp", new MessageAttributeValue()
            .withDataType("Number")
            .withStringValue(Long.toString(System.currentTimeMillis())));
    return toReturn;
}

[Fatal Error] :1:1: Content is not allowed in prolog. [Fatal Error] :1:1: Content is not allowed in prolog. [Fatal Error] :1:1: Content is not allowed in prolog. [Fatal Error] :1:1: Content is not allowed in prolog.

com.amazonaws.AmazonServiceException: Unable to unmarshall error response (There was an internal server error.) (Service: AmazonSQS; Status Code: 500; Error Code: 500 Internal Server Error; Request ID: null) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1073) at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:721) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:456) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:295) at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2291) at com.amazonaws.services.sqs.AmazonSQSClient.sendMessage(AmazonSQSClient.java:908) Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124) at com.amazonaws.util.XpathUtils.documentFrom(XpathUtils.java:125) at com.amazonaws.util.XpathUtils.documentFrom(XpathUtils.java:132) at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:80) at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:40) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1041) ... 32 more

AveryRegier commented 9 years ago

I solved my own problem. I was sending 'All' as a message attribute instead of just as a plain old attribute. Sorry for the spam.

adamw commented 9 years ago

No problem, I'm not 100% sure what was the root cause, but anyway if there's something that ElasticMQ should set (and what SQS sets) that would be useful for tests let me know, it should be added :)