def test_async_consumer(request): # We'll use the ElasticMQ as backend since it works like a real SQS queue backend = LocalSQSBackend(host=os.environ.get("SQSHOST"), port=os.environ.get("SQSPORT")) queue_name = "testqueue" # Initialize the queue queue = MessagingBackendFactory(backend).init_queue(queue_name) # Delete the queue upon finishing the execution of the test def teardown(): backend.delete_queue(queue) request.addfinalizer(teardown) # Create a consumer that, upon receiving a message, will set # the variable "value set" to later assert that this value # has, indeed, been set by the consumer that is running on another thread state = State() def set_state(message: Dict) -> None: state.value_set = message["value"] consumer = Consumer(on_message=set_state) registry = SerializerRegistry(serializer_settings) handler = SimpleMessageDispatcher(consumer, registry, backend=backend) # Start the consumer loop thread to run the consumer loop in the background threading.Thread(target=lambda: handler.consume_loop(queue_name), daemon=True).start() # Publish a message and... publisher = QueuePublisher(registry, backend) publisher.publish(queue_name, {"value": 1}) # ...wait until the value is set probe = StateProbe(state) probe.wait() assert_that(state.value_set, is_(1))
from melange import MessagingBackendFactory from melange.backends import AWSBackend backend = AWSBackend() factory = MessagingBackendFactory(backend) factory.init_topic("my-topic")
import os from melange import MessagingBackendFactory from melange.backends import LocalSQSBackend if __name__ == "__main__": backend = LocalSQSBackend(host=os.environ.get("SQSHOST"), port=os.environ.get("SQSPORT")) factory = MessagingBackendFactory(backend=backend, ) factory.init_queue("payment-updates") factory.init_queue("order-updates") factory.init_queue("saga-updates") print("Queues created.")
def test_create_and_subscribe_queue_with_a_topic(self, backend): factory = MessagingBackendFactory(backend=backend) queue = factory.init_queue("myqueue", ["mytopic1", "mytopic2"], "mydlq") assert_that(queue.unwrapped_obj, is_not(none()))
def test_create_topic(self, backend): factory = MessagingBackendFactory(backend=backend) topic = factory.init_topic("mytopic") assert_that(topic.unwrapped_obj, is_not(none()))
from melange import MessagingBackendFactory from melange.backends import LocalSQSBackend backend = LocalSQSBackend() factory = MessagingBackendFactory(backend) factory.init_queue( "payment-updates.fifo", ["my-topic-1", "my-topic-2", "my-topic-3"], dead_letter_queue_name="payment-updates.fifo", )
from melange import MessagingBackendFactory from melange.backends import LocalSQSBackend backend = LocalSQSBackend(host="localhost", port=9324) factory = MessagingBackendFactory(backend) factory.init_queue("melangetutorial-queue")
from melange import MessagingBackendFactory from melange.backends import LocalSQSBackend backend = LocalSQSBackend() factory = MessagingBackendFactory(backend) factory.init_queue("payment-updates.fifo")