Skip to main content

th2_common

Project description

TH2 Common Library (Python)

Installation

pip install th2-common

This package can be found on PyPI.

Usage

First things first, you need to import CommonFactory class:

from th2_common.schema.factory.common_factory import CommonFactory

Then you create an instance of imported class, choosing one of the options:

  1. Create factory with configs from default path (/var/th2/config/*):
    factory = CommonFactory()
    
  2. Create factory with configs from specified directory path (path/*):
    factory = CommonFactory(config_path=...)
    
  3. Create factory with configs from specified file paths:
    factory = CommonFactory(rabbit_mq_config_filepath=...,
                            mq_router_config_filepath=...,
                            grpc_router_config_filepath=...,
                            cradle_config_filepath=...,
                            custom_config_filepath=...)
    
  4. Create factory with configs from command line arguments (sys.argv):
    factory = CommonFactory.create_from_arguments()
    
  5. Create factory with configs from specified arguments:
    factory = CommonFactory.create_from_arguments(args)
    

After that you can create various Routers through factory properties:

message_parsed_batch_router = factory.message_parsed_batch_router
message_raw_batch_router = factory.message_raw_batch_router
event_batch_router = factory.event_batch_router

message_parsed_batch_router is working with MessageBatch
message_raw_batch_router is working with RawMessageBatch
event_batch_router is working with EventBatch

See th2-grpc-common for details.

With router created, you can subscribe to queues (specifying callback function) or send data that router works with:

router.subscribe(callback)  # subscribe to single queue 
router.subscribe_all(callback)  # subscribe to all queues
router.send(message)  # send to single queue
router.send_all(message)  # send to all queues

You can do these actions provide queue attributes in addition to default ones.

router.subscribe(callback, attrs...)  # subscribe to single queue
router.subscribe_all(callback, attrs...)  # subscribe to all queues
router.send(message, attrs...)  # send to single queue
router.send_all(message, attrs...)  # send to all queues

Default attributes are:

  • message_parsed_batch_router
    • Subscribe: subscribe, parsed
    • Send: publish, parsed
  • message_raw_batch_router
    • Subscribe: subscribe, raw
    • Send: publish, raw
  • event_batch_router
    • Subscribe: subscribe, event
    • Send: publish, event

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

th2_common-2.2.2.tar.gz (17.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page