The IBM Stock Trader application is a simple stock trading sample, where you can create various stock portfolios and add shares of stock to each for a commission.
Introduction to the IBM Stock Trader sample
The IBM Stock Trader application is a simple stock trading sample, where you can create various stock portfolios and add shares of stock to each for a commission. It keeps track of each portfolio’s total value and its loyalty level, notifying you of changes in level, which affect the commission charged per transaction. It also lets you submit feedback on the application, which can result in earning free (zero commission) trades, based on the tone of the feedback. (Tone is determined by calling the Watson Tone Analyzer, which will be covered in a future article).
The sample is intended to showcase what one might expect after performing a lift-and-shift of a traditional monolithic, on-premises application to one that has been refactored as Docker(container)-based microservices running within a modern Kubernetes-based environment. It deliberately shows off how to use the traditional Java EE programming models, such as JDBC and JMS, to access traditional system-of-record resources, such as a relational database or a message queueing infrastructure. Note that while the application usually uses IBM Db2 and MQ, it also works great with open source technologies, like Apache Derby as the relational database, and with the JMS server built into Open Liberty, an open-source cloud-native Java runtime.
The concept demonstrates how to run a microservices-based application in a Kubernetes environment. Initially tested in a MiniKube, the application is generally deployed to a Kubernetesplatform in public clouds like IBM Cloud Kubernetes Service or as hybrid cloud deployment atop Red Hat OpenShift Container Platform. This sample demonstrates usage of various IBM middleware products, such as Db2, MQ, and ODM, each of which are deployed with their Helm charts containers to Kubernetes, called from Java-based micro-services running atop Open Liberty.
All of the source code is publicly available in GitHub. There are eight repositories underneath the IBMStockTrader org, each of which represents a separate microservice that delivers a specific capability. For example, the /stock-quote repository, provides the functionality of looking up the price of a given stock and takes care of caching such values in Redis for a configurable period of time.
The built versions of each of these repositories are available in public DockerHub. For example, to work with the stock-quote microservice, you would need access to ibmstocktrader/stock-quote, or you would pull it down to your Docker register using
docker pull ibmstocktrader/stock-quote.
Whether you prefer to clone the source code from GitHub and build each microservice yourself, or just use the pre-built images in DockerHub, you can easily get this sample up and running in your own Kubernetes environment.
As stated earlier, this sample has been factored into a set of microservices that work together to deliver the overall application. The following diagram shows the interactions between these microservices:
As you can see, the portfolio microservice sits at the center of the application, serving as the controller in a standard Model View Controller (MVC) architecture, accessed by a choice of clients that provide the view. This microservice takes care of persistence using JDBC, messaging using JMS, and makes REST calls to get stock quotes or to drive a business rule in IBM Operational Decision Manager (ODM); plus, it drives Watson and invokes APIs in API Connect in the public IBM Cloud. There is also one old-fashioned Enterprise Java Bean (EJB) — specifically a Message Driven Bean (MDB), which listens for the messages sent from portfolio, and which invokes a notification service. Using an Istio routing rule that can be specified per portfolio, it sends its notification either to a Slack channel (using a “serverless” IBM Cloud Functions action sequence) or as a tweet to the @IBMStockTrader Twitter account.
Though all of the back-end microservices in this sample are written in Java, we enter the world of polyglot programming when it comes to which user interface you choose. One is written in Java, and the other in Node.js/Vue.js. Both call the exact same REST services from the portfolio microservice, but each renders the results in a different way in the web browser.
Check it out on GitHub
Learn about IBM StockTrader on Git Hub and contribute to its code.
Learn more about the open-source cloud-native Java runtime, Open Liberty
- 6 reasons why Open Liberty is an ideal choice for developing and deploying microservices
- Choosing the right Java runtime for the job
Get hands-on learning and building with the APIs and technologies mentioned in the article using one of the Open Liberty guides:
- Getting started with Open Liberty
- Creating a RESTful microservice (using Jakarta REST or JAX-RS)
- Invoking REST services from Java, using the MicroProfile REST Client feature
- Security using JSON Web Tokens (JWT)
- Learn about health checks, using the MicroProfile Heath feature, and wiring those up to Kubernetes so it can restart an unhealthy microservice:
– Adding health reports to microservices
– Checking the health of microservices on Kubernetes
- Learn about externalizing configuration parameters using Kubernetes config maps and secrets, and accessing those with the MicroProfile Config feature in Configuring microservices running in Kubernetes
- Learn about tracking usage metrics with the MicroProfile Metrics feature in Providing metrics from a microservice
- Learn about using Istio to manage traffic and control routing to different versions of a service in Managing microservice traffic using Istio
– Consuming a RESTful web service with ReactJS
– Consuming a RESTful web service with Angular
MicroProfile and Jakarta EE
See what MicroProfile and Jakarta EE offer in terms of open cloud-native Java APIs for Java developers.