Package: pikatopic
PikaTopic - a convenience layer atop Pika for use with RabbitMQ topic exchangesPika is a good general purpose library for interacting with a RabbitMQ
server. PikaTopic is a simpler, limited interface which can be used when
you just need to send or receive messages using a topic exchange.Additionally, PikaTopic will handle json conversion when sending and
receiving data.Seehttps://github.com/AnimationMentor/pikatopicfor more usage
examples.ConfigurationYou will probably need to set the host name to connect to your RabbitMQ
server. The username, password and exchange are all set to defaults
which work for a generic server install.Default values:host islocalhostOR thePIKATOPIC_HOSTenvariable if that is
setusername isguestOR thePIKATOPIC_USERNAMEenvariable if
that is setpassword isguestOR thePIKATOPIC_PASSWORDenvariable if
that is setexchange isamq.topicOR thePIKATOPIC_EXCHANGEenvariable if
that is setThese may be overridden by passing any of these arguments to thePikaTopicclass initialiser or you can change them at the module
level by:import pikatopic

pikatopic.DEFAULT_USERNAME = 'otheruser'
pikatopic.DEFAULT_PASSWORD = 'secrt'
pikatopic.DEFAULT_HOST = '172.17.0.2'
pikatopic.DEFAULT_EXCHANGE = 'monster'Pika LibraryPikatopic depends on the pika libary.http://pika.readthedocs.io/Examplesfrom pikatopic import PikaTopic

with PikaTopic(host='172.17.0.2') as pt:
    pt.sendData(
        "project.new",
        {
        'project_id':"12345-12345",
        'name':"The Amazing Adventures of Sausage Farts The Dog",
        'creator_id':"676867-45657",
        },
    )from pikatopic import PikaTopic

def handler(routing_key, message, message_data):
    if message_data:
        print("%r data=%r" % (routing_key, message_data))
    else:
        print("%r text=%r" % (routing_key, message))
    return True


with PikaTopic(host='172.17.0.2') as pt:
    pt.listen(handler, ['#'])ReferenceThis library provides a class,PikaTopicwhich can be used for
sending and receiving messages.Unless using thewithconstruct as in the examples above, you must
callopen()andclose()before and after thesend...()andlisten()functions.SendingsendText(routing_key (string), message (string))sendData(routing_key (string), message (dict or list))ThesendDatamethod converts the message to a json string and sets
the message content_type property to application/json.Receivinglisten(handler (function), binding_keys (list of strings))Thelistenmethod enters an event loop which normally does not
return.It accepts a handler function which is called for each message received.handler(routing_key, message_text, message_data)message_textcontains the raw text of the message. If the message is
json encoded thenmessage_datacontains the decoded dict otherwise
it is set toNone.If the handler returns a false value, thelisten()loop will return.Serverless TestingPassno_rabbit_server=Trueto the class initialiser to run without
connecting to a server.This might be useful for testing or transition.You may want to also setverbose=TrueVerbosePassverbose=Trueto the class initialiser to get messages sent to
stdout by the listen() and send…() functions.Thanks, Artella!This work was funded by Artella (https://www.artella.com/).