示例#1
0
def wrapper_callback(message_data, message):
    """generic message consume callback wrapper

    content must be of type dict, with key matching function to be called
    passing value:

        content = {'function1': 'argument for function1'}
        would call func_function1('argument for function1')

    will raise an exception if message is not encrypted
    """

    # always send acknowledgement, even if an exception is raised so as not
    # block the queue
    message.ack()

    if not message_data["encrypted"]:
        raise Error("hubclient only accepts encrypted messages")

    secret = os.getenv("SECRET")
    sender, content, timestamp = decode_message(message_data, secret)

    for func_name in content.keys():
        func = getattr(sys.modules[__name__], "func_" + func_name)
        func(content[func_name])

    print "message processed (%s)" % timestamp.isoformat(" ")
示例#2
0
def wrapper_callback(message_data, message):
    """generic message consume callback wrapper

    content must be of type dict, with key matching function to be called
    passing value:

        content = {'function1': 'argument for function1'}
        would call func_function1('argument for function1')

    will raise an exception if message is not encrypted
    """

    # always send acknowledgement, even if an exception is raised so as not
    # block the queue
    message.ack()

    if not message_data['encrypted']:
        raise Error("hubclient only accepts encrypted messages")

    secret = os.getenv('SECRET')
    sender, content, timestamp = decode_message(message_data, secret)

    for func_name in content.keys():
        func = getattr(sys.modules[__name__], 'func_' + func_name)
        func(content[func_name])

    print "message processed (%s)" % timestamp.isoformat(" ")
示例#3
0
def decrypt_callback(message_data, message):
    encrypted = message_data['encrypted']
    secret = os.getenv('TKLAMQ_SECRET', None)

    if encrypted and not secret:
        fatal('TKLAMQ_SECRET not specified, cannot decrypt cipher text')

    sender, content, timestamp = decode_message(message_data, secret)
    print content

    message.ack()