Last active
December 16, 2015 13:38
-
-
Save toritori0318/5442520 to your computer and use it in GitHub Desktop.
効率よくSQSを処理する単純なスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Amazon::SQS::Simple; | |
use Time::Piece; | |
my $access_key = ''; # Your AWS Access Key ID | |
my $secret_key = ''; # Your AWS Secret Key | |
my $queue_name = 'perl_test_queue'; | |
# Create an SQS object | |
my $sqs = Amazon::SQS::Simple->new( | |
$access_key, | |
$secret_key, | |
Endpoint => "https://ap-northeast-1.queue.amazonaws.com", | |
); | |
# Create a new queue | |
my $q = $sqs->CreateQueue($queue_name); | |
# Long Polling Setting | |
$q->SetAttribute('ReceiveMessageWaitTimeSeconds', 20); | |
my $i=0; | |
while(1) { | |
# fetch 10 messages | |
my @msgs = $q->ReceiveMessage( | |
MaxNumberOfMessages => 10, | |
); | |
for my $msg (@msgs) { | |
warn sprintf("%s recv%s: %s", Time::Piece->new(), $i, $msg->MessageBody()); | |
# delete message | |
$q->DeleteMessage($msg->ReceiptHandle()); | |
$i++; | |
} | |
warn sprintf("%s loop...", Time::Piece->new()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import boto.sqs | |
from boto.sqs.message import Message | |
from datetime import datetime | |
AWS_ACCESS_KEY='' | |
AWS_SECRET_KEY='' | |
queue_name = 'python_test_queue' | |
# connection | |
conn = boto.sqs.connect_to_region( | |
"ap-northeast-1", | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_KEY) | |
# Create or Get queue | |
queue = conn.create_queue(queue_name) | |
# Long Polling Setting | |
queue.set_attribute('ReceiveMessageWaitTimeSeconds', 20) | |
i=0 | |
while 1: | |
# fetch 10 messages | |
msgs = queue.get_messages(10) | |
for msg in msgs: | |
dt = datetime.today().strftime('%Y/%m/%d %H:%M:%S') | |
sys.stderr.write("%s recv%s: %s\n" % (dt, str(i), msg.get_body())) | |
i = i+1 | |
# delete message | |
queue.delete_message(msg) | |
sys.stderr.write("%s loop...\n" % (dt)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Amazon::SQS::Simple; | |
my $access_key = ''; # Your AWS Access Key ID | |
my $secret_key = ''; # Your AWS Secret Key | |
my $queue_name = 'perl_test_queue'; | |
# Create an SQS object | |
my $sqs = Amazon::SQS::Simple->new( | |
$access_key, | |
$secret_key, | |
Endpoint => "https://ap-northeast-1.queue.amazonaws.com", | |
); | |
# Create or Get a queue | |
my $q = $sqs->CreateQueue($queue_name); | |
# Long Polling Setting | |
$q->SetAttribute('ReceiveMessageWaitTimeSeconds', 20); | |
# Send a message | |
$q->SendMessage('Hello world!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import boto.sqs | |
from boto.sqs.message import Message | |
AWS_ACCESS_KEY='' | |
AWS_SECRET_KEY='' | |
queue_name = 'python_test_queue' | |
# connection | |
conn = boto.sqs.connect_to_region( | |
"ap-northeast-1", | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_KEY) | |
# Create or Get queue | |
queue = conn.create_queue(queue_name) | |
# Long Polling Setting | |
queue.set_attribute('ReceiveMessageWaitTimeSeconds', 20) | |
# send | |
queue.write(Message(body='Hello World!')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment