Skip to main content

AMPS spark CLI

simple. fast. right from the command-line.

The AMPS spark CLI provides a simplified subset of AMPS commands in a command-line client. The client is designed for adhoc queries or light scripting.

tip

The AMPS spark CLI requires a JRE version 8 or later installed.

Example 1: Subscribe to a Topic​

%> spark subscribe -server localhost:9007 -type json -topic order

In this example, AMPS spark CLI connects to an AMPS server running locally and listening on port 9007 and starts a subscription to the order topic. As new messages are published to that topic, AMPS spark CLI writes the data of each message to stdout.

Example 2: Publish a Message​

%> echo '{ "id" : 1, "data": "hello, world!" }' | \
spark publish -server localhost:9007 -type json -topic order

In this example, AMPS spark CLI connects to AMPS for json messages. The AMPS spark CLI then reads a line from stdin and publishes that line to the order topic in AMPS as a json message.

Example 3: Publish Messages From a File​

%> spark publish -server localhost:9007 -type json -topic order \
-file order_data.json

In this example, AMPS spark CLI connects to AMPS for json messages. The AMPS spark CLI then reads the order_data.json file in the current directory, and publishes each line in the file as a message to the order topic.

Example 4: Query the Contents of a "SOW" Topic​

State-of-the-World ("SOW") topics in AMPS combine the power of a database table with the performance of a publish-subscribe system. You can use the AMPS spark CLI to query the contents of a SOW topic.

%> spark sow -server localhost:9007 -type json -topic order \
-filter "/id = '1'"

This example queries for all orders for the id 1, and simply prints the messages to the console.

Example 5: Save the Messages in a "SOW" Topic To A zip File​

The AMPS spark CLI can write the results of a SOW query to a file. The following command line will write the messages currently in the order topic to the order.zip file, with one message per file within the archive.

%> spark sow -server localhost:9007 -type json -topic order -file order.zip

Example 6: Publish Messages From A zip File​

The AMPS spark CLI can read the contents of a zip file publish the contents of the file. In this case, each individual file at the root level of the archive will be read and published as an individual message. The AMPS spark CLI will read these files and publish the contents in filename order. Files in nested directories will not be processed.

%> spark publish -server localhost:9007 -type json -topic order -file order.zip

Example 7: List Complete Options​

The AMPS spark CLI includes help screens that show complete options for each command. For example, the command below shows the complete set of options for the sow command:

%> spark help sow

Ready To Crank it Up?​

The AMPS spark CLI is ready to go for adhoc queries and simple scripting jobs. It offers a simplified set of options, and doesn't try to provide all of the features that a full client library would provide.

For work that goes beyond simple scripting, the AMPS Client for Python includes everything you need to fully take advantage of AMPS in the Python language.