Skip to content
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

Version 1.0.0 of the SNSExtendedClient #1

Merged
merged 8 commits into from
Aug 6, 2020
Merged

Version 1.0.0 of the SNSExtendedClient #1

merged 8 commits into from
Aug 6, 2020

Conversation

aws-rizi
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aws-rizi aws-rizi force-pushed the rizi-dev branch 3 times, most recently from a4a69ef to 31827f7 Compare July 29, 2020 05:39
@aws-rizi aws-rizi requested a review from adam-aws July 29, 2020 17:24
adam-aws
adam-aws previously approved these changes Jul 29, 2020
aws-ivvladim
aws-ivvladim previously approved these changes Jul 30, 2020
@aws-rizi aws-rizi requested a review from coulaudf July 30, 2020 16:09

/**
* <p>
* Sends a message to an Amazon SNS topic or sends a text message (SMS message) directly to a phone number.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is misleading since the extended client will only handle SQS endpoints

Copy link
Contributor Author

@aws-rizi aws-rizi Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now SNSExtended only works with SQSExtended but it might be enriched to support other endpoints in future. Do you think I should remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since right now the extended client only supports SQS I think we should make this clear in the java doc. In the future, when we support other endpoint we may update the documentation.

*/
public AmazonSNSExtendedClient(AmazonSNS snsClient, PayloadStorageConfiguration payloadStorageConfiguration) {
super(snsClient);
this.payloadStorageConfiguration = new PayloadStorageConfiguration(payloadStorageConfiguration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think the copy constructor is needed here?

Copy link
Contributor Author

@aws-rizi aws-rizi Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed making copy.
I think we do not need that since we do not do any modification on received object.

private PayloadStore payloadStore;
private PayloadStorageConfiguration payloadStorageConfiguration;

public AmazonSNSExtendedClient(AmazonSNS amazonSNSToBeExtended) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going to happen if the client object is used and the payloadStorageConfiguration is not initialized? My guess is will be getting a couple of NPE all over the code.

I believe we should remove this constructor or set a default configuration (if possible).

totalMsgAttributesSize += Util.getStringSizeInBytes(stringVal);
}

ByteBuffer binaryVal = entryVal.getBinaryValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can de an else

Copy link
Contributor Author

@aws-rizi aws-rizi Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change the code to

String stringVal = entryVal.getStringValue();
if (stringVal != null) {
    totalMsgAttributesSize += Util.getStringSizeInBytes(stringVal);
} else {
    totalMsgAttributesSize += entryVal.getBinaryValue().array().length;
}

But if entryVal.getBinaryValue() is null then it will throw a null exception. but I think the current code is fine.

}
}

private void checkSizeOfMessageAttributes(Map<String, MessageAttributeValue> messageAttributes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this method name to validateMessageAttributesAndCalculate size and return the message size instead of void. This will allow to use the already calculated message size in the isLarge method, avoiding the calculation again

}
}

private boolean isLarge(PublishRequest publishRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra param for the size of messages attributes, already calculated in the attributes validation

messageAttributeValue.setStringValue(messageContentSize.toString());
publishRequest.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);

checkSizeOfMessageAttributes(publishRequest.getMessageAttributes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just add the size of the new attribute to the already calculated size avoid the calculation again

@aws-rizi aws-rizi merged commit 8032871 into master Aug 6, 2020
@aws-rizi aws-rizi mentioned this pull request Aug 7, 2020
@aws-rizi aws-rizi deleted the rizi-dev branch August 20, 2020 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants