Wednesday, January 25, 2017

New Narayana release and Spring Boot quickstart

Last week we released Narayana 5.5.1.Final which is important if you’d like to use Narayana with Spring Boot. More specifically the new release contains a bug fix which resolves issues when making multiple database calls in a same transaction.

Subsequent to this release, we’ve added a new Narayana Spring Boot quickstart to our repository. It is a very much simplified stock market application where users can buy and sell shares. Every transaction executes a couple of database updates and sends a few notifications to a message queue. I’m not going to go through the code in this quickstart in depth, because most of it is pretty straightforward. However, there are a few bits which needs an explanation.

Making sure we are using Narayana


To begin with let’s go through the setup. Most of the necessary dependencies can be added by Spring Initializr:


Notice how “Narayana (JTA)” has been added to the “Selected Dependencies”.

Making sure we are using the right version of Narayana


Now, we need to make sure we’re running the latest version of Narayana. There are a number of options to do that as explained in a post on a Spring blog. But in this case, overriding version property is the easiest option:
<narayana.version>5.5.1.Final</narayana.version> 
<jboss-transaction-spi.version>7.5.0.Final</jboss-transaction-spi.version>
You can see this in the applications pom over here.

Observing the transaction demarcation


In this application, both buying and selling operations are transactional. Buy method looks like this:

And sell method looks like this:

Note on Artemis


Artemis broker is not available on Spring Initializr and to make our application self contained we would like to use an embedded broker. To do this we add the following dependency into the applications pom:
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>artemis-jms-server</artifactId>
</dependency>
Everything else is quite self explanatory. Go ahead and try it out over here.
If you have comments or feedback please do contact us over on our forum.
Post a Comment