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");
 4 
 5         try {
 6             amps.connect("tcp://192.168.0.2:9007/amps/json");
 7             amps.logon();
 8 
 9             foreach (Message msg
10                        in amps.subscribe("orders",
11                                          "/symbol LIKE 'ABCD'")
12             {
13                   Console.WriteLine(msg.Data);
14             }
15 
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");
 2 
 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.
 8 
 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);
13 
14 client.connectAndLogon();
15 
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.
20 
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"/>
5 
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;
 2 
 3       ...
 4 
 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 "doc/DeveloperGuide-C-Sharp.pdf" 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 5.2.0.2, which supports AMPS servers version 5.2 and earlier.

Documentation

HERE'S THE GOOD STUFF.

If you're ready to CRANK IT UP, here's the information you need to get started. Choose the guide you're looking for, or download a ZIP file with all of the docs.

Visit Documentation Download Documentation