Flow Manager
In this video:
00:00:00 Hi everyone and welcome to the Mia-Platform tutorials! Today we're going to be taking a look at Flow Managers. In this tutorial we will see how to create and expose a Flow Manager service.
00:00:12 The Flow Manager is a Saga Orchestrator capable of managing flows, structured by leveraging the architectural pattern named Saga pattern using the command-and orchestration-approach. Since this can help you govern the interaction to complete various tasks and to guard data consistency, Flow Manager can simplify your work when you want to model complex flows involving the interaction of several services.
00:00:39 To begin with, we begin in the design section of the Mia-Platform Console. We go ahead and click on "Create a microservice" from the marketplace over here. We look for the Flow Manager option - here you can see that we have a core plugin called Flow Manager service. Let's go ahead and give that a name. The given name by default is "Flow Manager Service". This is a Saga Orchestrator capable of managing flows structured by using the architectural pattern named The Saga pattern. Let's go ahead and create that. Here you can see all of the configurations of this microservice.
00:01:15 Now, we're going to go ahead into the new section called "The View Flow Manager" section. This is where you can see this on a canvas. To begin with you can see the start, the creation event and the states. Let's go ahead and link a microservice first. Perfect, your microservice is now linked. We're goingto use the example of a Payment Orchestrator.
00:01:38 So there's a creation event after start, and then you move into the first state. We don't want this to be the final state, we're going to add some more states to this example, so let's go ahead and click on "Add State". This will be our next state, and let's go ahead and add another state - this will be our third state. Now let's go ahead and change the configurations. So let's go ahead to this event, on the right hand side, you can change the name of the event. So for this example we're going to use the the example of payment. So let's go ahead and put it as "Payment-begins". This is an e-commerce example of any e-commerce platform where you're going to try to make a payment.
00:02:19 Perfect, now that we're happy with that we're in the first state. Now you can see that the first state - we're going to go ahead and change it to "Not-final", and we're going to rename this state "Payment-initiated". Perfect, that's our first state. Now we have two possible options: one is that the payment takes place properly and the second one is that the payment fails.
00:02:46 So let's go ahead and create a connection to our next state. This would be in the category of the payment taking place successfully, so this would be "Payment-successful". Here you can select the group. For this let's just go ahead and select the same group, "Group 0", and you can see that this is going to be a final state, so let's go ahead and click on "Is final". Perfect, once we're happy with that we'll go ahead and look at our next state. This would be in the example of the payment failing, so let's go ahead and rename that to "Payment-failed". For this let's not select "Group 0", let's make a new group. Let's go ahead and click on "New state group", here you can see you can name the group "Payment-failed". This will be in the color red just to display that the payment is failed, and click on "Save". Now you can see the payment is failed and this is a separate state. Let's go ahead and connect this as well.
00:03:56 Perfect, let's go ahead and we've connected these. Now you can see there is an event between these two states. Let's click on the event so we can see all of the properties.
00:04:06 Here we see the name, the group, the source state is "Payment-initiated", the target state is "Payment-successful". For this, let's name it as "Successful-payment". That would be the event taking place before we get to that state. For this one, let's go ahead and put "Unsuccessful-payment". This would display that the event that's necessary to take place before we reach the payment fail state is an unsuccessful payment. What we can also do is make sure that this one is a final state as well. As you can see here, we have created a very basic chart in which you can see all of the states and all of the steps and events you have to go through to reach the final state. Here you can also see the type of communication, so there are commands, protocols, hooks and side effects.
00:05:03 Let's go ahead and set up a command for "Group 0 - Payment-initiated". As you can see here there are no available commands, so we're going to create a new command. Let's go ahead and click on "New command". Here you can see that you can insert a label or a name for your command, so let's go ahead and give it the name "Payment-orchestrated". You can enter any description that you would like and then click on "Next". Here you can see you have the option to enable hooks: if you turn this on, you can either use an existing hook from a layer of drop down or you can go ahead and click on "Set custom hooks", where you can set your custom hooks. For this example I choose not to enable hooks.
00:05:44 Let's go ahead and click on "Next" and then we enter the communication protocol. Again, you can use an existing protocol appearing in this drop-down menu if you have any, or create a new protocol. I'm going to go ahead and create a new protocol and name it "Payments".
00:06:00 You can choose between Kafka and Rest. For this example I'm just going to use Rest. Here you can see that your protocol type can be HTTP or HTTPS. You can enter an endpoint. For this example I'm going to enter the endpoint "Result". You can enter a path, you can enter a port and a method, which can either be post, put or patch. Once you're happy with this, et's go ahead and click on "Save". Perfect, you have now initiated a command which is called "Payment-orchestration". As you can see here in the final display that this is your start state, your payment has begun, it has been initiated and the command "Payment-orchestrated" is being run. There are two events that could take place: one is a successful payment, which would take you to "Payment-successful", a final state; and you can also have unsuccessful payment which would take you to "Payment-failed" which is also a final state.
00:06:56 This is how you can use the Flow Manager service on the Mia-Platform Console. As always, if you have any questions feel free to reach out to us via email or book a demo call with us. Thank you so much for watching!