@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getMD5OfMessageBody() == null) ? 0 : getMD5OfMessageBody().hashCode()); hashCode = prime * hashCode + ((getMD5OfMessageAttributes() == null) ? 0 : getMD5OfMessageAttributes().hashCode()); hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode()); hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); return hashCode; }
static SendMessageResult convert(SendMessageBatchResultEntry br) { SendMessageResult toReturn = new SendMessageResult(); toReturn.setMD5OfMessageBody(br.getMD5OfMessageBody()); toReturn.setMessageId(br.getMessageId()); toReturn.setMD5OfMessageAttributes(br.getMD5OfMessageAttributes()); return toReturn; }
@Override public void onSuccess(SendMessageRequest request, SendMessageResult result) { if (logger.isDebugEnabled()) { logger.debug("-> Message id:" + result.getMessageId() + ", sequence number:" + result.getSequenceNumber()+" "+json+" "+position); } cc.markCompleted(); }
private <T extends Serializable> void sendMessageToLocalRegionSync(final T body) throws IOException { if ( sqs == null ) { logger.error( "SQS client is null, perhaps it failed to initialize successfully" ); return; } final String stringBody = toString( body ); if (logger.isDebugEnabled()) { logger.debug(" sendMessageToLocalRegion " + stringBody); } String url = getReadQueue().getUrl(); if ( logger.isTraceEnabled() ) { logger.trace( "Publishing Message...{} to url: {}", stringBody, url ); } SendMessageRequest messageRequest = new SendMessageRequest(url, stringBody); try { SendMessageResult result = sqs.sendMessage(messageRequest); if (logger.isTraceEnabled()) { logger.trace("Successfully published... messageID=[{}], arn=[{}]", result.getMessageId(), url); } } catch (Exception e) { logger.error(FAILED_TO_SEND_MESSAGE, messageRequest.getMessageBody(), url, e); sendMessageToLocalRegionAsync(body); } }
/** * Throw an exception if the MD5 checksums returned in the SendMessageResult do not match the * client-side calculation based on the original message in the SendMessageRequest. */ private static void sendMessageOperationMd5Check(SendMessageRequest sendMessageRequest, SendMessageResult sendMessageResult) { String messageBodySent = sendMessageRequest.getMessageBody(); String bodyMd5Returned = sendMessageResult.getMD5OfMessageBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBodySent); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)); } Map<String, MessageAttributeValue> messageAttrSent = sendMessageRequest.getMessageAttributes(); if (messageAttrSent != null && !messageAttrSent.isEmpty()) { String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttrSent); String attrMd5Returned = sendMessageResult.getMD5OfMessageAttributes(); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)); } } }
@Override public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) { // Throw a throttling exception for a specific queue name for testing purposes. if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } // Throw an illegal state exception for a specific queue name for testing purposes. if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME)) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName)); } // Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published. return new SendMessageResult().withMessageId(AbstractDaoTest.MESSAGE_ID); } }
/** * <p> * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon * SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For * information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * </p> * * @param mD5OfMessageAttributes * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that * Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 * digest. For information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public SendMessageResult withMD5OfMessageAttributes(String mD5OfMessageAttributes) { setMD5OfMessageAttributes(mD5OfMessageAttributes); return this; }
/** * <p> * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon * SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For * information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * </p> * * @param mD5OfMessageBody * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that * Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 * digest. For information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public SendMessageResult withMD5OfMessageBody(String mD5OfMessageBody) { setMD5OfMessageBody(mD5OfMessageBody); return this; }
@Override protected void additionalOnSuccessHeaders(AbstractIntegrationMessageBuilder<?> messageBuilder, AmazonWebServiceRequest request, Object result) { if (result instanceof SendMessageResult) { SendMessageResult sendMessageResult = (SendMessageResult) result; messageBuilder.setHeaderIfAbsent(AwsHeaders.MESSAGE_ID, sendMessageResult.getMessageId()); messageBuilder.setHeaderIfAbsent(AwsHeaders.SEQUENCE_NUMBER, sendMessageResult.getSequenceNumber()); } }
/** * Send an event message to SQS. * * @param event * @throws SiteWhereException */ protected void sendSqsMessage(IDeviceEvent event) throws SiteWhereException { SendMessageRequest message = new SendMessageRequest(); message.setMessageBody(MarshalUtils.marshalJsonAsString(event)); message.setQueueUrl(getQueueUrl()); SendMessageResult result = getSqs().sendMessage(message); LOGGER.debug("Sent SQS message with id: " + result.getMessageId()); }
/** * Throw an exception if the MD5 checksums returned in the SendMessageResult * do not match the client-side calculation based on the original message in * the SendMessageRequest. */ private static void sendMessageOperationMd5Check(SendMessageRequest sendMessageRequest, SendMessageResult sendMessageResult) { String messageBodySent = sendMessageRequest.getMessageBody(); String bodyMd5Returned = sendMessageResult.getMD5OfMessageBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBodySent); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw new AmazonClientException(String.format( MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)); } Map<String, MessageAttributeValue> messageAttrSent = sendMessageRequest .getMessageAttributes(); if (messageAttrSent != null && !messageAttrSent.isEmpty()) { String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttrSent); String attrMd5Returned = sendMessageResult.getMD5OfMessageAttributes(); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw new AmazonClientException(String.format( MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)); } } }
@Test public void testSendMessage() { // Send an SQS message without specifying HTTP proxy settings. assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao.sendMessage( new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, NO_HTTP_PROXY_HOST, NO_HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Send an SQS message using proxy settings. assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao .sendMessage(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Publish an SQS message with message headers. assertEquals(new SendMessageResult().withMessageId(MESSAGE_ID), sqsDao.sendMessage( new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, NO_HTTP_PROXY_HOST, NO_HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)))); } }
/** * <p> * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon * SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For * information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * </p> * * @param mD5OfMessageAttributes * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that * Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 * digest. For information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public SendMessageResult withMD5OfMessageAttributes(String mD5OfMessageAttributes) { setMD5OfMessageAttributes(mD5OfMessageAttributes); return this; }
/** * <p> * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon * SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For * information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * </p> * * @param mD5OfMessageBody * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that * Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 * digest. For information about MD5, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public SendMessageResult withMD5OfMessageBody(String mD5OfMessageBody) { setMD5OfMessageBody(mD5OfMessageBody); return this; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof SendMessageResult == false) return false; SendMessageResult other = (SendMessageResult) obj; if (other.getMD5OfMessageBody() == null ^ this.getMD5OfMessageBody() == null) return false; if (other.getMD5OfMessageBody() != null && other.getMD5OfMessageBody().equals(this.getMD5OfMessageBody()) == false) return false; if (other.getMD5OfMessageAttributes() == null ^ this.getMD5OfMessageAttributes() == null) return false; if (other.getMD5OfMessageAttributes() != null && other.getMD5OfMessageAttributes().equals(this.getMD5OfMessageAttributes()) == false) return false; if (other.getMessageId() == null ^ this.getMessageId() == null) return false; if (other.getMessageId() != null && other.getMessageId().equals(this.getMessageId()) == false) return false; if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) return false; if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) return false; return true; }
public SendMessageResult unmarshall(StaxUnmarshallerContext context) throws Exception { SendMessageResult sendMessageResult = new SendMessageResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; sendMessageResult.setMD5OfMessageBody(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; sendMessageResult.setMD5OfMessageAttributes(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; sendMessageResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; sendMessageResult.setSequenceNumber(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
@Override protected void additionalOnSuccessHeaders(AbstractIntegrationMessageBuilder<?> messageBuilder, AmazonWebServiceRequest request, Object result) { if (result instanceof SendMessageResult) { SendMessageResult sendMessageResult = (SendMessageResult) result; messageBuilder.setHeaderIfAbsent(AwsHeaders.MESSAGE_ID, sendMessageResult.getMessageId()); messageBuilder.setHeaderIfAbsent(AwsHeaders.SEQUENCE_NUMBER, sendMessageResult.getSequenceNumber()); } }
public static String sendMessage(String relativeQueueUrl, String message, Map<String,CQSMessageAttribute> messageAttributes) throws Exception { long ts1 = System.currentTimeMillis(); String receiptHandle = null; if (useInlineApiCalls) { receiptHandle = CQSAPI.sendMessage(cnsInternal.getUserId(), relativeQueueUrl, message, null, messageAttributes); } else { String absoluteQueueUrl = Util.getAbsoluteQueueUrlForRelativeUrl(relativeQueueUrl); SendMessageRequest sendMessageRequest = new SendMessageRequest(absoluteQueueUrl, message); if (messageAttributes != null) { for (String messageAttributeName : messageAttributes.keySet()) { MessageAttributeValue value = new MessageAttributeValue(); value.setDataType(messageAttributes.get(messageAttributeName).getDataType()); value.setStringValue(messageAttributes.get(messageAttributeName).getStringValue()); sendMessageRequest.addMessageAttributesEntry(messageAttributeName, value); } } SendMessageResult sendMessageResult = sqs.sendMessage(sendMessageRequest); receiptHandle = sendMessageResult.getMessageId(); } long ts2 = System.currentTimeMillis(); CMBControllerServlet.valueAccumulator.addToCounter(AccumulatorName.CNSCQSTime, ts2 - ts1); logger.debug("event=send_message message_id=" + receiptHandle); return receiptHandle; }
/** * Throw an exception if the MD5 checksums returned in the SendMessageResult do not match the * client-side calculation based on the original message in the SendMessageRequest. */ private static void sendMessageOperationMd5Check(SendMessageRequest sendMessageRequest, SendMessageResult sendMessageResult) { String messageBodySent = sendMessageRequest.getMessageBody(); String bodyMd5Returned = sendMessageResult.getMD5OfMessageBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBodySent); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)); } Map<String, MessageAttributeValue> messageAttrSent = sendMessageRequest.getMessageAttributes(); if (messageAttrSent != null && !messageAttrSent.isEmpty()) { String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttrSent); String attrMd5Returned = sendMessageResult.getMD5OfMessageAttributes(); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)); } } }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getMD5OfMessageBody() != null) sb.append("MD5OfMessageBody: ").append(getMD5OfMessageBody()).append(","); if (getMD5OfMessageAttributes() != null) sb.append("MD5OfMessageAttributes: ").append(getMD5OfMessageAttributes()).append(","); if (getMessageId() != null) sb.append("MessageId: ").append(getMessageId()).append(","); if (getSequenceNumber() != null) sb.append("SequenceNumber: ").append(getSequenceNumber()); sb.append("}"); return sb.toString(); }