Crank It Up!¶
To get started with AMPS, create a simple subscriber and publisher:
- Open the AMPS C# samples in Visual Studio
- Navigate to the directory where you unzipped the C# client
- Navigate to the
samples
directory - Open the CrankItUp solution
- Add the reference to the AMPS C# client
- Update the connection strings to connect to AMPS
- In Visual Studio, choose Edit > Find and Replace > Replace in Files (or type Ctrl-Shift-H)
- Click on Replace in Files
- In the Find What text box, enter
127.0.0.1
- In the Replace With text box, enter the IP address of the virtual machine (provided when the machine boots and when you log in to the virtual machine)
- Run the sample subscriber
- In the solution view, right click on
01-AMPSConsoleSubscriber
. Select Debug > Start new instance. - The program starts in a console window.
- Choose Debug > Detach all. You can start as many subscribers as you like this way.
- In the solution view, right click on
- Run the sample publisher
- In the solution view, right click on
02-AMPSConsolePublisher
. Select Debug > Start new instance. - The program runs, and subscribers receive the
Hello, World
message. The subscriber itself produces no output if it is successful.
- In the solution view, right click on
One of the most useful parts of AMPS is being able to keep track of the current value of a message, using the state of the world (SOW) database:
- Retrieve the state of the world
- In the solution view, right click on
04-AMPSSOWConsoleSubscriber
. Select Debug > Start new instance. - The program runs. This program queries the state of the world for the
messages-sow
topic, filtered to messages with a messageNumber less than 10. The console output shows the results of the query. Notice that for message 5, the database shows the latest value – the current state of the world.
- In the solution view, right click on
- Retrieve the state of the world and subscribe to updates.
- In the solution view, right click on
05-AMPSSOWandSubscribeConsoleSubscriber
. Select Debug > Start new instance. - The program runs. This program queries the state of the world for the
messages-sow
topic, filtered to messages with a messageNumber less than 10. The console output shows the results of the query. Notice that for message 5, the database shows the latest value – the current state of the world. Rather than ending, the program continues to run. AMPS will send the program any new messages that match the filter. - Choose Debug > Detach all.
- In the solution view, right click on
03-AMPSSOWConsolePublisher
. Select Debug > Start new instance. - The publisher sends another 100 messages to AMPS, updating the value of each message, then updates message 5 again. Notice that AMPS sends each update to the subscriber, meaning that the subscriber receives two updates to message 5. When subscribed, the subscriber always receives the most current information.
- In the solution view, right click on
Detecting when messages go out of focus¶
One of the difficulties in conventional messaging systems and databases is being notified when an item no longer matches your query. For example, you may want to keep a list of all of the orders which are not yet fulfilled, or all of the taxis that are available to pick up passengers. In a traditional system, you detect change by running the query again and comparing the new results to the previous results.
With AMPS, you can ask to be notified when a message no longer matches the query. AMPS delivers the notification as a special kind of message – an Out of Focus message.
- Retrieve the state of the world and request Out of Focus notifications.
- In the solution view, right click on
07-AMPSSOWandSubscribeWithOOF
. Select Debug > Start new instance. - The program runs. This program queries the state of the world for the
messages-sow topic
, filtered to messages with a messageNumber is a multiple of 10, and where an optional field is either not present or set to a value other than ‘ignore_me’. The console output shows the results of the query. - Choose Debug > Detach all.
- In the solution view, right click on
06-AMPSSOWUpdateForOOF
. Select Debug > Start new instance. - The program runs. This program does the following work:
- Sends a message with an expiration time. The subscriber receives the message.
- Sends a message that it will later delete. The subscriber receives the message.
- Sends a set of messages that match the filter. The subscriber receives these messages.
- Sends updates to a set of messages that cause them to no longer match the filter. The subscriber receives Out Of Focus messages. Notice that these messages include the information that the filter no longer matches.
- Deletes the message that it sent earlier. The subscriber receives an Out of Focus message saying that the message was deleted.
- In the solution view, right click on
The program waits to help ensure that all messages have been published, then exits. The message with the expiration time set will expire, and the subscriber will receive an Out of Focus message saying that the message expired.
Go beyond¶
The sample directory contains a number of sample programs, including programs that demonstrate publishing to and consuming from AMPS queues, programs that work with composite messages, and more.
You call the tune¶
Now that you’ve seen the samples run, it’s time for you to play with the samples. Modify them. Step through them in a debugger to see how they work.