Friday, 17 March 2017
Dear Infinispan community,
as announced in a previous post, starting from version 8.1.0 also the C++/C# clients can receive and process Infinispan events.
Here’s an example of usage of C++ event listeners that, with a good dose of imagination, pretends to be a customer behavior tracking system for our store chain (don’t take this too seriously, we’re just trying to add some fiction).
As a first requirement our tracking system will record every single purchase made in our stores. How many stores we have? 1, 100, millions? It doesn’t matter: we’re backed with an Infinispan data grid. This is version 0.x and hence the checker must use the keyboard to enter all the needed information.
As you can see our entry key is a concatenation of the product name and the timestamp and the entry value is an unstructured string, maybe too simply but it could work for now. Seems we are at a good point: we have the data and we can do analytics on it, so far so good but now our boss makes a new request: he wants a runtime monitor on how’s the sales performance. That’s a perfect request to be fulfilled with event listener: the monitor application will be an Hotrod C++ client that registers a client listener on the server and receives and show on the boss’s laptop the data flow. A client listener, once registered on the server, can receive events related to: creation, modification, deletion, expiration of cache entries; in our example only the creation and expiration events are processed (expired events can be useful to do some moving average statistics?). Following a snip of code that creates and registers a listener that writes the events key on the stdout.
You can git this quickstart here . On startup a multiple choice menu is shown with all the available operations. Running several instances you can act as the checker (data entry) or the boss (installing the listener and seeing the events flow).
Again so far so good, but then the marketing department ask support to do targeted advertising like: soliciting customers that bought product Y to buy product X. Let’s suppose that X="harmonica" and Y="hiking boots" (it’s a well known fact of life that in the high mountains you feel the desire to play an harmonica).
To do that we register on the server another listener, but this time we’re not interested in the whole flow of purchase data: to run our marketing campaign, we only interested in cache entries having the key starting with "hiking". The Infinispan server can filter out events for us, if we pass in the AddClientListener operation the name of the wanted filter along with any configuration arguments.
Filter are java classes that must be deployed into the Infinispan server (more here )
Predefined events contain very few information: basically the event type and the entry key, this to prevent to flood the network spreading around very long entry values. Users can override this limitation using a converter, that is a java class deployed into the server, that can create custom events containing every data needed by the application.
As in the previous case, we pass into the add operation the name of the converter and the configuration arguments, any.
Thanks for reading and enjoy! The Infinispan Team
Tags: c++ example quick start remote events
Monday, 13 January 2014
Following up on the previous post on Infinispan remote queries, we’ve prepared a quick start guide to get you up and running with remote queries in minutes.
It’s a simple Java application that places some data in a remote cache and then retrieves it using queries over Hot Rod. On top of that, the project also contains a C companion app contributed by https://github.com/isavin[Ion Savin] that uses the https://github.com/infinispan/cpp-client/[C Hot Rod client] and is able to read and write (but not query, yet) the same data, demonstrating interoperability between C and Java clients. At this point the Protobuf encoding support comes in a few C external helper classes rather than being part of the C++ client, but this is going to improve in the upcoming versions. The code for this app is hosted on Github under the jboss-jdg-quickstarts project. Please note this tutorial was written for the JBoss Data Grid (JDG), but it applies to Infinispan as well. We welcome you to try it and let us know what you think!
Tags: jdg hotrod quick start cpp-client remote query