{"action":"created","issue":{"url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/26","repository_url":"https://api.github.com/repos/RammusXu/rammusxu.github.io","labels_url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/26/comments","events_url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/26/events","html_url":"https://github.com/RammusXu/rammusxu.github.io/issues/26","id":170824884,"number":26,"title":"在intellij IDE上開發aws-java-sdk ","user":{"login":"RammusXu","id":4367069,"avatar_url":"https://avatars.githubusercontent.com/u/4367069?v=3","gravatar_id":"","url":"https://api.github.com/users/RammusXu","html_url":"https://github.com/RammusXu","followers_url":"https://api.github.com/users/RammusXu/followers","following_url":"https://api.github.com/users/RammusXu/following{/other_user}","gists_url":"https://api.github.com/users/RammusXu/gists{/gist_id}","starred_url":"https://api.github.com/users/RammusXu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RammusXu/subscriptions","organizations_url":"https://api.github.com/users/RammusXu/orgs","repos_url":"https://api.github.com/users/RammusXu/repos","events_url":"https://api.github.com/users/RammusXu/events{/privacy}","received_events_url":"https://api.github.com/users/RammusXu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-12T08:42:47Z","updated_at":"2016-08-15T08:33:20Z","closed_at":null,"body":"## 開新專案\r\n- Getting Started with Gradle https://www.jetbrains.com/help/idea/2016.2/getting-started-with-gradle.html\r\n- How to create a gradle-based Java Project in Intellij IDEA 13.0.1 Community http://stackoverflow.com/questions/20648942/how-to-create-a-gradle-based-java-project-in-intellij-idea-13-0-1-community\r\n\r\n## 加入AWS SDK\r\nhttps://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-project-gradle.html\r\n\r\nTo configure the SDK for Gradle\r\n\r\n- Add the dependency management plugin to your build.gradle file:\r\n```gradle\r\nbuildscript {\r\n    repositories {\r\n        mavenCentral()\r\n    }\r\n    dependencies {\r\n        classpath \"io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE\"\r\n    }\r\n}\r\napply plugin: \"io.spring.dependency-management\"\r\n```\r\n\r\n- Add the BOM to the dependencyManagement section of the file:\r\n```\r\ndependencyManagement {\r\n    imports {\r\n        mavenBom 'com.amazonaws:aws-java-sdk-bom:1.10.47'\r\n    }\r\n}\r\n```\r\n\r\n- Specify the SDK modules that you’ll be using in the dependencies section:\r\n```gradle\r\ndependencies {\r\n    compile 'com.amazonaws:aws-java-sdk-s3'\r\n    testCompile group: 'junit', name: 'junit', version: '4.11'\r\n}\r\n```\r\nGradle will automatically resolve the correct version of your SDK dependencies using the information from the BOM.\r\n\r\n\r\n\r\n## Reference"},"comment":{"url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/comments/239753329","html_url":"https://github.com/RammusXu/rammusxu.github.io/issues/26#issuecomment-239753329","issue_url":"https://api.github.com/repos/RammusXu/rammusxu.github.io/issues/26","id":239753329,"user":{"login":"RammusXu","id":4367069,"avatar_url":"https://avatars.githubusercontent.com/u/4367069?v=3","gravatar_id":"","url":"https://api.github.com/users/RammusXu","html_url":"https://github.com/RammusXu","followers_url":"https://api.github.com/users/RammusXu/followers","following_url":"https://api.github.com/users/RammusXu/following{/other_user}","gists_url":"https://api.github.com/users/RammusXu/gists{/gist_id}","starred_url":"https://api.github.com/users/RammusXu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RammusXu/subscriptions","organizations_url":"https://api.github.com/users/RammusXu/orgs","repos_url":"https://api.github.com/users/RammusXu/repos","events_url":"https://api.github.com/users/RammusXu/events{/privacy}","received_events_url":"https://api.github.com/users/RammusXu/received_events","type":"User","site_admin":false},"created_at":"2016-08-15T08:33:20Z","updated_at":"2016-08-15T08:33:20Z","body":"## SQS snippet\r\n```java\r\npackage com.haufu.aws;\r\n\r\nimport com.amazonaws.AmazonClientException;\r\nimport com.amazonaws.AmazonServiceException;\r\nimport com.amazonaws.auth.AWSCredentials;\r\nimport com.amazonaws.auth.profile.ProfileCredentialsProvider;\r\nimport com.amazonaws.regions.Region;\r\nimport com.amazonaws.regions.Regions;\r\nimport com.amazonaws.services.sqs.AmazonSQS;\r\nimport com.amazonaws.services.sqs.AmazonSQSClient;\r\nimport com.amazonaws.services.sqs.model.*;\r\n\r\nimport java.util.*;\r\n\r\n/**\r\n * Created by rammus on 2016/8/12.\r\n */\r\npublic class Main {\r\n\tprivate static AmazonSQS sqs;\r\n\tprivate static String myQueueUrl;\r\n\tprivate static boolean deleteMessageFlag = false;\r\n\tprivate static AWSCredentials credentials;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t/*\r\n\t\t * The ProfileCredentialsProvider will return your [default]\r\n         * credential profile by reading from the credentials file located at\r\n         * (~/.aws/credentials).\r\n         */\r\n\t\ttry {\r\n\t\t\tcredentials = new ProfileCredentialsProvider().getCredentials();\r\n\r\n\t\t\tsqs = new AmazonSQSClient(credentials);\r\n\t\t\tRegion myRegion = Region.getRegion(Regions.AP_NORTHEAST_1);\r\n\t\t\tsqs.setRegion(myRegion);\r\n\r\n\t\t\t// Create a queue\r\n\t\t\tSystem.out.println(\"Creating a new SQS queue called MyQueue.\\n\");\r\n\t\t\tCreateQueueRequest createQueueRequest = new CreateQueueRequest(\"MyQueue\");\r\n\t\t\tmyQueueUrl = sqs.getQueueUrl(\"RD_RAMMUS_DEV\").getQueueUrl();\r\n//\t\t\tmyQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();\r\n\t\t} catch (Exception e) {\r\n\t\t\tthrow new AmazonClientException(\r\n\t\t\t\t\t\"Cannot load the credentials from the credential profiles file. \" +\r\n\t\t\t\t\t\t\t\"Please make sure that your credentials file is at the correct \" +\r\n\t\t\t\t\t\t\t\"location (~/.aws/credentials), and is in valid format.\",\r\n\t\t\t\t\te);\r\n\t\t}\r\n\r\n\r\n\t\tTimer timer = new Timer();\r\n\t\tTimerTask receiveTask = new ReceiveTask();\r\n\r\n\t\ttimer.schedule(receiveTask, 1000, 2000);\r\n\t\tsendMessage();\r\n\r\n\t\tSystem.out.println(\"===========================================\");\r\n\t\tSystem.out.println(\"Getting Started with Amazon SQS\");\r\n\t\tSystem.out.println(\"===========================================\\n\");\r\n\r\n\r\n\t}\r\n\r\n\tpublic static void sendMessage() {\r\n\t\t// Send a message\r\n\t\tSystem.out.format(\"Sending a message to %s.\\n\", myQueueUrl);\r\n\t\tsqs.sendMessage(new SendMessageRequest(myQueueUrl, \"This is my message text.\"));\r\n\t}\r\n\r\n\tpublic static void listQueue() {\r\n\t\t// List queues\r\n\t\tSystem.out.println(\"Listing all queues in your account.\\n\");\r\n\t\tfor (String queueUrl : sqs.listQueues().getQueueUrls()) {\r\n\t\t\tSystem.out.println(\"  QueueUrl: \" + queueUrl);\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic static void deleteQueue() {\r\n\t\t// Delete a queue\r\n\t\tSystem.out.println(\"Deleting the test queue.\\n\");\r\n\t\tsqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));\r\n\t}\r\n\r\n\tpublic static class ReceiveTask extends TimerTask {\r\n\t\tpublic void run() {\r\n\t\t\tSystem.out.println(new Date());\r\n\t\t\ttry {\r\n\t\t\t\t// Receive messages\r\n\t\t\t\tSystem.out.println(\"Receiving messages from MyQueue.\\n\");\r\n\t\t\t\tReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);\r\n\t\t\t\treceiveMessageRequest.setMaxNumberOfMessages(5);\r\n//\t\t\t\treceiveMessageRequest.setWaitTimeSeconds(3);\r\n\r\n\t\t\t\tList<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();\r\n\t\t\t\tfor (Message message : messages) {\r\n\t\t\t\t\tSystem.out.println(\"  Message\");\r\n\t\t\t\t\tSystem.out.println(\"    MessageId:     \" + message.getMessageId());\r\n\t\t\t\t\tSystem.out.println(\"    ReceiptHandle: \" + message.getReceiptHandle());\r\n\t\t\t\t\tSystem.out.println(\"    MD5OfBody:     \" + message.getMD5OfBody());\r\n\t\t\t\t\tSystem.out.println(\"    Body:          \" + message.getBody());\r\n\t\t\t\t\tfor (Map.Entry<String, String> entry : message.getAttributes().entrySet()) {\r\n\t\t\t\t\t\tSystem.out.println(\"  Attribute\");\r\n\t\t\t\t\t\tSystem.out.println(\"    Name:  \" + entry.getKey());\r\n\t\t\t\t\t\tSystem.out.println(\"    Value: \" + entry.getValue());\r\n\t\t\t\t\t}\r\n\r\n\r\n\t\t\t\t\tif (deleteMessageFlag) {\r\n\t\t\t\t\t\t// Delete a message\r\n\t\t\t\t\t\tSystem.out.println(\"Deleting a message.\\n\");\r\n\t\t\t\t\t\tString messageReceiptHandle = messages.get(0).getReceiptHandle();\r\n\t\t\t\t\t\tsqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle));\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\r\n\r\n\t\t\t} catch (AmazonServiceException ase) {\r\n\t\t\t\tSystem.out.println(\"Caught an AmazonServiceException, which means your request made it \" +\r\n\t\t\t\t\t\t\"to Amazon SQS, but was rejected with an error response for some reason.\");\r\n\t\t\t\tSystem.out.println(\"Error Message:    \" + ase.getMessage());\r\n\t\t\t\tSystem.out.println(\"HTTP Status Code: \" + ase.getStatusCode());\r\n\t\t\t\tSystem.out.println(\"AWS Error Code:   \" + ase.getErrorCode());\r\n\t\t\t\tSystem.out.println(\"Error Type:       \" + ase.getErrorType());\r\n\t\t\t\tSystem.out.println(\"Request ID:       \" + ase.getRequestId());\r\n\t\t\t} catch (AmazonClientException ace) {\r\n\t\t\t\tSystem.out.println(\"Caught an AmazonClientException, which means the client encountered \" +\r\n\t\t\t\t\t\t\"a serious internal problem while trying to communicate with SQS, such as not \" +\r\n\t\t\t\t\t\t\"being able to access the network.\");\r\n\t\t\t\tSystem.out.println(\"Error Message: \" + ace.getMessage());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n}\r\n```"}}
{"actor":{"display_login":"RammusXu"}}