-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
SNS SMS support #457
Conversation
*/ | ||
package io.awspring.cloud.sns.sms.attributes; | ||
|
||
public class ADM { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
spring-cloud-aws-sns/src/main/java/io/awspring/cloud/sns/sms/core/SnsSmsOperations.java
Outdated
Show resolved
Hide resolved
Will commit sample in following days |
spring-cloud-aws-sns/src/main/java/io/awspring/cloud/sns/sms/attributes/AttributeCodes.java
Outdated
Show resolved
Hide resolved
…ttributes/AttributeCodes.java
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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!")); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Tried it against real AWS integration works as expected. |
Great job! Please add nullability annotations (including |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
📢 Type of change
📜 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
🔮 Next steps