Welcome back. In this video we are going to understand about what are domains and why to use domains. Firstly, let me tell about a simple requirement and discuss normally in one project in one mule project you will be having lots of dot XML files. And in each XML file you'll have you can have multiple flows. For me actually one flow is like one method. Every flow will take some data, some messages input, and we'll get some responses it Yes, method also takes an argument and has a return value.
So we can imagine like each each flow is like a method. And one XML is like a class where we group all the related methods together, is it so there is a good design principle a single responsibility principle. This says that every method should have a single responsibility. Don't write logic for two responsibilities in a single flow or single method. So try to make your flows as small as possible. Make sure that every flow will have a single responsibility and split your logic into multiple flows insert single XML and make sure that you have all the related flows in one single XML.
But if your project is so big, you might be having modules independent modules. If you write the logic for all the modules in a single project, your project is nothing but a monolithic application one single application, which contains all the functionalities we call it as a monolithic application. So, traditionally in earlier days we used to develop monolithic application and nowadays it is common to see micro service based architecture. So now the idea is don't write a single application, which contains all the modules, make sure that each and every module will be deployed independently as a single application. So, you can divide your application or project into multiple modules and for each module, you can have a separate project. Okay.
So now let's assume that in your application, you have three projects. And, and for all the projects, it is possible that there might be some global configuration which is common. Take an example in first project and second project you want to http listener listening on port 8081. That means there's a common global element which is common to all these projects. Then you duplicate such global elements in each in each and every project. Now, the good idea is, you create one project called as domain project.
And in this domain project, you configure all the global elements, which are common across these projects, and make each of the project to belong to this domain. What our projects are belonging to this domain will, like inherit the global properties. Remember, in the domain application or the domain project, don't keep common flows only global elements common global elements can be kept Again, I'm repeating don't keep common flows inside one project. One project is not for having common flows, it's only for common global elements. Okay? Now you understood the cons.
Let us see how to create a domain application and how to use it. Okay, so to create a domain application, I'll create a new layer we used to create mule project. Now it is mule domain project. So I'll select this mule, one project. And I'll give the project name as say my meal domain. I take all the defaults and finish.
So here is my mule domain project. Now, what are global elements I want to be common. I'll configure here, click on Create Let me select will there be HTTP? No. Why? Because the module is not added.
So if you want a particular module in this domain project and click on Manage module, and then add module. Again, you need to log into any points to do account and open platform accounts. I'll just login. Okay, so I'm logged in. No I will select so His GTP his DB module alert. Then I want sexual properties also.
Let me add your spelling mistake. I'll do it again. Yep, so I'll add this as well. And then I say finish. So these two modules should be added. So take some time, just pause the video I actually forgot to add a database module.
I'll add that as well as the cornered module again. And then select Search for database database connector at that's all I will finish yep it is added up and close. Now I will go to create now here I'll select HTTP listener configuration. Okay I'll take all the defaults like age rate one slash, okay, then what else later is click on database database config You're a select MySQL then I need to add the MySQL driver. I will click on configure add Maven dependency, I want my sequel a dot zero dot one file version. Finish Okay, now the host value dollar sick your colon colon DB host port is 3306 default one again, dollar secure colon colon DB dot username Ashley password dollar secure colon colon DB dot password Finally the database name is mule.
Graining live, okay. Now I need to add secure property placeholder also. But before that I will copy from my earlier project. I'll copy the DB dash secure dash dash L and I will paste it inside FFC main resources here. Okay. is a no no i'd configure secure, secure properties.
I'll type here secure properties config. The file name is BB secure. Dash demo dot yamo. And the key is a B, C, D, E, F, G, H, i, j, k l O p p, I will go to my selectorized blowfish. Okay that's all configured all the global elements are common. Then what I'll do is I'll go to this project and I do I don't need this yamo file here I will delete it and in the externalization dot YAML the same global elements are present I don't need them anymore I will have to delete all them glitch and dig okay.
But now this Pollock is showing error because it might XML if you see I was actually referencing sync to the global elements and global elements are no more present. Oh, there is a conflict if it does not present, I'll just press Ctrl J, control jet and project. Okay, so actually what now if I save these should go right now I will delete these global elements from the XML if I delete from the visual way. Contract reps also were getting related I want them but now I'll leave the global elements from XML like this. That's fine. Now there will be errors as it is big because the next cemal we're having conflict right physic question global element and global element is no more present here.
Now what I have to do is tell that this project belongs to the domain, how there are multiple ways, one of the easiest ways just right click on the project properties and select New Project. Here I can select the domain, my mule domain. And now I'll apply this and close. Yeah, once I made this project to belong to this domain, you can see here that this project is belonging to my mule domain. But still there is an error. What is that in the palm dot XML file.
Because it's saying there is multiple definition, both in application and linkage domain. Actually, once I made this product to belong to this domain, let's see what happened in the dependencies. My mule domain also is added as a dependency. In the mule, my mule domain project I have already added the MySQL jar. and here also my sequel jar is present that is a contract. So I don't need my sequel jar dependency here.
Because it is already added in my mule domain so I removed it. Now the error should be gone. Not yet. Just save it again and close it Just go to project and say clean once. Still I have an error. What is it saying?
Also complaining about secure properties HTTP and socket salts also. So what I can do is I can just go to these dependencies and I can delete all these dependencies because they're anywhere present in the domain. No, do not interrupt duplicate. Okay, I guess this one also secure configuration properties. Okay. So hopefully the errors should have gone Yes, there are no errors.
Now, let me deploy this applicant Observe the console. Oh, I got an error. What are they saying MySQL connector Java is not present. Okay, I guess I did a mistake. So in this palm dot XML, I don't think there is my SQL connector conductor, but it has you saying the shared library. Oh, I should have kept that MySQL connector dependency also in the original POM dot XML, these are the common mistakes of spam showing them so In my actual pomerode XML since I mentioned it as a shared library, I should have retained that MySQL connector jack.
So I'll have to add the dependency. Now copy this tax and add dependency and know where to add the version. version I know it is a dot zero dot one file okay. Hopefully the error might have gone. Now I'll try to deploy this project again. The project is getting deployed, I'll pause the video application got deployed successfully.
Now you can see that actually a mule mule domain also started it also got deployed and these externalization start exploiting start is deployed into this particular domain. earlier if you have observed, the projects are getting deployed onto default domain, what I did is I created my own domain and I have deployed my application to that particular domain. So like that, multiple projects can belong to one domain if there is any shared configuration global elements Any shared global elements for all the projects you can keep them inside the domain configuration level, and also realm or whatever dependencies you are adding in their domain project. You don't need to add the same dependencies in your individual products. So hope you understood why to use governments and how to use dominance. Now there's a lab you have to do after this video, he just opened his externalization document which is given to you.
And here is step four, where I have clearly given documentation about how to actually create your own domains and all this whatever I have done, go through this video and complete the exercise. See you in next video.