Skip to content

My First CRA Application

Badrish Chandramouli edited this page Jun 18, 2018 · 11 revisions

Overview

To deploy an application on Common Runtime for Applications (CRA), you need to:

  1. Create as many CRA instances as you want in your service, and give them unique names.
  2. Define vertices - this involves creating the vertices and registering them with CRA.
  3. Instantiate CRA vertices on CRA instances.

Interesting side note: Because CRA is resilient, you can perform step #1 after steps #2 and #3. The non-existent CRA instances are just assumed to be in a failed state when you deploy the vertices to them. Later, when you deploy the correctly named instances, they will automatically load the vertices (and connections) that you deployed to those instances earlier.

For this guide, we assume you have CRA instances named crainst01 and crainst02 already running, either on consoles as described here or in Kubernetes, as described here. To run the sample application, make sure you have downloaded sources and built the solution (we assume Debug mode).

Creating and deploying a vertex on each instance

We use a simple example of two instances of a vertex that simply communicates (sends and receives) a sequence of integers with another vertex. The code for such a simple vertex is present in the file src/Samples/ConnectionPair/ConnectionPairVertex.cs in the project named ConnectionPair.

Make sure that the file src/privatesettings.config has been updated with your Azure storage account key, as described here. For other applications, you may also specify the key directly using the app.config setting key AZURE_STORAGE_CONN_STRING (if you are not on .NET core), via an environment variable AZURE_STORAGE_CONN_STRING, or even more directly as a parameter to the constructor that creates a new instance of CRAClientLibrary.

If you run the project src/Samples/ConnectionPair/bin/Debug/ConnectionPair.exe it will programmatically:

  1. Register the vertex definition for ConnectionPairVertex with CRA

  2. Create two objects of this vertex type, named vertex1 and vertex2 respectively, on CRA instances crainst01 and crainst02 respectively.

  3. Establish the connections between the two vertices. Note that in our example, the connections are established from outside the vertex, i.e., from the same project that deploys the vertex. This connection could have also been made from within each vertex itself, if the application preferred this model for connection establishment.

    The relevant code snippets are below:

     client.DefineVertex("connectionpairvertex", () => new ConnectionPairVertex());
    
     client.InstantiateVertex("crainst01", "vertex1", "connectionpairvertex", null);
     client.InstantiateVertex("crainst02", "vertex2", "connectionpairvertex", null);
    
     client.Connect("vertex1", "output", "vertex2", "input");
     client.Connect("vertex2", "output", "vertex1", "input");
    

    If all goes well, you should see messages on the consoles (or in the Kubernetes output logs) corresponding to CRA instances crainst01 and crainst02 that indicate that a sequence of integers is being sent from and received by each instance, as shown below for vertex1 (running on CRA instance crainst01):

     Receiving data from vertex: vertex2, endpoint: output
     Read value: 0
     Sending data to vertex: vertex2, endpoint: input
     Written value: 0
     Read value: 1
     Written value: 1
     Read value: 2
     Written value: 2
    

Congratulations! You have a running application on top of Common Runtime for Applications (CRA).