En la publicación anterior, presentamos la tecnología Flogo como una de las cosas en la industria del desarrollo nativo en la nube y ahora vamos a construir nuestra primera aplicación Flogo e intentar cubrir todas las opciones que describimos en la publicación anterior.
NOTA .- Si eres nuevo en Flogo y no leíste la publicación anterior sobre las capacidades de Flogo, por favor tómate unos minutos para leerla antes de continuar.
TIBCO Flogo Introduction
Flogo is the next new thing in the developing applications in a cloud-native way. Since its foundation has been designed to cover all the new challenges that we need to face when dealing with new cloud-native development. So, please, if you or your enterprise is starting its movement to the cloud it’s the moment to […]
Primero que nada, me gustaría presentar el escenario, este va a ser un escenario simple que muestra de la manera más sencilla los conceptos dentro de una aplicación Flogo, así que vamos a crear una aplicación Hola Mundo que va a ser expuesta usando el protocolo HTTP/JSON para comunicarse. Así que, el escenario va a ser como la imagen mostrada a continuación:
Entonces, lo primero que necesitamos hacer es lanzar la interfaz web de Flogo, así que vamos a nuestra carpeta donde tenemos nuestra instalación de TIBCO Flogo Enterprise y ejecutamos el comando desde el directorio bin
Ahora, vamos a crear nuestra primera aplicación, así que hacemos clic en el botón “Crear” y proporcionamos un nombre para la aplicación, en nuestro caso la vamos a llamar “HelloWorldREST”
Ahora, entraremos en la página principal de una aplicación que es la que se muestra a continuación:
Es importante notar que los servicios Flogo se basan en flujos, por lo que puedes crear uno o más flujos que van a orquestar la lógica que necesitas implementar. Así que, lo primero que necesitamos hacer es crear un flujo, y lo vamos a hacer haciendo clic en el botón “Crear un flujo” y proporcionar un nombre para el flujo, en nuestro caso, como esta va a ser una aplicación simple, vamos a usar “main” como nombre del flujo que vamos a crear:
Y se te llevará al lienzo vacío de tu nuevo flujo “main”:
Hay dos conceptos importantes en un flujo Flogo:
Disparador: Esta es la forma en que este flujo va a ser iniciado, hay varias maneras de iniciar un flujo Flogo, por ejemplo, con una solicitud HTTP o un temporizador, o una fuente de eventos AWS Lambda, un tema de Kafka o un mensaje MQTT, etc. Puedes tener uno o más disparadores en tu aplicación y deberías tener uno si este es un flujo principal (en lugar de un subflujo que discutiremos en una publicación diferente). Los disparadores se muestran a la izquierda del lienzo como pequeños iconos cuadrados como puedes ver en la imagen a continuación:
Actividades: Son las que van a decidir qué lógica se va a ejecutar. Cada actividad tiene una acción que realizar que podría ser una interna como un registro de trazas o una externa como invocar un servicio REST o algo similar, y vamos a usar el resto del lienzo para construir el flujo lógico.
Entonces, lo primero que necesitamos hacer es configurar el Disparador de este flujo, y para hacer eso hacemos clic en el icono de más en el área de Disparadores y seleccionamos el disparador HTTP REST:
Y lo vamos a configurar como la imagen mostrada a continuación:
Método: GET
Ruta del recurso: /hello/{name}
Y hacemos clic en Continuar y en la siguiente ventana seleccionamos “Copiar Esquema”, para copiar el Esquema de Salida del Disparador al Esquema de Entrada del Flujo. Ahora, hemos añadido el disparador pero necesitamos configurar cómo se van a transferir los datos a las actividades del flujo. Para hacer esto, hacemos clic en la “Configuración del Disparador” porque necesitamos mapear los datos del disparador a la entrada del flujo, así que en caso de que tengamos más de un disparador podemos tener diferentes mapeos de cada uno de los disparadores a la entrada del flujo.
Ahora, vamos a la pestaña de Salida y seleccionamos “name” bajo el objeto pathParams y lo mapeamos al mismo atributo (name bajo pathParams del objeto $trigger).
Así que ahora este nombre va a ser transferido a la entrada del flujo y podemos usarlo en la lógica del flujo. Ahora es el momento de construir la lógica del flujo. En este caso va a ser muy fácil, ya que ya tenemos una actividad de retorno que se añade por defecto, solo vamos a añadir una actividad de Registro para imprimir los nombres que estamos recibiendo.
Para hacer eso hacemos clic en el botón de más en el lienzo y seleccionamos dentro de la Sección General la actividad Registrar Mensaje:
Y necesitamos configurarlo como muestra la imagen a continuación:
Así que, hacemos clic en la sección de Entrada y en este caso la actividad por defecto solo tiene un parámetro llamado “mensaje” que es el mensaje de registro que se va a imprimir, y creamos una estructura basada en la concatenación de un valor constante “Recibe solicitud con nombre: “ y el nombre que fue previamente mapeado en la configuración del disparador.
Como puedes ver, siempre tienes visibles todas las funciones que tienes disponibles agrupadas en diferentes categorías y también todos los datos de la tubería que puedes usar que están siendo generados por la ejecución de todas las actividades dentro del flujo
Así que, lo último que necesitamos hacer es configurar la actividad de retorno. Para hacer eso hacemos clic en la actividad de retorno y mapeamos los atributos código (a constante 200) y mensaje a la estructura mostrada a continuación:
Y eso es todo. Estamos listos. Así que ahora podemos comenzar a probar el servicio simple que hemos creado. Para hacer eso, Flogo Studio proporciona un Motor de Pruebas capaz de verificar que la lógica que has construido está funcionando bien. Este Motor de Pruebas va a probar la lógica del flujo, no los disparadores, así que comienza desde la primera actividad y no incluye la interacción con el disparador.
Para hacer eso solo necesitas hacer clic en el botón Iniciar Pruebas y proporcionar valores de entrada a tu flujo.
En nuestro caso, como la mayor parte de la lógica se basa en el disparador, no tiene sentido hacer ese paso, pero volveremos al Motor de Pruebas en próximas publicaciones sobre el Desarrollo Flogo. Así que, en lugar de hacer eso, vamos a construir el servicio directamente. Para hacer eso salimos del lienzo del flujo y volvemos a la página principal de la aplicación y vamos a hacer clic en el botón Construir y seleccionar la arquitectura que vas a usar para probar tu aplicación, en mi caso será Windows
Y eso va a generar un archivo ejecutable, en mi caso una aplicación EXE que tiene mi lógica que solo necesitamos ejecutar para ejecutar nuestro servicio
Así que, ahora, lo lanzamos y obtendremos una salida similar a esta:
Para probar la aplicación vamos a abrir una nueva pestaña en nuestro navegador y escribir la siguiente URL:
In the previous post, we introduce Flogo technology like one of the things in the cloud-native development industry and now we’re going to build our first Flogo Application and try to cover all the options that we describe in the previous post.
NOTE .- If you’re new to Flogo and you didn’t read the previous post about Flogo capabilities please take a few minutes to read it before continuing.
TIBCO Flogo Introduction
Flogo is the next new thing in the developing applications in a cloud-native way. Since its foundation has been designed to cover all the new challenges that we need to face when dealing with new cloud-native development. So, please, if you or your enterprise is starting its movement to the cloud it’s the moment to […]
First of all, I’d like to introduce the scenario, this is going to be a simple scenario that shows in the most simple way the concepts inside a Flogo application, so we’re going to create a Hello world application that is going to be exposed using HTTP/JSON protocol to communicate. So, the scenario is going to be like the picture shown below:
So, the first thing we need to do is to launch the Flogo Web UI, so we go to our folder where we have our TIBCO Flogo Enterprise installation and we run the command from the bin directory
./run-studio.bat
Now, we can go to the location http://localhost:8090 and we see something similar to this:
Now, we are going to create our first application so we click on the “Create” button and we’ll provide an application name, in our case we are going to call it “HelloWorldREST”
Now, we’ll enter in the main page for an application that is the one shown below:
It’s important to notice that Flogo Services are based on flows, so you can create one or more flows that are going to orchestrate the logic that you need to implement. So, the first thing we need to do is to create one flow, and we’re going to do it clicking in the button “Create a flow” and provide a name for the flow, in our case as this is going to be a simple application we’re going to use “main” as name of the flow we’re going to create:
And you’re going to be prompted to the empty canvas of your new “main” flow:
There are two important concepts in a Flogo flow:
Trigger: This is how this flow is going to be started, there are several ways to start a Flogo flow, for example with an HTTP Request or a Timer, or an AWS Lambda Event Source, a Kafka Topic or MQTT message and so on. You can have one or more triggers in your application and you should have one if this is a principal flow (instead of a subflow that we’ll discuss in a different post). Triggers are shown in the left of the canvas like little square icons as you can see in the picture below:
Activities: Are the ones that are going to decide which logic is going to be executed. Each activity has an action to be performed that could be an internal one like a Log Trace or an external one like invoking a REST Service or something similar, and we’re going to use the rest of the canvas to build the logic flow.
So, the first thing we need to do is to configure the Trigger of this flow, and to do that we click on the plus icon in the Triggers are and select the HTTP REST trigger:
And we’re going to configure it like the image shown below:
Method: GET
Resource Path: /hello/{name}
And we click Continue and in the next window we select “Copy Schema”, to copy the Trigger Output Schema to Flow Input Schema. Now, we’ve added the trigger but we need to configure how the data is going to be transferred into the flow activities. To do this, we click in the “Trigger configuration” because we need to map data from the trigger to the flow input, so in case we have more than one triggers we can have different mappings from each of the triggers to the flow input.
Now, we go to the Output tab and we select “name” under the pathParams object and we map it to the same attribute (name under pathParams from the $trigger object).
So now this name is going to be transferred to the flow input and we can use it in the flow logic. Now it’s time to build the flow logic. In this case is going to be so easy, as we already have a return activity that is added by default, we only going to add a Log activity to print the names that we’re receiving.
To do that we click on the plus button in the canvas and select inside the General Section the activity Log Message:
And we need to configure it like it shows the image below:
So, we click in the Input section and in this case the activity by default only has a parameter named “message” that is the log message that is going to be printed, and we create a structure based on the concatenation of a constant value “Receives request with name: “ and the name that was previously mapped in the trigger configuration.
As you can see you have always visible all the functions you’ve available grouped in different categories and also all the pipeline data that you can use that is being generated by the execution of all the activities inside the flow
So, the last thing we need to do is to configure the return activity. To do that we click in the return activity and map the attributes code (to constant 200) and message to the structure shown below:
And that’s all. We’re all set. So now we can start testing the simple service we’ve created. To do that Flogo Studio provides a Test Engine able to check that the logic you’ve to build is working fine. This Test engine is going to test the flow logic, not the triggers so it starts from the first activity and doesn’t include the interaction with the trigger.
To do that you only need to click in the Start Testing button and provides input values to your flow.
In our case, as most of the logic is based on the trigger makes no sense to do that step, but we’ll come back to the Test Engine in upcoming posts about Flogo Development. So, instead of doing that we’re going to build the service directly. To do that we exit the flow canvas and come back to the application main page and we’re going to click on the Build button and select the architecture that you’ll be using to test your application, in my case this will be windows
And that’s going to generate an executable file, in my case EXE application that has my logic that we only need to execute it to run our service
So, now, we launch it and we’ll get an output similar to this:
To test the application we’re going to open a new tab in our browser and type the following URL: