Queries
At any point in time, applications can issue SOW queries to retrieve all of the messages that match a given topic and content filter. When a query is executed, AMPS will test each message in the SOW against the content filter specified and all messages matching the filter will be returned to the client. The topic can be a literal topic name or a regular expression pattern. For more information on issuing queries, please see Querying the State of the World (SOW) in the AMPS User Guide.
A SOW query is atomic. Updates that occur while the query is running, or while a client is receiving results, are not returned as part of the query.
Spark: Basic SOW Query Example
Here's how to use spark
to query the current state of an AMPS SOW topic.
This example assumes that:
You have configured a topic named
test-sow
in the AMPS server of message type JSON.The
test-sow
topic uses the/id
field of the message to calculate the key for the topic.
To retrieve the current state of the topic, an application issues the sow
command. Unlike a subscription, which stays active until it is explicitly stopped (or the application disconnects), the sow
command provides results for a specific point in time. Once the results are returned, the command is over.
First, publish a message or two to the test-sow
topic:
Open a new terminal in your Linux environment.
Use the following command (with
AMPS_DIR
set to the directory where you installed AMPS) to send a single message to AMPS:spark
automatically connects to AMPS and sends a logon command with the default credentials (the current username and an empty password). With thepublish
command,spark
reads the message from the standard input and publishes the message to the JSON topictest-sow
. The command produces output similar to the following line (the rate calculation will likely be different:When the publisher sends the message, AMPS parses the message to determine the value of the Key fields in the message, and then either inserts the message for that key, or overwrites the existing message with that key.
You can publish any number of messages this way. Each distinct
id
value will create a distinct record in the topic.
Next, retrieve the current contents of the topic:
Open a new terminal in your Linux environment.
Use the following command (with
AMPS_DIR
set to the directory where you installed AMPS) to retrieve the contents of the topic:spark
automatically connects to AMPS and sends a logon command with the default credentials (the current username and an empty password).spark
then sends thesow
command to AMPS. This command requests the current contents of thetest-sow
topic. Since the command is finished once the query is complete,spark
will exit when the query results are complete.spark
shows the current contents of the topic. Notice that the output is strictly the message data, separated by newline characters.spark
does not show any of the metadata for a message.
Last updated