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.
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.
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.
Last updated