Performing SOW Queries
To begin, we will look at a simple example of issuing a SOW query.
In the listing above, the program invokes ampsClient.sow()
to initiate a SOW query on the orders
topic, for all entries that have a symbol of ’ROL’. The SOW query is requested with a batch size of 100, meaning that AMPS will attempt to send 100 messages at a time as results are returned.
As the query executes, each matching entry in the topic at the time of the query is returned. Messages containing the data of matching entries have a Command
of value sow
, so as those arrive, we write them to the console. AMPS sends a "group_begin" message before the first SOW result, and a "group_end" message after the last SOW result.
When the SOW query is complete, the MessageStream
completes iteration and the loop completes. There's no need to explicitly break out of the loop.
As with subscribe, the sow function also provides an asynchronous version. In this case, you provide a message handler that will be called on a background thread:
In the listing above, the ExecuteSOWQuery()
function invokes client.sow()
to initiate a SOW query on the orders topic, for all entries that have a symbol of ROL
. The SOW query is requested with a batch size of 100, meaning that AMPS will attempt to send 100 messages at a time as results are returned.
As the query executes, the HandleSOW()
method is invoked for each matching entry in the topic. Messages containing the data of matching entries have a Command
of sow
, so as those arrive, we write them to the console.
Last updated