diff --git a/README.md b/README.md index 714c1c319fe429026215cd1b4356962f016dfbc3..950c173cebdc3176aa7c70faaadf1a036d67ad59 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,10 @@ your application that a disconnect happened. You only need to remember that: -1. Reconnects and redefinitions take a while. - * Things will happen during that time. It is your responsibility to ensure that your distributed system is built to handle this -2. CoolAMQP will tell you when it senses losing broker connection. - * It will also tell you when it regains the connection (that means that everything is redefined and ready to go) -3. Delivering messages multiple times may happen. - * Ensure you know when it happens. Keywords: message acknowledgement, amqp specification +1. Reconnects and redefinitions take a while. Things will happen during that time. It is your responsibility to ensure that your distributed system is built to handle this +2. CoolAMQP will tell you when it senses losing broker connection. It will also tell you when it regains the connection (that means that everything is redefined and ready to go) +3. Delivering messages multiple times may happen. Ensure you know when it happens. Keywords: message acknowledgement, amqp specification +4. CoolAMQP won't unserialize your messages. You send bags of bytes and properties, you get bags of bytes and their properties. The project is actively maintained and used in a commercial project. Tests can run either on Vagrant (Vagrantfile attached) or Travis CI, and run against RabbitMQ. diff --git a/coolamqp/messages.py b/coolamqp/messages.py index 4815e3440dac4980f8f16da4b71afd408bbc1b9f..c30db8abd4f414b6459bfc524906e2a586fd616f 100644 --- a/coolamqp/messages.py +++ b/coolamqp/messages.py @@ -13,7 +13,8 @@ class Message(object): :type body: str (py2) or bytes (py3) :param properties: AMQP properties to be sent along """ - assert isinstance(body, six.binary_type) + if not isinstance(body, six.binary_type): + raise TypeError('Message body must be binary!') self.body = body self.properties = {} if properties is None else properties diff --git a/tests/test_basics.py b/tests/test_basics.py index 90cfc8a07519dacb3291dc33aac4eb668ee3729f..cb702a5128efd9503e8efb1689d54209dde173c3 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -42,6 +42,9 @@ class TestBasics(unittest.TestCase): self.assertIs(self.amqp.drain(wait=1), None) + def test_send_bullshit(self): + self.assertRaises(TypeError, lambda: Message(u'what the fuck')) + def test_nacknowledge(self): myq = Queue('myqueue', exclusive=True) diff --git a/tests/test_failures.py b/tests/test_failures.py index 9cc2f7bd5172a2e6a22089f2987a72f53f5f2b9a..5eb6a96401d0ce672bf2032f6131155873bbd34d 100644 --- a/tests/test_failures.py +++ b/tests/test_failures.py @@ -85,7 +85,7 @@ class TestFailures(unittest.TestCase): os.system("sudo service rabbitmq-server stop") self.assertIsInstance(self.amqp.drain(wait=4), ConnectionDown) - result = self.amqp.send(Message('what the fuck'), '', routing_key='wtf1') + result = self.amqp.send(Message(b'what the fuck'), '', routing_key='wtf1') result.cancel() os.system("sudo service rabbitmq-server start") @@ -120,7 +120,7 @@ class TestFailures(unittest.TestCase): os.system('sudo service rabbitmq-server restart') - self.amqp.send(Message('hello'), xchg) + self.amqp.send(Message(b'hello'), xchg) self.assertIsInstance(self.amqp.drain(wait=4), ConnectionDown) self.assertIsInstance(self.amqp.drain(wait=10), ConnectionUp) self.assertIsInstance(self.amqp.drain(wait=4), MessageReceived)