LogoLogo
AMPS Python Client 5.3.4
AMPS Python Client 5.3.4
  • Welcome to the AMPS Python Client
    • Before You Start
    • Obtaining and Installing the AMPS Python Client
    • Your First AMPS Program
      • Client Identification
      • Connection Strings for AMPS
      • Connection Parameters for AMPS
      • Providing Credentials to AMPS
    • Subscriptions
      • Content Filtering
        • Changing the Filter on a Subscription
      • Synchronous Message Processing
      • Asynchronous Message Processing
        • Understanding Threading
      • Understanding Message Objects
      • Regular Expression Subscriptions
      • Ending Subscriptions
    • Error Handling
      • Exceptions
      • Exception Types
      • Exception Handling and Asynchronous Message Processing
      • Controlling Blocking with Command Timeout
      • Disconnect Handling
        • Using a Heartbeat to Detect Disconnection
        • Managing Disconnection
        • Replacing Disconnect Handling
      • Unexpected Messages
      • Unhandled Exceptions
      • Detecting Write Failures
      • Monitoring Connection State
    • State of the World
      • SOW and Subscribe
      • Setting Batch Size
      • Managing SOW Contents
      • Client Side Conflation
    • Using Queues
      • Backlog and Smart Pipelining
      • Acknowledging Messages
      • Returning a Message to the Queue
      • Manual Acknowledgment
    • Delta Publish and Subscribe
      • Delta Subscribe
      • Delta Publish
    • High Availability
    • AMPS Programming: Working with Commands
    • Utility Classes
    • Advanced Topics
    • Exceptions Reference
    • AMPS Server Documentation
    • API Documentation
Powered by GitBook

Get Help

  • FAQ
  • Legacy Documentation
  • Support / Contact Us

Get AMPS

  • Evaluate
  • Develop

60East Resources

  • Website
  • Privacy Policy

Copyright 2013-2024 60East Technologies, Inc.

On this page
Export as PDF
  1. Welcome to the AMPS Python Client

State of the World

AMPS State of the World (SOW) allows you to automatically keep and query the latest information about a topic on the AMPS server, without building a separate database. Using SOW lets you build impressively high-performance applications that provide rich experiences to users. The AMPS Python client lets you query SOW topics and subscribe to changes with ease.

Performing SOW Queries

To begin, we will look at a simple example of issuing a SOW query.

for message in client.sow("orders", "/symbol='ROL'"):
    if message.get_command() == AMPS.Message.Command.GroupBegin:
        print("--- Begin SOW Results ---")
    if message.get_command() == AMPS.Message.Command.SOW:
        print(message.get_data())
    if message.get_command() == AMPS.Message.Command.GroupEnd:
        print("--- End SOW Results ---")

In the example above, the Client.sow() convenience method is used to execute a SOW query on the orders topic, for all entries that have a symbol of 'ROL'.

As the query executes, messages containing the data of matching entries have a Command of value "sow" (provided as a constant value, AMPS.Message.Command.SOW), so as those arrive, we write them to the console.

As with subscribe, the sow command also provides an asynchronous mode, where you provide a message handler.

def on_message_handler(message):
    if message.get_command() == AMPS.Message.Command.GroupBegin:
        print("--- Begin SOW Results ---")
    if message.get_command() == AMPS.Message.Command.SOW:
        print(message.get_data())
    if message.get_command() == AMPS.Message.Command.GroupEnd:
        print("--- End SOW Results ---")

def execute_sow_query(client):
    return client.execute_async(             \
            AMPS.Command("sow")              \
                .set_topic("orders")         \
                .set_filter("/symbol='ROL'"),\
            on_message_handler)

execute_sow_query(client)

In the example above, the execute_sow_query() function invokes Client.execute_async() to initiate a SOW query on the orders topic, for all entries that have a symbol of 'ROL'.

As the query executes, the on_message_handler() function is invoked for each matching entry in the topic. Messages containing the data of matching entries have a Command of value sow, so as those arrive, we write them to the console.

PreviousMonitoring Connection StateNextSOW and Subscribe

Last updated 3 months ago