[JAVA-23452] Clean up
This commit is contained in:
parent
da7c711f25
commit
8a7e667f0d
|
@ -36,6 +36,11 @@
|
|||
<version>${dynamodblocal.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -80,7 +85,7 @@
|
|||
|
||||
<properties>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<dynamodblocal.version>2.0.0</dynamodblocal.version>
|
||||
<dynamodblocal.version>1.21.1</dynamodblocal.version>
|
||||
<commons-codec-version>1.10.L001</commons-codec-version>
|
||||
<jets3t-version>0.9.4.0006L</jets3t-version>
|
||||
<maven-plugins-version>3.1.1</maven-plugins-version>
|
||||
|
|
|
@ -47,7 +47,6 @@ public class EC2Application {
|
|||
.cidrIp("0.0.0.0/0")
|
||||
.build();
|
||||
|
||||
|
||||
IpPermission ipPermission1 = IpPermission.builder()
|
||||
.ipRanges(Arrays.asList(ipRange1))
|
||||
.ipProtocol("tcp")
|
||||
|
@ -86,6 +85,7 @@ public class EC2Application {
|
|||
|
||||
// Launch an Amazon Instance
|
||||
RunInstancesRequest runInstancesRequest = RunInstancesRequest.builder()
|
||||
.imageId("ami-97785bed")
|
||||
.instanceType("t2.micro") // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
|
||||
.minCount(1)
|
||||
.maxCount(1)
|
||||
|
@ -119,12 +119,10 @@ public class EC2Application {
|
|||
ec2Client.unmonitorInstances(unmonitorInstancesRequest);
|
||||
|
||||
// Reboot an Instance
|
||||
|
||||
RebootInstancesRequest rebootInstancesRequest = RebootInstancesRequest.builder()
|
||||
.instanceIds(yourInstanceId)
|
||||
.build();
|
||||
|
||||
|
||||
ec2Client.rebootInstances(rebootInstancesRequest);
|
||||
|
||||
// Stop an Instance
|
||||
|
|
|
@ -102,7 +102,6 @@ public class AWSRDSService {
|
|||
logger.info(identifier + "\t" + engine + "\t" + status);
|
||||
logger.info("\t" + endpointUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Delete RDS instance
|
||||
|
@ -119,13 +118,13 @@ public class AWSRDSService {
|
|||
// Information about the RDS instance being deleted
|
||||
String status = response.dbInstance().dbInstanceStatus();
|
||||
Endpoint endpoint = response.dbInstance().endpoint();
|
||||
String endpoint_url = "Endpoint URL not available yet.";
|
||||
String endpointUrl = "Endpoint URL not available yet.";
|
||||
if (endpoint != null) {
|
||||
endpoint_url = endpoint.toString();
|
||||
endpointUrl = endpoint.toString();
|
||||
}
|
||||
|
||||
logger.info(identifier + "\t" + status);
|
||||
logger.info(endpoint_url);
|
||||
logger.info(endpointUrl);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ public class SQSApplication {
|
|||
private static final String FIFO_QUEUE_NAME = "baeldung-queue.fifo";
|
||||
private static final String DEAD_LETTER_QUEUE_NAME = "baeldung-dead-letter-queue";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Set up the client
|
||||
|
@ -47,12 +46,10 @@ public class SQSApplication {
|
|||
|
||||
System.out.println("\nGet queue url");
|
||||
|
||||
GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest
|
||||
.builder()
|
||||
GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest.builder()
|
||||
.queueName(STANDARD_QUEUE_NAME)
|
||||
.build()
|
||||
);
|
||||
String standardQueueUrl = getQueueUrlResponse.queueUrl();
|
||||
.build());
|
||||
String standardQueueUrl = getQueueUrlResponse.queueUrl();
|
||||
|
||||
System.out.println(standardQueueUrl);
|
||||
|
||||
|
@ -68,12 +65,11 @@ public class SQSApplication {
|
|||
|
||||
sqsClient.createQueue(createFifoQueueRequest);
|
||||
|
||||
GetQueueUrlResponse getFifoQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest
|
||||
.builder()
|
||||
GetQueueUrlResponse getFifoQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest.builder()
|
||||
.queueName(FIFO_QUEUE_NAME)
|
||||
.build());
|
||||
|
||||
String fifoQueueUrl = getFifoQueueUrlResponse.queueUrl();
|
||||
String fifoQueueUrl = getFifoQueueUrlResponse.queueUrl();
|
||||
|
||||
System.out.println(fifoQueueUrl);
|
||||
|
||||
|
@ -82,7 +78,8 @@ public class SQSApplication {
|
|||
.queueName(DEAD_LETTER_QUEUE_NAME)
|
||||
.build();
|
||||
|
||||
String deadLetterQueueUrl = sqsClient.createQueue(createDeadLetterQueueRequest).queueUrl();
|
||||
String deadLetterQueueUrl = sqsClient.createQueue(createDeadLetterQueueRequest)
|
||||
.queueUrl();
|
||||
|
||||
GetQueueAttributesRequest getQueueAttributesRequest = GetQueueAttributesRequest.builder()
|
||||
.queueUrl(deadLetterQueueUrl)
|
||||
|
@ -94,11 +91,13 @@ public class SQSApplication {
|
|||
String deadLetterQueueARN = deadLetterQueueAttributes.attributes()
|
||||
.get("QueueArn");
|
||||
|
||||
Map<QueueAttributeName, String> attributes = new HashMap<>();
|
||||
attributes.put(QueueAttributeName.REDRIVE_POLICY, "{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"" + deadLetterQueueARN + "\"}");
|
||||
|
||||
SetQueueAttributesRequest queueAttributesRequest = SetQueueAttributesRequest.builder()
|
||||
.queueUrl(standardQueueUrl)
|
||||
.attributes(null)
|
||||
.attributes(attributes)
|
||||
.build();
|
||||
// .addAttributesEntry("RedrivePolicy", "{\"maxReceiveCount\":\"2\", " + "\"deadLetterTargetArn\":\"" + deadLetterQueueARN + "\"}");
|
||||
|
||||
sqsClient.setQueueAttributes(queueAttributesRequest);
|
||||
|
||||
|
@ -161,21 +160,22 @@ public class SQSApplication {
|
|||
|
||||
ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder()
|
||||
.waitTimeSeconds(10)
|
||||
.maxNumberOfMessages(1)
|
||||
.maxNumberOfMessages(10)
|
||||
.build();
|
||||
|
||||
|
||||
List<Message> sqsMessages = sqsClient.receiveMessage(receiveMessageRequest)
|
||||
.messages();
|
||||
|
||||
|
||||
sqsMessages.get(0).attributes();
|
||||
sqsMessages.get(0).body();
|
||||
sqsMessages.get(0)
|
||||
.attributes();
|
||||
sqsMessages.get(0)
|
||||
.body();
|
||||
|
||||
// Delete a message from a queue
|
||||
DeleteMessageRequest deleteMessageRequest = DeleteMessageRequest.builder()
|
||||
.queueUrl(fifoQueueUrl)
|
||||
.receiptHandle(sqsMessages.get(0).receiptHandle())
|
||||
.receiptHandle(sqsMessages.get(0)
|
||||
.receiptHandle())
|
||||
.build();
|
||||
|
||||
sqsClient.deleteMessage(deleteMessageRequest);
|
||||
|
@ -185,7 +185,6 @@ public class SQSApplication {
|
|||
.queueUrl(standardQueueUrl)
|
||||
.build();
|
||||
|
||||
|
||||
GetQueueAttributesResponse attributesResponse = sqsClient.getQueueAttributes(getQueueAttributesRequestForMonitoring);
|
||||
System.out.println(String.format("The number of messages on the queue: %s", attributesResponse.attributes()
|
||||
.get("ApproximateNumberOfMessages")));
|
||||
|
|
Loading…
Reference in New Issue