Below is the program that I am using to publish a message to SNS. There is no issue when I execute this program(simple Java or Spring boot) in my local system. The message is published on the topic.
But, the actual program runs inside a thread in a spring boot project. The thread runs every 1 minute. Whenever the thread runs, the below program has to publish the message. This spring boot project deployed inside a standalone Unix server. From the server, it is not publishing messages. There is no exception. The logs are showing a successful handshake to the Amazon network.
I tried AmazonSNS and SnsClient classes as well.
AmazonSNSAsync snsClient1 = AmazonSNSAsyncClient.asyncBuilder()
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials("access-key",
"secret-key")))
.withRegion("us-east-1")
.build();
log.info("STATUS: snsClient1 formed");
PublishRequest publishReq =
new PublishRequest()
.withTopicArn("sns_topic-arn")
.withMessage("mes: " message);
log.info("STATUS: publishReq formed");
snsClient1.publishAsync(publishReq);
I tried the below things already.
- moved the program out of the thread
- tried with a new topic
- used the latest dependency of SNS
However, when I published a message from the Unix box using AWS CLI, the message was published successfully.
Did anyone face a similar issue? If not, you can share any alternative way to hit the SNS from a Java program if you know.
CodePudding user response:
The issue is partially fixed. AWS SDK was throwing an error, not an exception. That was the cause of the code block. Once, I catch with the "Throwable" keyword, the program is not stopping.
Later, I used the bom concepts to avoid the transitive dependency version conflicts and converted all the AWS SDK 1 code into SDK 2 code. Now, the message is posted on the SNS topic. But, the weird thing is that SDK2 also throws a similar error. I am trying to fix it.
Reference:
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/sns/src/main/java/com/example/sns/PublishTopic.java
Meanwhile, you can track the issue on the below page as well.