Allow message passing to SQS queues in different regions from SNS.
This commit is contained in:
parent
53acdf6c76
commit
16660ab72b
@ -9,7 +9,7 @@ import six
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import iso_8601_datetime
|
||||
from moto.sqs import sqs_backend
|
||||
from moto.sqs import sqs_backends
|
||||
from .utils import make_arn_for_topic, make_arn_for_subscription
|
||||
|
||||
DEFAULT_ACCOUNT_ID = 123456789012
|
||||
@ -54,7 +54,8 @@ class Subscription(object):
|
||||
def publish(self, message, message_id):
|
||||
if self.protocol == 'sqs':
|
||||
queue_name = self.endpoint.split(":")[-1]
|
||||
sqs_backend.send_message(queue_name, message)
|
||||
region = self.endpoint.split(":")[3]
|
||||
sqs_backends[region].send_message(queue_name, message)
|
||||
elif self.protocol in ['http', 'https']:
|
||||
post_data = self.get_post_data(message, message_id)
|
||||
requests.post(self.endpoint, data=post_data)
|
||||
|
@ -12,11 +12,12 @@ from .exceptions import (
|
||||
)
|
||||
|
||||
MAXIMUM_VISIBILTY_TIMEOUT = 43200
|
||||
SQS_REGION_REGEX = r'://(.+?)\.queue\.amazonaws\.com'
|
||||
|
||||
|
||||
class QueuesResponse(BaseResponse):
|
||||
|
||||
region_regex = r'://(.+?)\.queue\.amazonaws\.com'
|
||||
region_regex = SQS_REGION_REGEX
|
||||
|
||||
@property
|
||||
def sqs_backend(self):
|
||||
@ -50,6 +51,8 @@ class QueuesResponse(BaseResponse):
|
||||
|
||||
class QueueResponse(BaseResponse):
|
||||
|
||||
region_regex = SQS_REGION_REGEX
|
||||
|
||||
@property
|
||||
def sqs_backend(self):
|
||||
return sqs_backends[self.region]
|
||||
|
@ -29,6 +29,26 @@ def test_publish_to_sqs():
|
||||
message.get_body().should.equal('my message')
|
||||
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
def test_publish_to_sqs_in_different_region():
|
||||
conn = boto.sns.connect_to_region("us-west-1")
|
||||
conn.create_topic("some-topic")
|
||||
topics_json = conn.get_all_topics()
|
||||
topic_arn = topics_json["ListTopicsResponse"]["ListTopicsResult"]["Topics"][0]['TopicArn']
|
||||
|
||||
sqs_conn = boto.sqs.connect_to_region("us-west-2")
|
||||
sqs_conn.create_queue("test-queue")
|
||||
|
||||
conn.subscribe(topic_arn, "sqs", "arn:aws:sqs:us-west-2:123456789012:test-queue")
|
||||
|
||||
conn.publish(topic=topic_arn, message="my message")
|
||||
|
||||
queue = sqs_conn.get_queue("test-queue")
|
||||
message = queue.read(1)
|
||||
message.get_body().should.equal('my message')
|
||||
|
||||
|
||||
@freeze_time("2013-01-01")
|
||||
@mock_sns
|
||||
def test_publish_to_http():
|
||||
|
Loading…
Reference in New Issue
Block a user