Skip to main content

It provides a resident process that periodically pull subscribes and publish on CLI and Python.

Project description

Description

Fetch the Subscription of the GCP Pub/Sub regularly, and if there is a message execute the script specified by the key in the message.

GCP Pub/SubのSubscriptionを定期的にFetchし、 メッセージがあればメッセージ内のキーで指定されたスクリプトを実行する。

Installation and Try to this sample.

  1. Create Pub/Sub topic and subscription on GCP. (ex: test-topic/test-sub)

  2. pip install pubsub_controller

  3. pubsubcontroller init and input your Pub/Sub setting. (ex: GCP_PROJECT_ID=your project id / SUBSCRIPTION_ID=test-sub)

  4. pubsubcontroller subscribe

  5. Subscriber will start immediately.

  6. Open Another Terminal Window.

  7. pubsubcontroller publish test-topic test-message '{"target":"exec_sample","text":"test_text"}'

  8. In the Subscriber’s window you will see the contents of the message you just published!

Installation and Try to this sample.

  1. Create a new python file under “exec_classes” directory.

    • The same Python filename as the name specified by the attribute “target” key of the message to be published is executed.

  2. Implement def main (message_data, message_attr) and describe what you want to do after receiving the message.

    • “message_data” contains the contents of the received message.

    • “message_attr” contains optional attributes of the received message.

Details

  • Settings pubsub_controller/settings.py Required parameters are set here. (It is set automatically by the pubsubcontroller init command)

    • GCP PROJECT ID Your GCP ProjectID

    • SUBSCRIPTION ID Enter the Subscription ID to be used. If the Subscription name is projects/hoge-project/subscriptions/fuga, please enter fuga.

    • Interval Second Enter the interval to fetch Subscription in seconds.

  • Subscriber If you need a new subscriber, please refer to apps/subscriber/pull/exec_classes/exec_sample.py and create it.

  • Pull Subscriber This is a resident process that pulls Subscription.

    • config For reference, I am creating a supervisor config file. apps/subscriber/pull/config/pull_subscriber.ini

  • Publisher Execute from the CLI or Python script and publish the message to the topic.

    • Exec on CommandLine

      • pubsubcontroller publish test test-message '{"target":"exec_sample","text":"test_text"}'

      • arguments

        • arg1 = topic name

        • arg2 = message data

        • arg3 = message attribute(json format)

    • Exec on PythonCode

      from apps.publisher.publish_message import publish
      
      publish('test-topic', 'test_data', {'target':'exec_sample','text':'test_text'})

Project details


Download files

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

Source Distribution

pubsub_controller-1.0.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

pubsub_controller-1.0.1-py2-none-any.whl (14.1 kB view details)

Uploaded Python 2

File details

Details for the file pubsub_controller-1.0.1.tar.gz.

File metadata

File hashes

Hashes for pubsub_controller-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bb26c4b0b875fea102818ad80c0e98ed48618629f7ab833f14002823fad09648
MD5 af7e782b02a4b7d7a7263ab29c37fe53
BLAKE2b-256 af50e322aa066c67425ef26ecc63e94e8c65b53dcd186f4678eb99089f518f5f

See more details on using hashes here.

File details

Details for the file pubsub_controller-1.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for pubsub_controller-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 c9f182deb3a6862335110053db42ba21fccd8f316c15bc3f7d1d183bc2b24d0c
MD5 b43780ebb711a5df6b2284be2dedaf11
BLAKE2b-256 bb9704192c62e7184a99b79bce141e09aae8b74421095d3e512416751ec30308

See more details on using hashes here.

Supported by

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