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