Skip to main content

Ruby

1 - install gem and then install aws sdk for ruby

If your project uses Bundler, add the following line to your Gemfile to add the AWS SDK for Ruby to your project.

	
gem 'aws-sdk'

If you don’t use Bundler, the easiest way to install the SDK is to use RubyGems. To install the latest version of the SDK, use the following command.


gem install aws-sdk

If the previous command fails on your Unix-based system, use sudo to install the SDK, as shown in the following command.


sudo gem install aws-sdk

2 - Make a connection with the EQS client.

To make the connection with the EQS client , you need to pass configurations and credentials.

Configurations-


region_name- your_region
endpoint_url - eqs_endpoint_url (provided by e2e networks eqs service)

Credentials-


aws_access_key_id - your_access_key_id
aws_secret_key_id - your_secret_key_id

Make connection with EQS

You can establish the connection with the EQS client in several ways.

a) You can directly pass the credentials and configurations at the time of making a session with the EQS client. warning - Hardcoded credentials in application is not recommended

edit your .rb file


require 'aws-sdk-sqs'

eqs_client = Aws::SQS::Client.new(
endpoint: “eqs_endpoint_url_provided_by_e2e”,
region:”your_region”,
credentials: Aws::Credentials.new(aws_access_key_id,aws_secret_access_key)
)

b) you can put credentials and configurations in the config and credentials file , and these files should be located at ~/.aws/config, ~/.aws/credentials location.

put into ~/.aws/config file


[default]
region =REGION

put into ~/.aws/credentials file


[default]
aws_access_key_id = ACCESS_KEY_ID
aws_secret_access_key = SECRET_KEY

edit your .rb file


require 'aws-sdk-sqs'

eqs_client = Aws::SQS::Client.new(
endpoint: “eqs_endpoint_url_provided_by_e2e”
)

c) you can make the connection with the EQS client by passing the credentials and configuration into the environment variables file.

To install the python dotenv package, you can use the command


gem install dotenv

using terminal (Linux, OS X or Unix)


$ export AWS_ACCESS_KEY_ID = your_access_key_id
$ export AWS_SECRET_ACCESS_KEY = your_secret_key
$ export AWS_DEFAULT_REGION = your_eqs_region

using terminal (Windows)


> set AWS_ACCESS_KEY_ID = your_access_key_id
> set AWS_SECRET_ACCESS_KEY = your_secret_key
> set AWS_DEFAULT_REGION = your_eqs_region

or, edit your enviourment valiable file


AWS_ACCESS_KEY_ID = your_access_key_id
AWS_SECRET_ACCESS_KEY = your_secret_access_key
AWS_DEFAULT_REGION = your_eqs_region

edit your .rb file


require 'aws-sdk-sqs'
require 'dotenv/load'

eqs_client = Aws::SQS::Client.new({
region: ENV['AWS_REGION'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
endpoint: ENV['AWS_SQS_ENDPOINT']
})

Methods available in eqs_client

Change VisibilityTimeout

Request Syntax


queue_url = "your_queue_url_here"
receipt_handle = "your_receipt_handle_here"
visibility_timeout = 123

resp = eqs_client.change_message_visibility({
queue_url: queue_url,
receipt_handle: receipt_handle,
visibility_timeout: visibility_timeout
})

Parameters

QueueUrl (string)- [Required]
The URL of the E2E EQS queue whose message's visibility is changed.

ReceiptHandle (string) - [Required]
The receipt handle is associated with the message whose visibility timeout is changed. This parameter is returned by the ReceiveMessage action

VisibilityTimeout (integer) - [Required] The new value for the message's visibility timeout (in seconds)

Response Syntax


nil

Change VisibilityTimeout in batch

Request Syntax


response = eqs_client.change_message_visibility_batch({
queue_url: "string",
entries: [
{
id: "string",
receipt_handle: "string",
visibility_timeout: 123,
},
],
})

Parameters

QueueUrl (string) - [Required]
The URL of the E2E EQS queue whose message's visibility is changed.

Entries (Array) - [Required] (Hash)

id [Required]-(string) An identifier for this particular receipt handle used to communicate the result

ReceiptHandle [Required] -(string) A receipt handle

VisibilityTimeout - (string) The new value (in seconds) for the message’s visibility timeout

Response Syntax


{
successful: [
{
id: "string",
},
],
failed: [
{
id: "string",
sender_fault: true | false,
code: "string",
message: "string",
},
],
}

Create queue

Request Syntax


queue_name = "my-queue"
attributes = {
"DelaySeconds" => "0",
"MaximumMessageSize" => "262144",
"MessageRetentionPeriod" => "345600",
"ReceiveMessageWaitTimeSeconds" => "0",
"VisibilityTimeout" => "30"
}
tags = {
"tag-key" => "tag-value"
}

resp = eqs_client.create_queue({
queue_name: queue_name,
attributes: attributes,
tags: tags
})

Parameters

QueueName (string)- [Required] 1 - A queue name can have up to 80 characters

2 - Valid values: alphanumeric characters, hyphens ( -), and underscores ( _).

Attributes (Hash)- Attributes could be

1 - DelaySeconds - Time(second), to which extent delivery of messages is delayed in the queue

Valid values - 0 to 900 (second)

default - 0 (second)

2 - MaximumMessageSize - The size of the message after which the queue will reject the message

Valid values - 1,024 bytes (1 KiB) to 262,144 bytes (256 KiB)

default - 262,144 bytes(256 KiB)

3 - MessageRetentionPeriod - Time to which extent a queue will retain a message

Valid values - 60 seconds (1 minute) to 1,209,600 seconds (14 days)

default - 345,600 (4 days)

4 - ReceiveMessageWaitTimeSeconds - Time to which extent ReceiveMessage action waits before receiving a message

Valid values - 0 to 20 (seconds)

default - 0 (second)

5 - VisibilityTimeout - The amount of time that a message in a queue is invisible to other consumers after a consumer retrieves it.

Valid values - 0 to 43,200 seconds (12 hours)

default - 30 second

tags (Hash) -

1 - Adding more than 50 tags to a queue isn't recommended.

2 - A new tag with a key identical to that of an existing tag overwrites the existing tag.

Response Syntax


{
queue_url: "string"
}

Delete message

Request Syntax


eqs_client.delete_message(
queue_url: "string",
receipt_handle: "string"
)

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue from which messages are deleted.

ReceiptHandle (string) - [Required] The receipt handle is associated with the message to delete.

Response Syntax


nil

Delete message in batch

Request Syntax


response = sqs_client.delete_message_batch({
queue_url: "string", # required
entries: [
{
id: "string", # required
receipt_handle: "string", # required
},
],
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue from which messages are deleted.

Entries (Array) - [Required] (Hash) id [Required]-(string) An identifier for this particular receipt handle used to communicate the result ReceiptHandle [Required] -(string) A receipt handle

Response Syntax


{
successful: [
{
id: "string",
},
],
failed: [
{
id: "string",
sender_fault: false,
code: "string",
message: "string",
},
],
}

Delete queue

Request Syntax


resp = eqs_client.delete_queue({
queue_url: "String", # required
})

Parameters

QueueUrl (string) - [Required]

The URL of the E2E EQS queue to delete.

Response Syntax


nil

Get queue Attributes

Request Syntax


queue_url = "your_queue_url"
attribute_names = ["All"]
resposne = sqs.get_queue_attributes({
queue_url: queue_url,
attribute_names: attribute_names
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue from which attributes are get.

AttributeNames (Array<String>) - [Optional] A list of attributes for which to retrieve information

All - it specifies, returns all values

you can also specify specific attributes in the list

As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']

Response Syntax


{
attributes: {
attribute_name1: "attribute_value1",
attribute_name2: "attribute_value2",
}
}

Get queue url

Request Syntax


queue_name = "queue-name"
resp = sqs.get_queue_url(queue_name: queue_name)

Parameters

QueueName (string) -[Required] The name of the queue whose URL must be fetched.

Response Syntax


{
queue_url: "string"
}

List queue tags

Request Syntax


queue_url = "queue_url"

resp = sqs.list_queue_tags({
queue_url: queue_url
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue of which all the tags must be listed.

Response Syntax


{
"Tags" => {
"Key1" => "Value1",
"Key2" => "Value2",
}
}

List queues

Request Syntax

	
queue_name_prefix = 'my-queue'
max_results = 10

resp = sqs.list_queues({
queue_name_prefix: queue_name_prefix,
max_results: max_results
})

Parameters QueueNamePrefix (string) - [Optional] A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned.

MaxResults (integer) - [Optional] The maximum number of results to include in the response. Valid values - 1 to 1000

Response Syntax


{
queue_urls: ["string"]
}


Purge queue

delete all the messages from queue.

Request Syntax


queue_url = "queue_url"

resp = sqs.purge_queue({
queue_url: queue_url
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue of which all the messages must be deleted.

Response Syntax


nil

Receive message

Request Syntax


resp = sqs_client.receive_message({
queue_url: "string",
attribute_names: ["All"],
message_attribute_names: ["string"],
max_number_of_messages: 2,
visibility_timeout: 25,
wait_time_seconds: 10,
receive_request_attempt_id: "string",
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue from which messages are received.

AttributeNames (Array) - A list of attributes that need to be returned along with each message.

All - it specifies, returns all values

you can also specify specific attributes in the list

As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']

MessageAttributeNames (Array) - The name of the message attribute.

MaxNumberOfMessages (integer) - The maximum number of messages to return.

Valid range - 1 to 10

default - 1

VisibilityTimeout (integer) - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.

WaitTimeSeconds (integer) - The duration (in seconds) for which the call waits for a message to arrive in the queue before returning.

Response Syntax


{
messages: [
{
message_id: "string",
receipt_handle: "string",
md5_of_body: "string",
body: "string",
attributes: {"string" => "string"},
md5_of_message_attributes: "string",
message_attributes: {
"string" => {
string_value: "string",
binary_value: "bytes",
data_type: "string",
}
}
},
]
}


Send message

Request Syntax


resp = sqs.send_message({
queue_url: "QUEUE_URL",
message_body: "MESSAGE_BODY",
delay_seconds: 123,
message_attributes: {
"ATTRIBUTE_NAME" => {
string_value: "ATTRIBUTE_VALUE",
data_type: "STRING" # EQS supports Binary, Number, String data types
}
},
message_system_attributes: {
"ATTRIBUTE_NAME" => {
string_value: "ATTRIBUTE_VALUE",
data_type: "STRING" # EQS supports Binary, Number, String data types
}
}
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue to which messages are send.

MessageBody (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB.

DelaySeconds (integer) - The length of time, in seconds, for which to delay a specific message.

MessageAttributes (Hash) - Each message attribute consists of a Name, Type, and Value .

Name, type, value and the message body must not be empty or null .

(string) - name of the message attributes

(Hash) - Value of message attributes

1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding.

2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.

(string) - [Required] Type of message attributes

EQS support the following data type

Binary, Number, String

MessageSystemAttributes (Hash) - Each message system attribute consists of a Name, Type, and Value.

The name, type, value and message body must not be empty or null.

(string) - the name of the message attributes

(Hash) - Value of message attributes

1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding.

2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.

(string) - Type of message attributes

EQS support the following data type

Binary , Number , String

Response Syntax

	
{
md5_of_message_body: "string",
md5_of_message_attributes: "string",
md5_of_message_system_attributes: "string",
message_id: "string",
sequence_number: "string"
}

Send message in batch

Request Syntax


resp = sqs_client.send_message_batch({
queue_url: "QUEUE_URL",
entries: [
{
id: "MESSAGE_ID_1",
message_body: "MESSAGE_BODY_1",
delay_seconds: 123,
message_attributes: {
"ATTRIBUTE_NAME_1" => {
string_value: "ATTRIBUTE_VALUE_1",
data_type: "String", # "Binary" or "Number"
},
},
message_system_attributes: {
"SYS_ATTRIBUTE_NAME_1" => {
string_value: "SYS_ATTRIBUTE_VALUE_1",
data_type: "String", # "Binary" or "Number"
},
}
},
{
id: "MESSAGE_ID_2",
message_body: "MESSAGE_BODY_2",
delay_seconds: 456,
message_attributes: {
"ATTRIBUTE_NAME_3" => {
string_value: "ATTRIBUTE_VALUE_3",
data_type: "String", # "Binary" or "Number"
},
},
message_system_attributes: {
"SYS_ATTRIBUTE_NAME_3" => {
string_value: "SYS_ATTRIBUTE_VALUE_3",
data_type: "String", # "Binary" or "Number"
},
}
},
]
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue to which messages are sent.

Entries (Array) - [Required] A list of SendMessageBatchRequestEntry items.

(Hash) -

Contains the details of a single E2E EQS message along with an Id.

Id (string) - [REQUIRED] An identifier for a message in this batch is used to communicate the result.

MessageBody (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB.

DelaySeconds (integer) - The length of time, in seconds, for which to delay a specific message.

MessageAttributes (Hash) - Each message attribute consists of a Name, Type, and Value.

The Name, type, value and message body must not be empty or null.

(string) - The name of the message attributes

(Hash) - Value of message attributes

1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding.

2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.

(string) -[Required] Type of message attributes

EQS support the following data type

Binary, Number, String

MessageSystemAttributes (Hash) - Each message system attribute consists of a Name, Type, and Value.

Name, type, value and the message body must not be empty or null.

(string) - The name of the message attributes

(Hash) - Value of message attributes

1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding.

2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.

(string) - Type of message attributes

EQS support following data type

Binary , Number , String

Response Syntax


{
successful: [
{
id: "string",
message_id: "string",
md5_of_message_body: "string",
md5_of_message_attributes: "string",
md5_of_message_system_attributes: "string",
sequence_number: "string"
}
],
failed: [
{
id: "string",
sender_fault: true | false,
code: "string",
message: "string"
}
]
}

Set queue Attributes

Request Syntax


resp = sqs_client.set_queue_attributes({
queue_url: "string", # required
attributes: {
"string" => "string",
},
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue of which attributes should be set.

Attributes (Hash) : [Required] A map of attributes to set.

Response Syntax


nil


Tag queue
---------

**Request Syntax**

```ruby

sqs_client.tag_queue({
queue_url: "QUEUE_URL",
tags: {
"TAG_NAME" => "TAG_VALUE",
},
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue.

Tags (Hash) - [Required] The list of tags to be added to the specified queue.

Response Syntax


nil

Untag queue

Request Syntax


queue_url = "QUEUE_URL"
tag_keys = ["TAG_KEY1", "TAG_KEY2"]
sqs.untag_queue({
queue_url: queue_url,
tag_keys: tag_keys,
})

Parameters

QueueUrl (string) - [Required] The URL of the E2E EQS queue.

TagKeys (Array) - [Required] The list of tags to be removed from the specified queue.

Response Syntax


nil