-
-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amazon SQS transport passing functional tests. Sponsored by the good …
…guys at Yipit.com!
- Loading branch information
Showing
5 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
|
||
from nose import SkipTest | ||
|
||
from funtests import transport | ||
|
||
|
||
class test_SQS(transport.TransportCase): | ||
transport = "SQS" | ||
prefix = "sqs" | ||
sep = "-" # SQS queue names cannot include '.' | ||
event_loop_max = 100 | ||
message_size_limit = 4192 # SQS max body size / 2. | ||
|
||
def before_connect(self): | ||
if "AWS_ACCESS_KEY_ID" not in os.environ: | ||
raise SkipTest("Missing envvar AWS_ACCESS_KEY_ID") | ||
if "AWS_SECRET_ACCESS_KEY" not in os.environ: | ||
raise SkipTest("Missing envvar AWS_SECRET_ACCESS_KEY") | ||
|
||
def after_connect(self, connection): | ||
connection.channel().client |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
""" | ||
kombu.transport.SQS | ||
=================== | ||
Amazon SQS transport. | ||
:copyright: (c) 2010 - 2011 by Ask Solem | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
from Queue import Empty | ||
|
||
from anyjson import serialize, deserialize | ||
from boto.sqs.connection import SQSConnection | ||
from boto.sqs.message import Message | ||
|
||
from kombu.transport import virtual | ||
from kombu.utils import cached_property | ||
|
||
class Channel(virtual.Channel): | ||
_client = None | ||
|
||
def _new_queue(self, queue, **kwargs): | ||
return self.client.create_queue(queue, self.visibility_timeout) | ||
|
||
def _get(self, queue): | ||
q = self._new_queue(queue) | ||
rs = q.get_messages(1) | ||
if rs: | ||
return deserialize(rs[0].get_body()) | ||
raise Empty() | ||
|
||
def _size(self, queue): | ||
return self._new_queue(queue).count() | ||
|
||
def _put(self, queue, message, **kwargs): | ||
q = self._new_queue(queue) | ||
m = Message() | ||
m.set_body(serialize(message)) | ||
q.write(m) | ||
|
||
def _purge(self, queue): | ||
q = self._new_queue(queue) | ||
size = q.count() | ||
q.clear() | ||
return size | ||
|
||
def close(self): | ||
super(Channel, self).close() | ||
if self._client: | ||
try: | ||
self._client.close() | ||
except AttributeError, exc: # FIXME ??? | ||
if "can't set attribute" not in str(exc): | ||
raise | ||
|
||
def _open(self): | ||
conninfo = self.connection.client | ||
return SQSConnection(conninfo.userid, conninfo.password) | ||
|
||
@property | ||
def client(self): | ||
if self._client is None: | ||
self._client = self._open() | ||
return self._client | ||
|
||
@cached_property | ||
def visibility_timeout(self): | ||
options = self.connection.client.transport_options | ||
return options.get("visibility_timeout") | ||
|
||
|
||
class Transport(virtual.Transport): | ||
Channel = Channel | ||
|
||
interval = 1 | ||
default_port = None | ||
connection_errors = () | ||
channel_errors = () |
This file contains 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
This file contains 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