LogoLogo
AMPS C#/.NET Client 5.3.3
AMPS C#/.NET Client 5.3.3
  • Welcome to the AMPS C#/.NET Client
    • Before You Start
    • Obtaining and Installing the AMPS C#/.NET Client
    • Your First AMPS Program
      • Client Identification
      • Connection Strings for AMPS
      • Connection Parameters for AMPS
      • Providing Credentials to AMPS
      • Assembly Deployment
    • Subscriptions
      • Content Filtering
        • Changing the Filter on a Subscription
      • Understanding Message Objects
      • Synchronous Message Processing
      • Asynchronous Message Processing
        • Understanding Threading
      • 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
      • Acknowledgement Batching
      • Returning a Message to the Queue
      • Manual Acknowledgement
    • 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 C#/.NET 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 C# 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.

public void ExecuteSOWQuery(Client client)
{

    foreach (Message m in client.sow("messages-sow", "/id > 20"))
    {
        if (m.Command == Message.Commands.BeginGroup)
        {
            System.Console.WriteLine("--- Begin SOW Results ---");
        }
        if (m.Command == Message.Commands.EndGroup)
        {
            System.Console.WriteLine("--- End SOW Results ---");
        }
        if (m.Command == Message.Commands.SOW)
        {
            System.Console.WriteLine(m.Data);
        }
    }
}

In the example above, the ExecuteSOWQuery() function invokes Client.sow() to initiate a SOW query on the messages-sow topic, for all entries that have an id greater than 20.

As the query executes, the body of the loop is invoked for each matching entry in the topic. Messages containing the data of matching entries have a Command of value sow; as those arrive, we write them to the console. AMPS sends a group_begin message at the beginning of the results and a group_end message at the end of the results. We use those messages to delimit the results of the query.

As with subscribe, the sow command also provides an asynchronous version, as well as versions that accept a Command. For example, the listing below shows an asynchronous SOW command that specifies the batch size, or the maximum number of records that AMPS will return at a time.

private void HandleSOW(Message message)
{
    if (message.Command == Message.Commands.SOW)
    {
        Console.WriteLine(message.Data);
    }
}

public void ExecuteSOWQuery(Client client)
{
    Command command = new Command(Message.Commands.SOW)
                             .setTopic("messages-sow")
                             .setFilter("/id > 20")
                             .setBatchSize(100);

    client.executeAsync(command, message => HandleSOW(message));

}

In the example above, the ExecuteSOWQuery() function invokes Client.executeAsync() to initiate a SOW query on the messages-sow topic, for all entries that have an id greater than 20. 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 value sow; as those arrive, we write them to the console.

PreviousMonitoring Connection StateNextSOW and Subscribe

Last updated 3 months ago