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:
| using AMPS.Client;
...
Client amps = new Client("myapplication");
try {
amps.connect("tcp://192.168.0.2:9007/amps/json");
amps.logon();
foreach (Message msg
in amps.subscribe("orders",
"/symbol LIKE 'ABCD'")
{
Console.WriteLine(msg.Data);
}
} catch (AMPSException exception) {
Console.WriteLine(exception);
}
|
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.
| HAClient client = new HAClient("reconnectingSubscriber");
// The ServerChooser interface tells the HAClient which server
// to connect to, both for the initial connection and failover.
// The DefaultServerChooser is included with the client: many
// applications implement a ServerChooser to control failover
// behavior.
DefaultServerChooser sc = new DefaultServerChooser();
sc.add("tcp://amps-server:9007/amps/json");
sc.add("tcp://amps-failover-server:9007/amps/json");
client.setServerChooser(sc);
client.connectAndLogon();
// Enter subscriptions. If the connection to the server
// is lost, the HAClient will restore the connection to
// the server or the failover partner, and restore
// subscriptions.
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:
| <amps:Server x:Key="localhost" Hostname="localhost"
Port="9007" MessageType="json"/>
<amps:Subscription Server="{StaticResource localhost}"
x:Key="orders" Topic="orders"/>
<StackPanel DataContext="{StaticResource orders}">
<DataGrid ItemsSource="{Binding Data}"
AutoGenerateColumns="true"/>
</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.
| using AMPS.Client;
...
void QuerySOW(Client client)
{
foreach (Message message in amps.sow("orders",
"/symbol = 'ROL'))
{
if (message.Command = "sow")
{
Console.WriteLine(message.Data);
}
}
}
|
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.