A local replacement for Amazon SQS.
I often see the method using connect_to_region
of boto
,
If it is a local ElasticMQ, you have to connect with regioninfo.SQSRegionInfo
, so make a note of it.
It seems that if ʻis_secure is set to
True, it becomes
https`.
ElasticMQ is dropped and started.
By default, the port is 9324
.
$ java -jar ~/opt/elasticmq-server-0.8.8.jar
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from boto.sqs import regioninfo
from boto.sqs.message import Message
AWS_ACCESS_KEY = 'TEST' #Any EMQ is fine
AWS_SECRET_KEY = 'TEST' #Any EMQ is fine
SQS_REGION = "emq" #Any EMQ is fine
SQS_ENDPOINT = "localhost"
#For AWS
# SQS_REGION = "ap-northeast-1"
# SQS_ENDPOINT = "sqs.ap-northeast-1.amazonaws.com"
SQS_QUEUE_NAME = 'dev_messages'
PORT = 9324 #80 for AWS/Or do not specify
region = regioninfo.SQSRegionInfo(name=SQS_REGION, endpoint=SQS_ENDPOINT)
conn = region.connect(
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
port=PORT,
is_secure=False
);
queue = conn.create_queue(SQS_QUEUE_NAME)
msg = Message(
body='QUEUE TEST',
)
msg.message_attributes = {
"name1": {
"data_type": "String",
"string_value": "I am a string"
},
}
queue.write(msg)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from boto.sqs import regioninfo
from boto.sqs.message import Message
AWS_ACCESS_KEY = 'TEST' #Any EMQ is fine
AWS_SECRET_KEY = 'TEST' #Any EMQ is fine
SQS_REGION = "emq" #Any EMQ is fine
SQS_ENDPOINT = "localhost"
#For AWS
# SQS_REGION = "ap-northeast-1"
# SQS_ENDPOINT = "sqs.ap-northeast-1.amazonaws.com"
SQS_QUEUE_NAME = 'dev_messages'
PORT = 9324 #80 for AWS/Or do not specify
region = regioninfo.SQSRegionInfo(name=SQS_REGION, endpoint=SQS_ENDPOINT)
conn = region.connect(
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
port=PORT,
is_secure=False
);
queue = conn.get_queue(SQS_QUEUE_NAME)
queue.set_attribute('ReceiveMessageWaitTimeSeconds', 20)
import json
msgs = queue.get_messages(10)
for msg in msgs:
print json.dumps(msg.__dict__, default=str)
queue.delete_message(msg)
Recommended Posts