List of usage examples for com.amazonaws.services.sqs.model MessageAttributeValue getStringValue
public String getStringValue()
Strings are Unicode with UTF-8 binary encoding.
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
private int getMsgAttributesSize(Map<String, MessageAttributeValue> msgAttributes) { int totalMsgAttributesSize = 0; for (Entry<String, MessageAttributeValue> entry : msgAttributes.entrySet()) { totalMsgAttributesSize += getStringSizeInBytes(entry.getKey()); MessageAttributeValue entryVal = entry.getValue(); if (entryVal.getDataType() != null) { totalMsgAttributesSize += getStringSizeInBytes(entryVal.getDataType()); }/*ww w. ja v a2s .c o m*/ String stringVal = entryVal.getStringValue(); if (stringVal != null) { totalMsgAttributesSize += getStringSizeInBytes(entryVal.getStringValue()); } ByteBuffer binaryVal = entryVal.getBinaryValue(); if (binaryVal != null) { totalMsgAttributesSize += binaryVal.array().length; } } return totalMsgAttributesSize; }
From source file:com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.java
License:Open Source License
/** * Convert the return SQS message into JMS message * @param message SQS message to convert * @return Converted JMS message// ww w . j ava 2 s.c om * @throws JMSException */ protected javax.jms.Message convertToJMSMessage(Message message) throws JMSException { MessageAttributeValue messageTypeAttribute = message.getMessageAttributes() .get(SQSMessage.JMS_SQS_MESSAGE_TYPE); javax.jms.Message jmsMessage = null; if (messageTypeAttribute == null) { jmsMessage = new SQSTextMessage(acknowledger, queueUrl, message); } else { String messageType = messageTypeAttribute.getStringValue(); if (SQSMessage.BYTE_MESSAGE_TYPE.equals(messageType)) { try { jmsMessage = new SQSBytesMessage(acknowledger, queueUrl, message); } catch (JMSException e) { LOG.warn("MessageReceiptHandle - " + message.getReceiptHandle() + "cannot be serialized to BytesMessage", e); throw e; } } else if (SQSMessage.OBJECT_MESSAGE_TYPE.equals(messageType)) { jmsMessage = new SQSObjectMessage(acknowledger, queueUrl, message); } else if (SQSMessage.TEXT_MESSAGE_TYPE.equals(messageType)) { jmsMessage = new SQSTextMessage(acknowledger, queueUrl, message); } else { throw new JMSException("Not a supported JMS message type"); } } jmsMessage.setJMSDestination(sqsDestination); return jmsMessage; }
From source file:org.springframework.cloud.aws.messaging.core.QueueMessageUtils.java
License:Apache License
private static Object getNumberValue(MessageAttributeValue value) { String numberType = value.getDataType().substring(MessageAttributeDataTypes.NUMBER.length() + 1); try {/* w w w . j a va 2 s . co m*/ Class<? extends Number> numberTypeClass = Class.forName(numberType).asSubclass(Number.class); return NumberUtils.parseNumber(value.getStringValue(), numberTypeClass); } catch (ClassNotFoundException e) { throw new MessagingException(String.format( "Message attribute with value '%s' and data type '%s' could not be converted " + "into a Number because target class was not found.", value.getStringValue(), value.getDataType()), e); } }