AMPS (Advanced Message Processing System)

Table of contents
Reading Time: 3 minutes

Hi readers, in this blog, I will talk about what are AMPS, how it works, and then finally will talk about how to run it with a working example.

So let’s get started…!!

What are AMPS(Advanced Message Processing System)?

AMPS from 60East Technologies is a fast messaging engine that supports both publish-subscribe messaging and queuing. It is not just a simple messaging engine it is also packed with some powerful feature like high availability, historical replay, aggregation and analytics, content filtering and continuous query, last value caching, focus tracking, and more.

Let me highlight some important features of AMPS that make it different from other messaging systems:

  1. Topic and content-based publish and subscribe
  2. Client development kits for popular programming languages such as Java, C#, C++, C and Python
  3. Built-in support for FIX, NVFIX, JSON, BSON, BFlat, Google Protocol Buffer, and XML messages. AMPS also supports uninterpreted binary messages and allows you to create composite message types from existing message types.
  4. State-of-the-World queries
  5. Replication for high availability
  6. Message replay functionality

I will talk about these features in detailed in my upcoming blogs.

AMPS PUB-SUB Model

PubSub

This is same as any other pub-sub model wherein a publisher publishes the message to a topic and subscriber subscribes to a topic and reads the message from it. But amps also provide some powerfully features like we can do content filtering where we can subscribe to a topic with a filter and with the help of that we can get only the filtered messages from AMPS server.

AMPS Cluster Model

When we compare with Kafka the AMPS model is little different. In AMPS, when we publish a message, the message goes to any of the available instances, not like Kafka where the message goes to the elected leader.

In an asynchronous communication, we get the acknowledgment soon after the message is published to one of the instances but the message is replicated between the instance in a synchronous manner.

AMPS Cluster Model

When we have a cluster across different data centers the message is replicated to different instance within a data center is synchronous but for different data centers, the messages are replicated asynchronously.

Installing AMPS

Note: AMPS currently provide support to Linux 64-bit (2.6 kernel or later) on x86 compatible processors

Pre-requisite

  • Java Development Kit version 1.7 or greater.
  • Java Runtime Environment version 1.7 or greater.
  • scala
  • optional Apache Ant version 1.8 or greater.

Download AMPS

You can download AMPS from here

Obtaining a Client

AMPS provide pre-compiled jars that we need to download and add it to in project so that we can start working with amps. You can download the jar from the AMPS official website. The pre-compiled JAR files will be located in the /dist/lib/ directory.

Starting AMPS

To run amps server we first create a configuration file for our server and run it with this file. Let’s take AMPSDIR is the directory location of amps on our local. So we first run the following command:

$AMPSDIR/bin/ampServer --sample-config > $AMPSDIR/amps_config.xml

This will create an amps_config.xml file and after that, we will run our amps server:

$AMPSDIR/bin/ampServer $AMPSDIR/amps_config.xml

This will start up the amps server.

Now let’s understand how to create a publisher and a subscriber.

AMPS Publisher and Subscriber Example

To publish and subscribe to a topic first we need to create and open a Client connection.

AMPS Publisher



This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters


import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
object Publisher extends App {
val client = new Client("MyClient")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")
client.logon()
client.publish("messages", "{ \"message\" : \"Hello, world!\" } ")
} catch {
case ampsException: AMPSException => println(s"Caught exception: ${ampsException.getMessage}")
}
}
view raw

AMPS Publisher

hosted with ❤ by GitHub

AMPS Subscriber



This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters


import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
import scala.collection.JavaConverters._
object Subscriber extends App {
val client = new Client("subscribe")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")
client.logon()
val messageStream = client.subscribe("messages").iterator().asScala
messageStream.foreach(message => println(message.getData))
} catch {
case ampsException: AMPSException => println(s"Caught exception: ${ampsException.getMessage}")
}
}
view raw

AMPS Subscriber

hosted with ❤ by GitHub

We can create a client using Client class or a HAClient class which extends Client class and provides additional functionality like, it provides high availability as it allows applications to automatically:

  • Recover from temporary disconnects between client and server.
  • Failover from one server to another when a server becomes unavailable.

HAClient should be used for production as it handles failure-overs automatically. You can get the code on amps using HAClient on my GitHub repository.

Reference:

crankuptheamps


Knoldus-Scala-spark-services-company

Written by 

I am a Software Consultant at Knoldus Inc. I am a Scala Enthusiast. I am familiar with Object Oriented Programming Paradigms, and has also worked upon .NET based technologies. Aside from being a programmer, I am familiar with NoSQL database technologies such like Cassandra. I also worked on Lagom microservice architecture.

1 thought on “AMPS (Advanced Message Processing System)3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading