C# Client API

powerful. fast. easy.

The AMPS C# Client lets you write blazingly fast messaging applications for Windows and the .NET framework. Here's a few examples in C# to get you started:

Example 1: Connect and Subscribe

Connecting and subscibing to a content-filtered topic couldn't be easier:

 1 using AMPS.Client;
 2         ...
 3         Client amps = new Client("myapplication");
 5         try {
 6             amps.connect("tcp://");
 7             amps.logon();
 9             foreach (Message msg
10                        in amps.subscribe("orders",
11                                          "/symbol LIKE 'ABCD'")
12             {
13                   Console.WriteLine(msg.Data);
14             }
16         } catch (AMPSException exception) {
17             Console.WriteLine(exception);
18         }

In this example, we connect to AMPS and subscribe to the "orders" topic. Messages are filtered on the server: we're only sent messages whose "symbol" field contains "ABCD". As messages arrive, they're handled by the lambda function provided, which prints their data to the console.

Example 2: Automatic Reconnection and Resubscription

Rock-solid applications must be able to recover from network outages. The AMPS C# client includes an HAClient class that includes automatic reconnection and resubscription. Best of all, easy-to-implement interfaces control reconnection and resubscription behavior, allowing you to easily customize failover.

 1 HAClient client = new HAClient("reconnectingSubscriber");
 3 // The ServerChooser interface tells the HAClient which server
 4 // to connect to, both for the initial connection and failover.
 5 // The DefaultServerChooser is included with the client: many
 6 // applications implement a ServerChooser to control failover
 7 // behavior.
 9 DefaultServerChooser sc = new DefaultServerChooser();
10 sc.add("tcp://amps-server:9007/amps/json");
11 sc.add("tcp://amps-failover-server:9007/amps/json");
12 client.setServerChooser(sc);
14 client.connectAndLogon();
16 // Enter subscriptions. If the connection to the server
17 // is lost, the HAClient will restore the connection to
18 // the server or the failover partner, and restore
19 // subscriptions.
21 client.subscribe(new MyMessageHandler(), "my-cool-topic");

The HAClient class can, optionally, also provide store-and-forward for reliable publish. With the AMPS transaction log, the class can provide resumable subscriptions that are guaranteed not to miss messages or receive duplicate messages, even in the case of failover between replicated servers.

Example 3: Build User Interfaces in a Snap With XAML

The AMPS Client now contains direct support for XAML as part of the new AMPS.Client.XAML namespace. Build user interfaces in a snap using data binding together with AMPS. Here's an example of using AMPS from a application's XAML, and displaying a real-time topic subscription in a DataGrid:

1 <amps:Server x:Key="localhost" Hostname="localhost"
2               Port="9007" MessageType="json"/>
3       <amps:Subscription Server="{StaticResource localhost}"
4               x:Key="orders" Topic="orders"/>
6       <StackPanel DataContext="{StaticResource orders}">
7         <DataGrid ItemsSource="{Binding Data}"
8               AutoGenerateColumns="true"/>
9       </StackPanel>

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. Use the AMPS C# client to query the contents of a SOW topic.

 1 using AMPS.Client;
 3       ...
 5       void QuerySOW(Client client)
 6       {
 7         foreach (Message message in amps.sow("orders",
 8                                          "/symbol = 'ROL'))
 9         {
10              if (message.Command = "sow")
11              {
12                  Console.WriteLine(message.Data);
13              }
14         }
15       }

This example queries for all orders for the symbol ROL and simply prints those orders to the console.

Everything You Need

Ready to learn more? The AMPS C# Client includes everything you need to get started: libraries, sample applications, developer's guide, and reference documentation. Each AMPS Client includes complete source code so you can fully learn and understand AMPS, and best integrate it into your environment.

Click here to download and start using the AMPS C# Client. Once you've downloaded it, read the Developer Guide to get started.

(Looking for a plain .zip file instead of an installer? Download it here.)

If you need more help getting started, the 60East Technologies support and services team is ready to provide the support you need to help you CRANK UP THE AMPS.

The current release of the C# client is version, which supports AMPS servers version 5.3 and earlier.