Exemplo n.º 1
0
 def setUp(self):
     config = TestConfig()
     self._connection = Connection(config.broker_uri,
                                   "paramore.brightside.exchange",
                                   is_durable=True)
     self._producer = ArameProducer(self._connection)
     self._pipeline = Queue()
Exemplo n.º 2
0
class ArameGatewayTests(unittest.TestCase):

    test_topic = "kombu_gateway_tests"

    def setUp(self):
        self._connection = ArameConnection("amqp://*****:*****@localhost:5672//", "paramore.brighter.exchange")
        self._producer = ArameProducer(self._connection)
        self._consumer = ArameConsumer(self._connection, "brightside_tests", self.test_topic)

    def test_posting_a_message(self):
        """Given that I have an RMQ message producer
            when I send that message via the producer
            then I should be able to read that message via the consumer
        """
        header = BrightsideMessageHeader(uuid4(), self.test_topic, BrightsideMessageType.command, uuid4())
        body = BrightsideMessageBody("test content")
        message = BrightsideMessage(header, body)

        self._consumer.purge()

        self._producer.send(message)

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        self.assertEqual(message.id, read_message.id)
        self.assertEqual(message.body.value, read_message.body.value)
        self.assertTrue(self._consumer.has_acknowledged(read_message))

    def test_posting_object_state(self):
        """Given that I have an RMQ producer
            when I deserialize an object via the producer
            then I should be able to re-hydrate it via the consumer
        """
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), self.test_topic, BrightsideMessageType.command, uuid4())
        body = BrightsideMessageBody(JsonRequestSerializer(request=request).serialize_to_json(), BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        self._consumer.purge()

        self._producer.send(message)

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        deserialized_request = JsonRequestSerializer(request=TestMessage(), serialized_request=read_message.body.value)\
            .deserialize_from_json()

        self.assertIsNotNone(deserialized_request)
        self.assertEqual(request.bool_value, deserialized_request.bool_value)
        self.assertEqual(request.float_value, deserialized_request.float_value)
        self.assertEqual(request.integer_value, deserialized_request.integer_value)
        self.assertEqual(request.id, deserialized_request.id)
Exemplo n.º 3
0
 def setUp(self):
     config = TestConfig()
     self._connection = Connection(config.broker_uri,
                                   "paramore.brightside.exchange",
                                   is_durable=True)
     self._producer = ArameProducer(self._connection)
     self._pipeline = Queue()
     self._consumer = ArameConsumer(
         self._connection,
         BrightsideConsumerConfiguration(self._pipeline, "brightside_tests",
                                         self.test_topic))
Exemplo n.º 4
0
def run():
    message_store = FakeMessageStore()
    message_mapper_registry = MessageMapperRegistry()
    message_mapper_registry.register(HelloWorldCommand,
                                     map_hellworldcommand_to_message)
    connection = Connection("amqp://*****:*****@localhost:5672//",
                            "paramore.brightside.exchange",
                            is_durable=True)
    producer = ArameProducer(connection)

    command_processor = CommandProcessor(
        message_mapper_registry=message_mapper_registry,
        message_store=message_store,
        producer=producer)

    try:
        loop = 0
        while True:
            message = "Hello " + str(loop)
            hello = HelloWorldCommand(message)
            print("Sending message: {}".format(message))
            command_processor.post(hello)
            loop += 1

            if loop % 100 == 0:
                time.sleep(5)
    except KeyboardInterrupt:
        sys.exit(1)
Exemplo n.º 5
0
def run():
    message_store = FakeMessageStore()
    message_mapper_registry = MessageMapperRegistry()
    message_mapper_registry.register(LongRunningCommand,
                                     map_longrunningcommand_to_message)
    connection = Connection("amqp://*****:*****@localhost:5672//",
                            "paramore.brightside.exchange",
                            is_durable=True)
    producer = ArameProducer(connection)

    command_processor = CommandProcessor(
        message_mapper_registry=message_mapper_registry,
        message_store=message_store,
        producer=producer)

    job = LongRunningCommand(60)
    command_processor.post(job)
Exemplo n.º 6
0
def run():
    parser = argparse.ArgumentParser()
    parser.add_argument("name", help="the name to send a greeting to")
    args = parser.parse_args()

    message_store = FakeMessageStore()
    message_mapper_registry = MessageMapperRegistry()
    message_mapper_registry.register(HelloWorldCommand, map_hellworldcommand_to_message)
    connection = Connection("amqp://*****:*****@localhost:5672//", "paramore.brightside.exchange", is_durable=True)
    producer = ArameProducer(connection)

    command_processor = CommandProcessor(
        message_mapper_registry=message_mapper_registry,
        message_store=message_store,
        producer=producer
    )

    hello = HelloWorldCommand(args.name)
    command_processor.post(hello)
Exemplo n.º 7
0
 def setUp(self):
     self._connection = ArameConnection("amqp://*****:*****@localhost:5672//", "paramore.brighter.exchange")
     self._producer = ArameProducer(self._connection)
     self._consumer = ArameConsumer(self._connection, "brightside_tests", self.test_topic)
Exemplo n.º 8
0
class ArameGatewayTests(unittest.TestCase):
    def setUp(self):
        config = TestConfig()
        self._connection = Connection(config.broker_uri,
                                      "paramore.brightside.exchange",
                                      is_durable=True)
        self._producer = ArameProducer(self._connection)
        self._pipeline = Queue()

    def test_posting_a_message(self):
        """Given that I have an RMQ message producer
            when I send that message via the producer
            then I should be able to read that message via the consumer
        """
        test_topic = "kombu_gateway_tests" + str(uuid4())
        header = BrightsideMessageHeader(uuid4(), test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody("test content")
        message = BrightsideMessage(header, body)

        queue_name = "brightside_tests" + str(uuid4())
        consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, queue_name,
                                            test_topic))

        self._producer.send(message)

        read_message = consumer.receive(3)
        consumer.acknowledge(read_message)

        self.assertEqual(message.id, read_message.id)
        self.assertEqual(message.body.value, read_message.body.value)
        self.assertTrue(consumer.has_acknowledged(read_message))

    def test_requeueing_a_message(self):
        """Given that I have an RMQ consumer
            when I requeue a message
            then it should return to the end of the queue
        """
        test_topic = "kombu_gateway_tests" + str(uuid4())
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody(
            JsonRequestSerializer(request=request).serialize_to_json(),
            BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        queue_name = "brightside_tests" + str(uuid4())
        consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, queue_name,
                                            test_topic))

        self._producer.send(message)

        read_message = consumer.receive(3)

        consumer.requeue(read_message)

        # should now be able to receive it again
        reread_message = consumer.receive(3)
        consumer.acknowledge(reread_message)

        self.assertEqual(message.id, reread_message.id)
        self.assertEqual(message.body.value, reread_message.body.value)
        self.assertTrue(consumer.has_acknowledged(reread_message))

    def test_posting_object_state(self):
        """Given that I have an RMQ producer
            when I deserialize an object via the producer
            then I should be able to re-hydrate it via the consumer
        """
        test_topic = "kombu_gateway_tests" + str(uuid4())
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody(
            JsonRequestSerializer(request=request).serialize_to_json(),
            BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        queue_name = "brightside_tests" + str(uuid4())
        consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, queue_name,
                                            test_topic))

        self._producer.send(message)

        read_message = consumer.receive(3)
        consumer.acknowledge(read_message)

        deserialized_request = JsonRequestSerializer(request=TestMessage(), serialized_request=read_message.body.value)\
            .deserialize_from_json()

        self.assertIsNotNone(deserialized_request)
        self.assertEqual(request.bool_value, deserialized_request.bool_value)
        self.assertEqual(request.float_value, deserialized_request.float_value)
        self.assertEqual(request.integer_value,
                         deserialized_request.integer_value)
        self.assertEqual(request.id, deserialized_request.id)