AWS SQS 和 SES 依赖库相互影响



我正在尝试同时使用来自SES和SQS的导入,但是这种组合导致.withBody方法引发错误。我猜这与依赖项有关,但它们是最新版本。

错误:(116,54( java:不兼容类型:com.amazonaws.services.simpleemail.model.Body 无法转换为 java.lang.String

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.ReceiveMessageRequest;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import com.amazonaws.services.simpleemail.model.*;
public void email(S3Event event, Person person, Boolean error) {
ObjectMapper mapper = new ObjectMapper();
String emailText = null;
if (error) {
emailText = "Error! No image in file!";
} else {
try {
emailText = mapper.writeValueAsString(person);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
String key = event.getRecords().get(0).getS3().getObject().getKey();
AmazonSimpleEmailService client =            
AmazonSimpleEmailServiceClientBuilder.standard().withRegion(Regions.EU_WEST_1).build();
Body body = new Body().withText(new Content().withData(emailText));
SendEmailRequest request = new SendEmailRequest().withDestination(
new Destination().withToAddresses(person.getEmail()))
.withMessage(new Message()
.withBody(new Body().withHtml(new 
Content().withCharset("UTF8").withData(emailText)))
.withSubject(new Content()
.withCharset("UTF-8").withData("Message from passport service.")))
.withSource(person.getEmail());
client.sendEmail(request);
}
public void getBaseCodeFromSQS() {
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
try {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("https://sqs.eu-  
west-1.amazonaws.com/416031944655/TISFEXP-PSS-2-QUEUE");
List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
for (Message message : messages) {
LOGGER.info("MessageId:     " + message.getMessageId());
LOGGER.info("ReceiptHandle: " + message.getReceiptHandle());
LOGGER.info("MD5OfBody:     " + message.getMD5OfBody());
LOGGER.info("Body:          " + message.getBody());
for (final Map.Entry<String, String> entry : message.getAttributes().entrySet())     
{
LOGGER.info("Attribute - Name:  " + entry.getKey());
LOGGER.info("Attribute - Value: " + entry.getValue());
}
}
} catch (Exception e) {
LOGGER.error(e);
}
}
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>1.11.634</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
<version>1.0.8</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<version>1.11.634</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.634</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

在 SES 和 SQS 包中都定义了 Message 类。您正在使用 SQS 包中定义的 Message 类。您应该改用 SES 包中定义的那个。

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/model/Message.html

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/simpleemail/model/Message.html

SendEmailRequest request = new SendEmailRequest().withDestination(
new Destination().withToAddresses(person.getEmail()))
.withMessage(new com.amazonaws.services.simpleemail.model.Message()
.withBody(new Body().withHtml(new 
Content().withCharset("UTF8").withData(emailText)))
.withSubject(new Content()
.withCharset("UTF-8").withData("Message from passport service.")))
.withSource(person.getEmail());

相关内容

  • 没有找到相关文章

最新更新