def handle_message():
    """
    Example that shows how to handle messages
    """
    print("handle message")

    msg1 = Message(body="hello world!".encode("utf-8"), header={"h1": "val1"})

    msg2 = Message(body="hello world!".encode("utf-8"), header={"h1": "val1"})
    assert(msg1 == msg2)
    msg2 = msg1.serialize()
    msg2 = deserialize(msg2)
    assert(msg1 == msg2)

    msg3 = deserialize('{"body": "hello world!", "header": {"h1": "val1"}}')
    assert(msg1 == msg3)

    tmp = msg1.stringify()
    msg4 = destringify(tmp)
    assert(msg1 == msg4)

    msg5 = msg1.jsonify()
    assert(isinstance(msg5, dict))
    msg5 = dejsonify(msg5)
    assert(msg1 == msg5)

    print("...handle message OK!")
 def __stringify(self, **kwargs):
     """ helper """
     gen = Generator(**kwargs)
     msg = gen.message()
     for option in MESSAGE_CONVERT_OPTIONS:
         stringified = msg.stringify(option)
         msg_b = message.destringify(stringified)
         self.assertEqual(msg, msg_b,
                          "Error in de/stringification:\n%s\n%s\n" %
                          (msg, msg_b))