jclouds-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mirabito, Massimo (Max) (CDC/OID/NCHHSTP) (CTR)" <m...@cdc.gov>
Subject RE: Help on how to use JCloud API with SQS
Date Tue, 10 Nov 2015 12:05:26 GMT
Hi Ignasi,

Thank you this is helpful and I am able to send a simple message but something is still not
clicking even after reading the API docs.

For example in AWS I can include message attributes when I send a message like this

   AWSCredentials credentials = Aws.getAwsCredentials(accessKey, secretKey);
        AmazonSQSClient sqs = new AmazonSQSClient(credentials);                          
      
        sqs.setRegion(Region.getRegion(Regions.US_EAST_1));
        SendMessageRequest smr = new SendMessageRequest();
        smr.withQueueUrl(url);
        smr.setMessageBody(messageBody);
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " :: " + entry.getValue());
            MessageAttributeValue mav = new MessageAttributeValue();
            mav.setStringValue(entry.getValue());
            mav.setDataType("String");
            smr.addMessageAttributesEntry(entry.getKey(), mav);
        }
        SendMessageResult x =  sqs.sendMessage(smr);
        System.out.println("SQS message published..." + x.getMessageId());
    }

I cannot understand which API or object  I would use in Jcloud to do the same I thought using
the SendMessageOptions would work but it's not

Thanks again 
max


-----Original Message-----
From: Ignasi Barrera [mailto:nacx@apache.org] 
Sent: Monday, November 09, 2015 15:49
To: user@jclouds.apache.org
Subject: Re: Help on how to use JCloud API with SQS

Hi Max,

I haven't used that API, but in jclouds all APIs and providers are instantiated the same way.
You need to use the ContextBuilder [1] to configure the provider, the credentials, and configuration
properties that may be required for some particular providers. In general, it looks like:

TheApi api = ContextBuilder.newBuilder("api or provider id")
   .credentials("identity", "credential")
   .overrides(optional extra configuration properties)
   .buildApi(TheApi.class);  // or buildView(Abstraction.class)

In the your case, you want to build the SQS api, and since that API is not yet supported in
a "portable abstraction" such as the ComputeService or the BlobStore, you can create it with
the "buildApi"
method. Something like:

SQSApi sqs = ContextBuilder.newBuilder("aws-sqs")
   .credentials("access key", "secret key")
   .buildApi(SQSApi.class);

You can read a quick intro to the basic jclouds concepts here [2].

HTH!

I.


[1] http://jclouds.apache.org/reference/javadoc/1.9.x/org/jclouds/ContextBuilder.html
[2] http://jclouds.apache.org/start/concepts/

On 9 November 2015 at 20:53, Mirabito, Massimo (Max) (CDC/OID/NCHHSTP)
(CTR) <mcm8@cdc.gov> wrote:
> All,
>
>
>
> I just  started using JCloud  for the past several days. I am having 
> difficulty  in finding a working example that connects JCloud to AWS-SQS.
> Could anyone point me in the right direction or share snippet  of code?.
>
>
>
> Thanks in advance for any help
>
>
>
> max
Mime
View raw message