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

SNS SMS support #457

Merged
merged 23 commits into from
Sep 5, 2022
Merged

SNS SMS support #457

merged 23 commits into from
Sep 5, 2022

Conversation

MatejNedic
Copy link
Member

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

This is currently just a draft how I vision Spring Cloud AWS support for sending SMS messages.
Before I go further with tests @maciejwalkowiak please check design out.

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated reference documentation to reflect the change
  • All tests passing
  • No breaking changes

🔮 Next steps

*/
package io.awspring.cloud.sns.sms.attributes;

public class ADM {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered making these attribute classes immutable?

private Builder() {
}

public Builder withTtl(Long ttl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of consistency with other builder classes in the project and builder classes in AWS SDK, instead of "withers" method names should be just named with an attribute"

Builder ttl(Long ttl) {
...
}

*/
public class DefaultMessageAttributeConverter implements MessageAttributeConverter {

public Map<String, MessageAttributeValue> convert(SmsMessageAttributes attr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered moving this conversion to SmsMessageAttributes class? Does not seem like there can be any other reasonable implementation of MessageAttributeConverter interface

@github-actions github-actions bot added the type: documentation Documentation or Samples related issue label Jul 21, 2022
@MatejNedic MatejNedic marked this pull request as ready for review July 21, 2022 15:27
@MatejNedic
Copy link
Member Author

Will commit sample in following days

Copy link
Contributor

@maciejwalkowiak maciejwalkowiak left a comment

Choose a reason for hiding this comment

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

Please add @Nullable to attribute classes (I imagine all these parameters are nullable..?).

Also perhaps we can merge packages attributes and core into single sms - this way we could reduce the number of public classes

private String entityId;
private String templateId;
private String messageGroupId;
private String deduplicationId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Deduplication id makes sense only for sending to topics, so it should not be a property on the top level attributes used also for sending to a number. https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html

private String templateId;
private String messageGroupId;
private String deduplicationId;
private String messageStructure;
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see, the only valid value for message structure is "json" and it is used for sending to topic when more than single protocol endpoints are subscribed to this topic. I think this is "advanced" usage that we don't need to cover with SnsSmsTemaplte - we can support sending only to topics with sms endpoints or if we decide to support mixed topics, this has to be redesigned.


void sendToTopicArn(String topicArn, String message, SmsMessageAttributes attributes);

void sendToTargetArn(String targetArn, String message);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is actually the use case for sending to targetArn? As far as I could find out there is no use case for SMS to send to target arn. Only to topic or directly to a phone number.

@Test
void sendValidMessage_ToPhoneNumber() {
Assertions
.assertDoesNotThrow(() -> snsSmsTemplate.send("+385 00 000 0000", "Spring Cloud AWS got you covered!"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert log message from Localstack?

localstack/localstack#2822

Copy link
Member Author

Choose a reason for hiding this comment

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

At first glance, I am not seeing it in container logs but will check again later.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, we're only checking the message is sent and doesn't throw any errors. Maybe we can fetch the message from local stack after sending it, and assert that?

If there are any concurrency concerns, I usually use a CountDownLatch to wait on the test thread until the message is consumed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @tomazfernandes I tried with getting localstack logs but I am not seeing a message. We can on other hand make operations and template return messageId and check that. Localstack uses moto to mock sms sending.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @MatejNedic, nice work here! Sure, if the SNS API returns an id I guess we should return that to users.

This being an SNS integration, can't we maybe subscribe to the topic and receive the sent message ourselves too? Just guessing, have no clue how this actually works 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

@MatejNedic Did you set the DEBUG env var to "1"? in LocalStackContainer should be .withEnv("DEBUG", "1") and change the logger for testcontainers to DEBUG too <logger name="org.testcontainers" level="DEBUG"/> just to make sure something useful is in the container's log. Then you can fetch the logs doing String logs = localstack.getLogs(OutputFrame.OutputType.STDOUT, OutputFrame.OutputType.STDERR); and assert against it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@eddumelendez I tried that as well but I am not seeing the correct message I want to see.
Delivering SMS message to. I am seeing Publishing message to TopicArn: None | Message: Spring Cloud AWS got you covered which makes sense but is still not what I want. I have added tests with at least some kind of message. I tried this against real AWS and I am getting SMS on my phone number without an issue.

@tomazfernandes we have something similar for SNS notifications where we send it to an SQS and we poll it from SQS. Sadly with SMS we can't do that.

@maciejwalkowiak maciejwalkowiak added component: sns SNS integration related issue type: feature Integration with a new AWS service or bigger change in existing integration and removed type: documentation Documentation or Samples related issue labels Aug 3, 2022
@maciejwalkowiak maciejwalkowiak added this to the 3.0.0 M2 milestone Aug 3, 2022
@github-actions github-actions bot added the type: documentation Documentation or Samples related issue label Aug 29, 2022
@MatejNedic MatejNedic marked this pull request as draft August 29, 2022 17:57
@MatejNedic MatejNedic marked this pull request as ready for review August 31, 2022 17:58
@MatejNedic MatejNedic requested review from maciejwalkowiak and removed request for eddumelendez August 31, 2022 17:58
@MatejNedic
Copy link
Member Author

Tried it against real AWS integration works as expected.

@maciejwalkowiak
Copy link
Contributor

maciejwalkowiak commented Aug 31, 2022

Great job! Please add nullability annotations (including package-info.java) and javadocs on public classes & interfaces. Also, conflict has to be resolved.

@sonarcloud
Copy link

sonarcloud bot commented Sep 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@maciejwalkowiak maciejwalkowiak modified the milestones: 3.0.0 M2, 3.0.0 M3 Sep 2, 2022
@maciejwalkowiak maciejwalkowiak merged commit 204829f into awspring:main Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sns SNS integration related issue type: documentation Documentation or Samples related issue type: feature Integration with a new AWS service or bigger change in existing integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants