Package: t3-core
InstallSetup Virtualenv (optional)python-mvenv.venvsource.venv/bin/activate# There is a bug in pip 9.x  go ahead and upgrade to make sure that you're pip 10.xpipinstall--upgradepipInstall# Install from pypipipinstallt3-core# Install in the `src` dir of your python environmentpipinstall-egit+ssh://git@gitlab.t-3.com:t3-core/t3-core-python.git# Choose where the clone livesgitclonegit@gitlab.t-3.com:t3-core/t3-core-python.gitpipinstall-e./t3-python-coreTesting & LintingTest & Coverage ReportpytestLintpylamaT3 EventsInt3-core, we’ve a sub-module which is an event queue system used to connect microservices together, in an asynchronous manner, with built-in fault tolerance. It usesRabbitMQas a messaging bus to accomplish this. Event queue system consists of 2 main parts,consumer, andpublisher.A Consumer, as the name suggests, consumes the messages, by invoking a callback upon receiving the specified message, which is published by the Publisher. Separately running processes, commonly known as workers can consume messages, whereas, any process including web process can publish messages. If any process is unable to finish consuming the message, it gets requed in the system and is sent to a different consumer or stored until the consumer is available again.InT3 Events.T3 Events, is configured by setting up 2 key environment variables,T3_EVENTS, andT3_EVENTS_AMQP_URL, the first one is a boolean value oftrueorfalseon whether to use events or not, and the second one is a connection string forrabbit-mq. This env vars can be inserted into any system, and as long as different systems have same value for those env vars, they are part of the same message queue system. There are two main types of consumers and publishers, details below:TaskTask consumer/publisher are dedicated to consuming or publishing Tasks, which by definition are consumed one at a time, for a given task, which means, the first available consumer will pick up the task and process it, then the next task in the list will go to the next available consumer, and so on. Below is an example of a sample task.Consumer:fromt3.events.consumersimoprtTaskConsumerdefmessage_callback(payload):print(f'message callback task consumer: payload:{payload}')# Start consumertest=TaskConsumer()test.set_task_name('test_task')test.set_callback(message_callback)test.run()Publisher:fromt3.events.publishersimportTaskPublisher# Use publishertest=TaskPublisher()test.set_task_name('test_task')test.set_message('test message, could be in json too')test.run()For the above example, the given example task name istest_task, which is the same for a consumer and a publisher, which connects them together. Since this is aTaskConsumer, and aTaskPublisher, if you run more than 1Consumer, andPublishseveral times, it’ll be processed in a round-robin manner with the runningConsumers, one at a time. Once 1 message is processed, then the system moves on to the next one, and so on.TopicTopic consumer/publisher are dedicated to consuming or publishingTopics, which by definition are broadcasted to all subscribedConsumers, for a givenTopic, which means, when a topic is published, all consumers signed up for this topic will receive the message. Below is an example of a sample topic.Consumer:fromt3.events.consumersimportTopicConsumerdefmessage_callback(payload):print(f'message callback topic consumer: payload:{payload}')# Start consumertest=TopicConsumer()test.set_topic_name('test_topic')test.set_callback(message_callback)test.run()Publisher:fromt3.events.publishersimportTopicPublisherimportjson# Use publishertest=TopicPublisher()test.set_topic_name('test_topic')test.set_message(json.dumps({'json':'object'}))test.run()For the above example, the given topic name istest_topic, which is the same for a consumer and a publisher, which connects them together. Since this is aTopicConsumer, and aTopicPublisher, if you run more than 1Consumer, andPublish, it’ll be processed by all runningConsumers, at once.Running T3 EventsT3 events is composed ofConsumers, andPublishers.Consumers must be run in a separate process, as they are independent of anything else that is going on in the system, for local development, you can runpython name_of_consumer_file.py, however in production environments, usenohup python name_of_consumer_file.py, for fault tolerance purposes.Pubishers on the other hand, can be run as part of a process, as their main job is to publish an event to the message queue system. To use aPublisher, you can run the lines below# Use publisherfrom the above examples, provided the 2 required environment variables are present.