Package com.amazonaws.services.sqs

Examples of com.amazonaws.services.sqs.AmazonSQSClient


    }

    @Override
    public void init() {
        if (sqsClient == null) { // not injected
            sqsClient = new AmazonSQSClient(credentialsProvider, clientConfig);
        }
        String endpoint = "sqs." + this.region + ".amazonaws.com";
        sqsClient.setEndpoint(endpoint);

        for (String queueName : queues) {
View Full Code Here


    public static class AmazonSQSClientProvider implements Provider<AmazonSQSClient> {

        @Override
        public AmazonSQSClient get() {
            AmazonSQSClient client = mock(AmazonSQSClient.class);
            doReturn(new SendMessageResult()).when(client).sendMessage(any(SendMessageRequest.class));

            ReceiveMessageResult result = new ReceiveMessageResult();
            result.setMessages(Arrays.asList(new Message[]{new Message().withBody("receivedMessage")}));
            doReturn(result).when(client).receiveMessage(any(ReceiveMessageRequest.class));
View Full Code Here

            return captor;
        }

        public SqsTest invoke() throws IOException {
            ObjectMapper mapper = injector.getInstance(DefaultObjectMapper.class);
            AmazonSQSClient client = injector.getInstance(AmazonSQSClient.class);

            queueNotice = mapper.readValue(desc, new TypeReference<Notice>() {});
            queueNotice.init();
            queueNotice.send("message");
            captor = ArgumentCaptor.forClass(SendMessageRequest.class);
View Full Code Here

     * Provide the possibility to override this method for an mock implementation
     * @return AmazonSQSClient
     */
    AmazonSQS createClient() {
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        AmazonSQS client = new AmazonSQSClient(credentials);
        if (configuration.getAmazonSQSEndpoint() != null) {
            client.setEndpoint(configuration.getAmazonSQSEndpoint());
        }
        return client;
    }
View Full Code Here

                downloadFrame.setVisible(true);

                Endpoints notificationEP = new Endpoints(
                    locationChoice);

                AmazonSQSClient dlSQS = new AmazonSQSClient(
                    dlCredentials);
                AmazonSNSClient dlSNS = new AmazonSNSClient(
                    dlCredentials);

                dlSQS.setEndpoint(notificationEP.sqsEndpoint());
                dlSNS.setEndpoint(notificationEP.snsEndpoint());

                // ArchiveTransferManager atm = new
                // ArchiveTransferManager(dlClient,
                // dlCredentials);
View Full Code Here

        }

        awsCredentials = new BasicAWSCredentials(cnsInternal.getAccessKey(), cnsInternal.getAccessSecret());
    }
   
        sqs = new AmazonSQSClient(awsCredentials);
        sqs.setEndpoint(CMBProperties.getInstance().getCQSServiceUrl());
       
        useInlineApiCalls = CMBProperties.getInstance().useInlineApiCalls() && CMBProperties.getInstance().getCQSServiceEnabled();

        initialized = true;
View Full Code Here

      deleteAllTopics(cns2);
      deleteAllTopics(cns3);
    }

    if (cqsServiceUrl != null) {
        cqs1 = new AmazonSQSClient(credentials1);
      cqs1.setEndpoint(cqsServiceUrl);
      cqs2 = new AmazonSQSClient(credentials2);
      cqs2.setEndpoint(cqsServiceUrl);
      cqs3 = new AmazonSQSClient(credentials3);
      cqs3.setEndpoint(cqsServiceUrl);
      deleteAllQueues(cqs1);
      deleteAllQueues(cqs2);
      deleteAllQueues(cqs3);
    }
View Full Code Here

            String cqsServerUrl = "http://localhost:6059";
            String cnsServerUrl = "http://localhost:6061";

            // initialize service

            AmazonSQSClient sqs = new AmazonSQSClient(user1Credentials);
            sqs.setEndpoint(cqsServerUrl);

            AmazonSNSClient sns = new AmazonSNSClient(user2Credentials);
            sns.setEndpoint(cnsServerUrl);
       
            // create queue
           
        Random randomGenerator = new Random();
       
        String queueName = QUEUE_PREFIX + randomGenerator.nextLong();
         
          HashMap<String, String> attributeParams = new HashMap<String, String>();
          CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
          createQueueRequest.setAttributes(attributeParams);
          String queueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
         
          AddPermissionRequest addPermissionRequest = new AddPermissionRequest();
          addPermissionRequest.setQueueUrl(queueUrl);
          addPermissionRequest.setActions(Arrays.asList("SendMessage"));
          addPermissionRequest.setLabel(UUID.randomUUID().toString());
          addPermissionRequest.setAWSAccountIds(Arrays.asList(user2Id));       
          sqs.addPermission(addPermissionRequest);
         
          // create topic
         
          String topicName = "TSTT" + randomGenerator.nextLong();
           
      CreateTopicRequest createTopicRequest = new CreateTopicRequest(topicName);
      CreateTopicResult createTopicResult = sns.createTopic(createTopicRequest);
      String topicArn = createTopicResult.getTopicArn();
     
      // subscribe and confirm cqs endpoint
     
      SubscribeRequest subscribeRequest = new SubscribeRequest();
      String queueArn = getArnForQueueUrl(queueUrl);
      subscribeRequest.setEndpoint(queueArn);
      subscribeRequest.setProtocol("cqs");
      subscribeRequest.setTopicArn(topicArn);
      SubscribeResult subscribeResult = sns.subscribe(subscribeRequest);
      String subscriptionArn = subscribeResult.getSubscriptionArn();
     
      if (subscriptionArn.equals("pending confirmation")) {
       
        Thread.sleep(500);
       
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
        receiveMessageRequest.setQueueUrl(queueUrl);
        receiveMessageRequest.setMaxNumberOfMessages(1);
        ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
       
        List<Message> messages = receiveMessageResult.getMessages();
       
        if (messages != null && messages.size() == 1) {
         
            JSONObject o = new JSONObject(messages.get(0).getBody());
           
            if (!o.has("SubscribeURL")) {
              throw new Exception("message is not a confirmation messsage");
            }
           
            String subscriptionUrl = o.getString("SubscribeURL");
            httpGet(subscriptionUrl);
           
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();
            deleteMessageRequest.setReceiptHandle(messages.get(0).getReceiptHandle());
            deleteMessageRequest.setQueueUrl(queueUrl);
            sqs.deleteMessage(deleteMessageRequest);
       
        } else {
          throw new Exception("no confirmation message found");
        }
      }
     
      // publish and receive message
     
      PublishRequest publishRequest = new PublishRequest();
      String messageText = "quamvis sint sub aqua, sub aqua maledicere temptant";
      publishRequest.setMessage(messageText);
      publishRequest.setSubject("unit test message");
      publishRequest.setTopicArn(topicArn);
      sns.publish(publishRequest);
     
      Thread.sleep(500);

      ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
      receiveMessageRequest.setQueueUrl(queueUrl);
      receiveMessageRequest.setMaxNumberOfMessages(1);
      ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
     
      List<Message> messages = receiveMessageResult.getMessages();
     
      if (messages != null && messages.size() == 1) {
       
        String messageBody = messages.get(0).getBody();
       
        if (!messageBody.contains(messageText)) {
          throw new Exception("message text not found");
        }
       
          DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();
          deleteMessageRequest.setReceiptHandle(messages.get(0).getReceiptHandle());
          deleteMessageRequest.setQueueUrl(queueUrl);
          sqs.deleteMessage(deleteMessageRequest);

      } else {
        throw new Exception("no messages found");
      }
     
      // subscribe and confirm http endpoint

      String id = randomGenerator.nextLong() + "";
      String endPointUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + id;
      String lastMessageUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "info/" + id + "?showLast=true";
     
      subscribeRequest = new SubscribeRequest();
      subscribeRequest.setEndpoint(endPointUrl);
      subscribeRequest.setProtocol("http");
      subscribeRequest.setTopicArn(topicArn);
      subscribeResult = sns.subscribe(subscribeRequest);
      subscriptionArn = subscribeResult.getSubscriptionArn();
     
      if (subscriptionArn.equals("pending confirmation")) {
       
        Thread.sleep(500);
       
        String response = httpGet(lastMessageUrl);
         
          JSONObject o = new JSONObject(response);
         
          if (!o.has("SubscribeURL")) {
            throw new Exception("message is not a confirmation messsage");
          }
         
          String subscriptionUrl = o.getString("SubscribeURL");
         
          response = httpGet(subscriptionUrl);
      }     
     
      // publish and receive message
     
      publishRequest = new PublishRequest();
      publishRequest.setMessage(messageText);
      publishRequest.setSubject("unit test message");
      publishRequest.setTopicArn(topicArn);
      sns.publish(publishRequest);
     
      Thread.sleep(500);
     
      String response = httpGet(lastMessageUrl);
     
      if (response != null && response.length() > 0) {
       
        if (!response.contains(messageText)) {
          throw new Exception("message text not found");
        }
       
      } else {
        throw new Exception("no messages found");
      }
     
      // delete queue and topic
     
      DeleteTopicRequest  deleteTopicRequest = new DeleteTopicRequest(topicArn);
      sns.deleteTopic(deleteTopicRequest);
     
          sqs.deleteQueue(new DeleteQueueRequest(queueUrl));
         
          System.out.println("OK");
     
      } catch (Exception ex) {
        ex.printStackTrace();
View Full Code Here

    if (awsCredentials == null) {
          awsCredentials = new BasicAWSCredentials(cnsInternalUser.getAccessKey(), cnsInternalUser.getAccessSecret());
    }
   
    if (sqs == null) {
            sqs = new AmazonSQSClient(awsCredentials);
            sqs.setEndpoint(CMBProperties.getInstance().getCQSServiceUrl());
    }
   
      String userId = user.getUserId();
      String message = request.getParameter("Message");
View Full Code Here

          throw new ServletException("Only admin may impersonate other users");
        }
   
        awsCredentials = new BasicAWSCredentials(user.getAccessKey(), user.getAccessSecret());
       
        sqs = new AmazonSQSClient(awsCredentials);
        sqs.setEndpoint(CMBProperties.getInstance().getCQSServiceUrl());
       
        sns = new AmazonSNSClient(awsCredentials);
        sns.setEndpoint(CMBProperties.getInstance().getCNSServiceUrl());
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.sqs.AmazonSQSClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.