Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

The Complete Reappt on Bluemix - Taxi Demo

DZone's Guide to

The Complete Reappt on Bluemix - Taxi Demo

Want to learn how to use Reappt and Bluemix together? We got you covered. Check out this demo of a system designed for taxis to ''bid'' on passengers, and pick up some new practical skills.

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

Reappt and Bluemix allow you to deploy new web applications that take advantage of enterprise-grade messaging features in minutes. First, you need to write your application.

Bluemix

Bluemix is a platform as a service offering that hosts the code you write. It supports lots of different runtime environments including Node and Java. You can deploy applications to it with only a handful of commands. It provides lots of different services that can be integrated into your code and Reappt is one of them.

Bluemix divides everything into applications and services. Applications are the code you write and deploy to Bluemix. Services are third-party offerings that can be connected to your applications to access functionality like persistence or messaging.

Reappt

Reappt is a real-time messaging platform. It’s our DiffusionTM product made available as a service. It streams data for up to 25,000 concurrent clients. There are SDKs available for many common web, mobile, and server languages, allowing you to develop for a broad range of devices.

Reappt is available in the US South region of Bluemix. It is also available on IBM Cloud Marketplace and you can always license a Diffusion server on premise.

Taxi Demo

We have written a demo that you can deploy and run on Bluemix yourself. The demo models a small town, passengers, and taxis. When a passenger appears, taxis can bid on the chance to give them a ride. The winning taxi collects and delivers the passenger and gets paid the fee.

The demo consists of any number of front-end clients and a single controlling, backend client, all connecting to the same Reappt service.

The front-end is a browser client implemented using ClojureScript on top of the JavaScript API. The client lets you create taxis and passengers and shows you the state of the world. The ClojureScript and HTML need to be served to the browser as static content. This means the application you deploy to Bluemix will be a server for the frontend client. The build process will use a plugin for Ring to package the application as a WAR file. Bluemix will detect the WAR file and automatically run it with IBM WebSphere Liberty Profile.

The backend client is a Clojure application running as an executable JAR. This application will run on Bluemix as a Java process. It runs the auctions and handles the bidding from taxis.

The backend client makes a secure connection to Reappt but the Java runtime provides a much smaller set of trusted certificates than a browser does. The certificate chain for Reappt has been exported to the reapptTruststore.jks file to allow it authenticate the TLS connection. The client loads the truststore and uses it to create the SSLContext used by the connection.

The demo code is available on GitHub and is still being developed. Clone the repository to your local machine so that you can build and deploy the applications.

git clone https://github.com/pushtechnology/taxi-demo.git

There are two directories at the top level one for the backend and frontend.

Accessing Reappt through Bluemix

To start you will need to set up Bluemix with a Reappt service instance.

Start by signing up to Bluemix. Bluemix uses IBM’s single sign-on system, IBM ID, to log in.

Once you have logged into Bluemix, select the US South region and set up a space. A space is a scope that can be shared by multiple applications and services. You can call your space whatever you like.

Find Reappt in the Bluemix catalog and add the Reappt service to your space. You can give the service any name you want to. For this blog post, I’ll assume the service is called taxi-reappt. You can only have one instance of a service in a space. Once Reappt has been added, you will be presented with a link to the Reappt dashboard. From the Reappt dashboard, you will be able to manage the credentials your clients to connect with, monitor your usage of Reappt and view the service log files.

A Reappt service does not start with any credentials that a session can use to connect. Credentials can either be setup through the Reappt dashboard or by binding the service to an application. The System Users in the dashboard represent the system authentication store, this store is used to authenticate sessions without calling out to external services. Binding an application to the service creates an entry in the System Users and makes the credentials visible to the application through the VCAP_SERVICES environmental variable. Changing the User name in System Users will break the binding but you can modify the roles however you want. The default roles of a user created by binding are CLIENT, CLIENT_CONTROL and TOPIC_CONTROL, suitable for most backend clients. Binding provides an easy way to link Bluemix applications to services.

Applications with bound services have a VCAP_SERVICES environmental variable set. This variable contains a JSON object. The object contains keys of service providers to arrays of service instances, Reappt uses the key push-reappt. The variable will contain something like:

{
   "push-reappt": [
      {
         "name": "taxi-reappt",
         "label": "push-reappt",
         "plan": "free",
         "credentials": {
            "host": "burningwideTycho.us.reappt.io",
            "principal": "service-binding-E5e1T9B8xYf4tLch",
            "credentials": "Iuee4Um4A06Kr2nO"
         }
      }
   ]
}

You now have a Reappt endpoint to target from your application. The host is listed in the VCAP_SERVICES and is displayed on the dashboard under the Reappt Service Details. It should be something like burningwideTycho.us.reappt.io.

Deploying to Bluemix

To deploy to Bluemix you should first install the CloudFoundry tools. You can use these command line tools to manage Bluemix.

Log into the Bluemix API endpoint with your IBM ID using cf and select the space that the Reappt service is in:

cf login -a https://api.ng.bluemix.net -s yourspace

If you have forgotten the name of your space you can login without specifying a space and the available spaces will be listed and you be prompted to select one.

The manifest.yml file describes the code to push, how to set up the requirements of the application and the routing to it.

Bluemix requires a unique subdomain to host the client on so you will need to change the host property of the frontend manifest.yml file to something unique to you. Once you get past the prototyping and demo phase you can set your application to use a custom domain name instead of mybluemix.net. The backend manifest file sets the no‑route property to true, this stops Bluemix trying to perform a network based health check on the application. It also sets the services property to include the name of the Reappt service, this binds the application to the service when it is deployed.

applications:
- name: taxi
  memory: 384M
  disk_quota: 256M
  path: target/taxi-0.1.0-SNAPSHOT-standalone.war
  host: yourhost
  domain: mybluemix.net
  timeout: 60
  services:
    - taxi-reappt

The demo has been implemented with Clojure and ClojureScript so you will need to have Leiningen installed to build it.

Both the front- and backend projects have had an alias added to project.clj that builds a deployable application. Use the alias to build the applications and then use the manifest files to deploy the applications to Bluemix. Run:

lein release-build && cf push -f manifest.yml

... for both projects.

This will build and deploy either the JAR or the WAR file containing all the dependencies to Bluemix and configure the application according to the manifest. The cf push command uploads the application to Bluemix. If you use Maven for your own projects you can use the CloudFoundry Maven Plugin to make this an automated step in your build process.

IBM Bluemix will detect the type of application pushed to it and select an appropriate runtime. If it fails to detect the right runtime or you want to use something not supported by IBM you can specify a buildpack. Buildpacks provide the runtime and any frameworks needed to run your application. To run your web applications in Tomcat instead of WebSphere you can specify the java_buildpack in the manifest, deploy as a new application and Bluemix will use the buildpack to setup Tomcat and deploy your war file to it.

Earlier I mentioned that the backend makes a secure connection to the Reappt server and uses an SSLContext to configure the trusted certificates. The buildpack used by Bluemix to run Java applications uses IBM’s J9 Java Virtual Machine. There are minor differences in how to configure TLS between different JVM implementations. For simplicity and portability the SSLContext is configured in a way that works for both HotSpot and OpenJDK. The manifest file uses the environmental variable JVM to request that the buildpack uses the OpenJDK instead of J9.

Once the buildpack has been applied a droplet will be created. The droplet is an image that can be stored and deployed to a container. The Warden containers that Bluemix uses for CloudFoundry applications provides isolation and resource control.

When you push an application, once the droplet has been created, Bluemix will deploy to a container and start the application. Bluemix supports horizontal scaling of the application by creating multiple instances of it. When you scale up the application the droplet will be deployed to additional containers. You can scale an application in Bluemix using either the Bluemix console to change the number of instances or cf scale from the command line. Connections will be load balanced across multiple instances of an application.

On Bluemix

In the Bluemix console you can see the state of the applications you have deployed. They should be running. Open ‘yourhost’.mybluemix.net in your browser and the demo should load. Try adding passengers, taxis, and see how Reappt and Bluemix work together. Hopefully, you’re getting excited about Reappt and Bluemix now too.

Want to see how easy it is to get started with Reappt? Sign up for a free demo here.

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:
bluemix ,mobile

Published at DZone with permission of Matt Champion, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}