Skip to content

Commit

Permalink
Corrected Module.md and version bumped.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maninda committed Oct 1, 2019
1 parent c0df71a commit 88178ab
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Ballerina.lock
@@ -1,14 +1,14 @@
org_name = "wso2"
version = "0.9.1"
version = "0.9.2"
lockfile_version = "1.0.0"
ballerina_version = "1.0.1"

[[imports."wso2/amazonsqs:0.9.1"]]
[[imports."wso2/amazonsqs:0.9.2"]]
org_name = "ballerinax"
name = "java"
version = "0.0.0"

[[imports."wso2/amazonsqs:0.9.1"]]
[[imports."wso2/amazonsqs:0.9.2"]]
org_name = "ballerinax"
name = "java.arrays"
version = "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion Ballerina.toml
Expand Up @@ -2,6 +2,6 @@
org-name= "wso2"
license= ["Apache-2.0"]
authors = ["WSO2"]
version= "0.9.1"
version= "0.9.2"
keywords = ["amazonsqs", "Amazon", "SQS", "Ballerina", "connector", "client"]
repository = "https://github.com/wso2-ballerina/module-amazonsqs"
55 changes: 36 additions & 19 deletions src/amazonsqs/Module.md
Expand Up @@ -16,18 +16,7 @@ Amazon SQS Connector allows you to connect to the Amazon SQS service via REST AP
First, import the `wso2/amazonsqs` module and related other modules into the Ballerina project and create a `main` method.

```ballerina
import ballerina/config;
import ballerina/log;
import wso2/amazonsqs;
public function main(string... args) {
}
```
Rest of the code can be written inside the `main` method. The source code can be saved in a file for example, `demo.bal`. The file can be executed with the following command where `ballerina.conf` is the configuration that is described below.

```
ballerina run demo.bal --b7a.config.file=path/to/ballerina.conf
```

The Amazon SQS connector can be instantiated using the Access Key ID, Secret Access Key, Region of the Amazon SQS geographic location
Expand Down Expand Up @@ -56,19 +45,41 @@ Follow the method explained below to obtain AWS credentials.

For more information please visit https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-setting-up.html .

You can now enter the credentials in the SQS client config and create SQS client by passing the config:
**Create Amazon SQS client**

You can now enter the credentials in the SQS client configuration and create SQS client by passing the configuration:

```ballerina
amazonsqs:Configuration configuration = {
accessKey: config:getAsString("ACCESS_KEY_ID"),
secretKey: config:getAsString("SECRET_ACCESS_KEY"),
region: config:getAsString("REGION"),
accountNumber: config:getAsString("ACCOUNT_NUMBER")
accessKey: "<ACCESS_KEY_ID>",
secretKey: "<SECRET_ACCESS_KEY>",
region: "<REGION>",
accountNumber: "<ACCOUNT_NUMBER>"
};
amazonsqs:Client sqsClient = new(configuration);
```
You can create a queue in SQS as follows with `createQueue` method. Successful creation returns the created queue URL as a string and the error cases returns an `error` object.

If you want to add your own key store to define the `secureSocketConfig`, change the SQS configuration as
mentioned below.

```ballerina
amazonsqs:Configuration configuration = {
accessKey: "<ACCESS_KEY_ID>",
secretKey: "<SECRET_ACCESS_KEY>",
region: "<REGION>",
accountNumber: "<ACCOUNT_NUMBER>",
secureSocketConfig: {
trustStore: {
path: config:getAsString("<TRUSTSTORE_PATH>"),
password: config:getAsString("<TRUSTSTORE_PASSWORD>")
}
}
};
```
**Creating a SQS Queue**

You can create a queue in SQS as follows with `createQueue` method for a preferred queue name and the required set of attributes. Successful creation returns the created queue URL as a string and the error cases returns an `error` object.

```ballerina
map<string> attributes = {};
Expand All @@ -81,7 +92,9 @@ if (response is string) {
}
```

You can send a message to SQS as follows with `sendMessage` method. Successful send operation returns an `OutboundMessage` object and the error cases returns an `error` object.
**Sending a Message to a SQS Queue**

You can send a message to SQS as follows with `sendMessage` method. Use message to be sent, appropriate attribute parameters for the queue and the path to the queue from Amazon host address as parameters to the operation. Successful send operation returns an `OutboundMessage` object and the error cases returns an `error` object.

```ballerina
map<string> attributes = {};
Expand All @@ -101,7 +114,9 @@ if (response is amazonsqs:OutboundMessage) {
}
```

A sent message can be received with `receiveMessage` method. Successful receive operation returns an array of `InboundMessage` objects and the error cases returns an `error` object.
**Receiving a Message from the SQS Queue**

A sent message can be received with `receiveMessage` method. Path to the queue from Amazon host address and appropriate attribute parameters should be used as the parameters to the operation. Successful receive operation returns an array of `InboundMessage` objects each containing the message and the `receiptHandler` while the error cases returns an `error` object.

```ballerina
map<string> attributes = {};
Expand All @@ -117,6 +132,8 @@ if (response is amazonsqs:InboundMessage[]) {
}
```

**Deleting a Message from the SQS Queue**

A received message should be deleted with `deleteMessage` method within `VisibilityTimeout` number of seconds providing the received `receiptHandler` string. Successful delete operation returns a boolean value `true` and the error cases returns a `false` value or an `error` object.

```ballerina
Expand Down
9 changes: 9 additions & 0 deletions src/amazonsqs/tests/main_test.bal
Expand Up @@ -24,6 +24,15 @@ Configuration configuration = {
secretKey: config:getAsString("SECRET_ACCESS_KEY"),
region: config:getAsString("REGION"),
accountNumber: config:getAsString("ACCOUNT_NUMBER")

// For secure connections with SQS add "secureSocketConfig" as a field.
//
// secureSocketConfig: {
// trustStore: {
// path: config:getAsString("TRUSTSTORE_PATH"),
// password: config:getAsString("TRUSTSTORE_PASSWORD")
// }
// }
};

Client sqs = new(configuration);
Expand Down

0 comments on commit 88178ab

Please sign in to comment.