示例#1
0
    def test_send_non_persistent(self):
        c = VigiloClient(None, None, None)
        c.channel = mock.Mock()
        c.channel.basic_publish.side_effect = lambda *a, **kw: defer.succeed(None)
        d = c.send("exch", "key", "msg", persistent=False)

        def check(r):
            self.assertTrue(c.channel.basic_publish.called)
            # print c.channel.basic_publish.call_args_list
            args = c.channel.basic_publish.call_args_list[0][1]
            print args
            self.assertTrue("delivery-mode" in args["content"].properties)
            self.assertEqual(args["content"].properties["delivery-mode"], 1)
            self.assertEqual(args["immediate"], True)

        d.addCallback(check)
        return d
示例#2
0
文件: essai.py 项目: vigilo/connector
class Tester(BusHandler):
    client = None
    def connectionInitialized(self, arg):
        print "initialized"
    def connectionLost(self, arg):
        print "lost"

class MsgLogger(MessageHandler):

    def processMessage(self, msg):
        print "RECV:", type(msg), msg, msg.__dict__
        #LOGGER.info("RECV2: %s", msg.content)

    def sendDummy(self):
        self.client.send("machin", "truc", "truc-machin")

client = VigiloClient(host="localhost", user="******", password="******", log_traffic=True)
client.addHandler(Tester())
msglogger = MsgLogger()
msglogger.setClient(client)
msglogger.subscribe("truc")
msglogger.sendDummy()


def stop():
    client.stopService()
    reactor.stop()
reactor.callLater(2, stop)
application = service.Application("essai")
client.setServiceParent(application)