Mule Basics Part 2

Mule 4 Indepth Mule Basics
24 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.39
List Price:  €93.41
You save:  €28.02
£55.92
List Price:  £79.90
You save:  £23.97
CA$96.01
List Price:  CA$137.16
You save:  CA$41.15
A$107.15
List Price:  A$153.08
You save:  A$45.93
S$95.13
List Price:  S$135.90
You save:  S$40.77
HK$547.14
List Price:  HK$781.66
You save:  HK$234.52
CHF 63.86
List Price:  CHF 91.23
You save:  CHF 27.37
NOK kr775.40
List Price:  NOK kr1,107.76
You save:  NOK kr332.36
DKK kr487.78
List Price:  DKK kr696.86
You save:  DKK kr209.07
NZ$118.01
List Price:  NZ$168.60
You save:  NZ$50.58
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,680.49
List Price:  ৳10,972.60
You save:  ৳3,292.11
₹5,842.03
List Price:  ₹8,346.11
You save:  ₹2,504.08
RM332.86
List Price:  RM475.54
You save:  RM142.67
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,491.96
List Price:  ₨27,846.85
You save:  ₨8,354.89
฿2,586.09
List Price:  ฿3,694.58
You save:  ฿1,108.48
₺2,265.39
List Price:  ₺3,236.41
You save:  ₺971.02
B$363.53
List Price:  B$519.35
You save:  B$155.82
R1,302.64
List Price:  R1,861
You save:  R558.35
Лв127.90
List Price:  Лв182.73
You save:  Лв54.82
₩96,270.48
List Price:  ₩137,535.16
You save:  ₩41,264.67
₪262.29
List Price:  ₪374.71
You save:  ₪112.42
₱4,033.94
List Price:  ₱5,763.02
You save:  ₱1,729.07
¥10,867.12
List Price:  ¥15,525.12
You save:  ¥4,658
MX$1,187.12
List Price:  MX$1,695.96
You save:  MX$508.84
QR254.93
List Price:  QR364.20
You save:  QR109.27
P994.08
List Price:  P1,420.18
You save:  P426.09
KSh9,360.69
List Price:  KSh13,372.99
You save:  KSh4,012.30
E£3,358.63
List Price:  E£4,798.26
You save:  E£1,439.62
ብር4,003.77
List Price:  ብር5,719.92
You save:  ብር1,716.15
Kz58,546.63
List Price:  Kz83,641.63
You save:  Kz25,095
CLP$67,216.99
List Price:  CLP$96,028.39
You save:  CLP$28,811.40
CN¥506.70
List Price:  CN¥723.89
You save:  CN¥217.19
RD$4,073.53
List Price:  RD$5,819.58
You save:  RD$1,746.04
DA9,418.34
List Price:  DA13,455.35
You save:  DA4,037.01
FJ$158.31
List Price:  FJ$226.17
You save:  FJ$67.86
Q543.96
List Price:  Q777.12
You save:  Q233.16
GY$14,650.29
List Price:  GY$20,929.88
You save:  GY$6,279.59
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.71
List Price:  DH1,011.06
You save:  DH303.35
L1,237.78
List Price:  L1,768.33
You save:  L530.55
ден4,025.24
List Price:  ден5,750.59
You save:  ден1,725.35
MOP$563.96
List Price:  MOP$805.69
You save:  MOP$241.73
N$1,304.33
List Price:  N$1,863.42
You save:  N$559.08
C$2,570.38
List Price:  C$3,672.13
You save:  C$1,101.75
रु9,397.27
List Price:  रु13,425.24
You save:  रु4,027.97
S/263.43
List Price:  S/376.35
You save:  S/112.91
K270.11
List Price:  K385.89
You save:  K115.77
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,873.89
List Price:  ZK2,677.10
You save:  ZK803.21
L325.37
List Price:  L464.84
You save:  L139.46
Kč1,643.47
List Price:  Kč2,347.91
You save:  Kč704.44
Ft25,458.03
List Price:  Ft36,370.18
You save:  Ft10,912.14
SEK kr764.90
List Price:  SEK kr1,092.76
You save:  SEK kr327.86
ARS$61,327.27
List Price:  ARS$87,614.14
You save:  ARS$26,286.87
Bs483.57
List Price:  Bs690.85
You save:  Bs207.27
COP$273,218.78
List Price:  COP$390,329.27
You save:  COP$117,110.49
₡35,710.66
List Price:  ₡51,017.42
You save:  ₡15,306.75
L1,733.65
List Price:  L2,476.75
You save:  L743.09
₲524,442.73
List Price:  ₲749,236.02
You save:  ₲224,793.28
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł283.24
List Price:  zł404.64
You save:  zł121.40
Already have an account? Log In

Transcript

Welcome back. We'll continue from the point where I left in the last video, we created a basic flow with one HTTP listener, set builder, transformer and logger. And I told you that whenever you're writing a log message, if a switch to expression mode I have the right data view expression. So, by rating this such data view expression, we are extracting the data from the payload from the message payload. As I told you, this expression will be evaluated. It will be evaluated to first of all, if I say hash message, it can be evaluated to an object colors mule message, dot payload will print the payload.

Okay, now, here coming back to set payload, I hard coded the string hello world. Right now I don't want to hard code HelloWorld. I want to write an expression Dynamic expression. So what I want is in the Hello World, let's assume that I'm expecting a query parameter and the request. Let's assume that I'm query I'm expecting query parameter Cora's user name, how to pass query parameters, you know, right? In the URL, it can pass query parameters in question mark.

Let's say user name is equals to say, My name. I'm expecting a request to come in this way. So what I want is is of hello world, it should say hello. So right now. I want to modify the set payload transformer to use the next question. So what I can do is I can switch to expression view.

And whenever I'm writing an expression if I want a string to keep it in, single quote. So this is how we can write a string a string literal, in database expression in single court and concatenation operator is plus plus not single plus plus plus is a common concatenation operator. Now, I told you that a mule message will also contain attributes right attribute will contain headers as I said. So, if I want to extract query parameters are they can those attributes or even I can say message dot attributes, if I say methods or attributes or even simple attribute that is both a single attribute attributes dot query params Yes, query params. Actually query params is a map that can be a number of query parameters I should know what is the key dot I'm expecting what the query parameter name username so dot username So, This will extract a query parameter with name, user name.

And it will concatenate a series of hello world. I say hello and concatenate with username. Now I saved my XML. And let me see the console. Is it getting rebuilt automatically? Yes.

Once I save my XML, automatically, it should be rebuilt. Oh, yeah. I'm seeing some error message here. What is our saying? I just got XML view in XML, it is not showing any problems okay. But if I come to graphical mode, it is showing some problems.

And if you want to see the problems, what you can do is you can go to problems and you can see here in errors, it's saying there is an error. Instead, the error is saying that there is some problem with expression. Okay. So let me see the expression again, is it correct or not? It looks to refine for me, what I'll do is I will close this XML and open it. Now there is no error, right.

So I won't tell you Firstly, sometimes on the ID, it shows that there might be some problems but actual there might not be. There are some bugs with any points to do. And sometimes it shows like this, but this is not really a problem. First, let me save it and then deploy it. It's saying you're already running an instance, the One Stop running application start. Yes.

So it will restart Then we see the console. It's again doing a Maven build and deploy my application. Let's wait, the application will get deployed and just wait for some time the application got deployed successfully. Now let me refresh. I am giving a request to slash Hallo and use an emoji Corsica. Oh, I got a pop up and I'll say open with okay.

I'd say open with notepad. Okay, let us see. I got Hello Siva huh. But why God opened in a notepad Why is it not displaying on the browser? Let us try to understand will understand if I give a same request using my postman. I have postman installed.

You can also install if you don't have open this postman for making HTTP requests. Let it open Okay, my postman is open, I will make a get request to this URL I selected get and pass the query parameter, user name request to see what we send. Just taking some time that we see here is anything. Yep. Yeah, I got the response. Hello, Siva.

But let's see the headers. What is the MIME type here? application slash Java. So by default, when I wrote an expression here and set payload, the MIME type is set as Java. Is it because here I wrote some expression Which is extracting the data from query parameters. What I'll do is I'll write S string.

Let us see now what will happen? I'll I've saved it. Let's see, is it getting redeployed? Do I need to run it every time? Now, once I saved it, I think you can observe that it got redeployed automatically. Again.

Now I'll give a request till I got application slash Java, but now here in the logs also should see that policy was displayed. So you saw that still I'm getting this s applications less job now. I can go to set payload. Here there is a tab called as MIME type. Let us see if we can set some MIME type here. Shall I say text slash plain?

Yes, I have configured the MIME type. And I saved it should get redeployed again. Yes, it looks like it caught redeployed. Now let me do a request. Yep, now I got text slash plain. So if you know what the MIME type you are setting you can just go to the transformer and select the MIME type that same mime template press will be given.

Now if I open my Firefox, it is giving it as a texter plain Is that okay? Now we understood some basics. Now what I want you to understand is How to debug this new application. If you want debug what you do is that right click on any component and select toggle breakpoint it will set a breakpoint where it will stop if you run in debug mode. I will go to console and I'll kill his application terminate the application will get terminated okay clear the console. Now, earlier I said run as your project now I said debug the project I want to run in debug mode.

Okay. Starting in debug mode. Now it is asking me to switch to mule debug perspective the view of this any points toward Do we change if I say yes, I will say yes. See now, once I said yes the view of this any points to your changed and here you are seeing a mule debugger window on the top Okay. Now, let me give a request How would you request once the request comes? I should see that it should be stopped here and I see yes, now, you can see that the request came here it stopped, you can see this icon right like this.

Yes, once the contract is here, what is the payload at each component? Let us see. If I select Set payload at this point, the value of set payload is Hello Siva. Right So, at this point, I want you to observe attributes also attributes contains all HTTP request specific headers as you can see attributes and here it has headers, the key value pairs or HTTP headers etc, right. So, attributes is having epi maximizes attributes his own query params and insert query params. We have user name is a cost to see what query params you can see is an abstract map is it?

Yes. Now, I will press f6 f6 will take me to next component, f six. C. Now I'm at the logger right now. At the logger if I see what is the payload Hello, Siva log level is info and say metric words, paler at this point is policy. Right? Okay.

So if you want to click from here f6 you can see the next process. And f8 will continue until next breakpoint. I'll click on resume. So now the flow completed and I got the response, I should have got response. All right. So now you understood how to debug, you have to just set a breakpoint anywhere wherever you want to break, and then they can press f6 f6 or f8 if you want to continue fully.

Okay, I will switch back to normal perspective. mule design perspective by clicking on this icon on the top right corner. Okay, now, earlier, we wrote expression data expression to extract user name from query parameter. I don't want like this What I want is I want my URL itself to contain slash hollow slash, see what I'm expecting the URL will be in this pattern slash Hello slash some variable in the URL, this can be variable it can be simple or it can press on or whatever it is. So, is my listener configured to listen for such requests? No, it is configured to listen for only slash Hello, if I want my listener to match any patterns, like whatever I was expecting to use slash hello and in curly braces, I say you name your networking I gave to name so that means the listener will be listening for any requests coming matching this patterns.

Okay, now, this you name how to access it in database expression. I will modify this query params As attributes dot you are a params.or that you name. So, whatever name I gave here you name I gave the same thing I can use it as a key. So, these are I can extract you are I parameter again as a string. Now, the application got redeployed. Now, let me do a request, go slash Hello slash press okay.

It's okay. It's opening in debug view because earlier, I ran in debug mode. I say yes. Now I don't want to run in debug mode anymore. I just resume f8 or exit logger again, there's one more breakpoint again it press f8 Now, let me see how long is it? Yes.

So, again I want you to observe right now, insert attributes there is you are a parent right now, which is again a map right. So, now you understood how to extract query parameters and you are a parameters from HTTP request and we understood some basics of data with expression simple data expression we have written and one more small thing I want to tell you before this video. As I told you, mule event will be created by the HTTP GDP is not a new level will be kept inside skilled and utterly In the structure of a mule event, how does it look like mule event contains a mule message. Of course a mule message internally contains attributes and payload. And you leave it also contains variables. Now, what I want to do is I want to set variables right now.

Okay? The how to set a variable in the event, there's a transformer called a set variable a drag and drop here. And in this set variable, what is the name? What are the variable name, I'll say my user whatever I want you and I want it to be set with some value. I will switch to expression more here and I write attributes dot you are right params dot union So I'm extracting the value of username and setting it as my user. Okay, then how to access this variable.

What I can do is again, I'll go to set payload. Now I want to extract it from variable. I hit Save as that is an implicit object in data we have expression. Whereas dot minute, that's it, these are way to access any variable. And again, I know that is a string as a as column as a string. Okay, so now you know how to set a variable.

And how to extract a variable in the database expression, I think is already working here. Now I stopped it. So again, let me launch this in debug mode. I want you to observe the variables also in the main event. I'll pause the video and then I'll start again. Okay, I'm switching to the workbench.

Back to yes. Okay now request comes here Yeah. Now did you see in the debugger that is aware with name my user where the control is except payload is a valid name my user, initialize it person. So whatever you are seeing here, you are seeing that you're seeing attributes you're seeing right. So now you understood how to look at vaccines and debug perspective also. Okay.

Cool. Now we understand mule basics. You understood how to write a simple flow. Every flow will contain three parts one is the source part, processor part and error handling part We didn't write anything in the error handling part right now, in the source part, we understood that there will be some inbound endpoints, what is an inbound endpoint, a component it will take a method into my flow is an inbound endpoint. So, here in this case, we have used HTTP listener as a inbound endpoint. And we understood that whenever we drag and drop components in the mule palette from the mule palette, the XML will be automatically written you can see that the flow has been automatically return inside the flow you have listener, where this listener is referencing to configure HTTP listener conflict.

Oh, this is a listener contract where it is configured to listen on port 8081. And this host this listener conflict tag is not inside the flow. is outside the flow tag is it it is global. So whatever is outside the flow tag, you can see that inside a tab called as global elements tab here. There is a stimulus and if you want to edit it, if you can select it and you can edit, okay? But why global elements actually, inside one XML, I can have multiple flows.

Let me drag and drop one more HTTP listener outside of this flow. See, in this XML, it created one more flow. That means one XML can have multiple flows, okay? But now what I can do is, see here, if I double click on this HTTP listener, it's selected by default the global element, right? So I'll use slash x. So now when the second foil big Enough when a request comes to again, same isn't aids right one slash x.

So, first one will be kicked off when the request comes to slash Hello slash this URL variable and this one will be kicked off for same port localhost 8081 but class x. So basically are we not use reusing this global element? listener config? Yes. So global elements are for reusability we can refer to the same global element multiple times. So here I am referencing to that global element.

Good. You understand what what is the global element and also you understood that one XML can contain multiple flows. And also Lastly, what I want to tell you is in one project that can be multiple examples. So I'll right click on SRC main mule, and I'll say new mule configuration file here. If I select and say, some test, see it creates one more XML. And here I can configure again, one more flow.

Let's assume again, I won't drag and drop one more HTTP listener. So and I'll set the payload in this flow. Here I'll write a plaintext Hello, okay. Now, this listener if I select the pod, I can give us slash x if you see one magic here, this A prisoner also is referencing the same global element. I didn't configure a global element in this XML, see in this XML is there any global limit? No.

That means the global element created in mule basics dot XML is also can also be referenced from another XML. That means global elements are not per XML, they are at project level. Okay. So that's it. Now, what you can do is, after seeing this video, you have to work on an exercise. So in this, you will be seeing in the section you will be seeing lab document in the resources section.

You will be seeing this lab document. Here I have given step by step instructions on what you have to do. You just have to follow this document and complete the exercise as per my description. Go ahead. It is very important to do the exercises after you see the video. Please proceed only after you complete this exercise.

Don't watch the video only just complete this exercise. See you next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.