Sending and receving Messages from ActiveMq using JMS Module

Mule 4 Indepth Using Jms Module
23 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
€67.35
List Price:  €96.21
You save:  €28.86
£55.83
List Price:  £79.77
You save:  £23.93
CA$100.76
List Price:  CA$143.95
You save:  CA$43.19
A$112.23
List Price:  A$160.33
You save:  A$48.10
S$95.14
List Price:  S$135.93
You save:  S$40.78
HK$543.62
List Price:  HK$776.63
You save:  HK$233.01
CHF 63.04
List Price:  CHF 90.06
You save:  CHF 27.02
NOK kr797.48
List Price:  NOK kr1,139.30
You save:  NOK kr341.82
DKK kr502.49
List Price:  DKK kr717.87
You save:  DKK kr215.38
NZ$124.10
List Price:  NZ$177.29
You save:  NZ$53.19
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,361.55
List Price:  ৳11,945.58
You save:  ৳3,584.03
₹5,962.79
List Price:  ₹8,518.63
You save:  ₹2,555.84
RM314.04
List Price:  RM448.65
You save:  RM134.61
₦108,335.42
List Price:  ₦154,771.52
You save:  ₦46,436.10
₨19,495.71
List Price:  ₨27,852.21
You save:  ₨8,356.49
฿2,390.81
List Price:  ฿3,415.60
You save:  ฿1,024.78
₺2,467.44
List Price:  ₺3,525.07
You save:  ₺1,057.62
B$434.14
List Price:  B$620.23
You save:  B$186.09
R1,296.68
List Price:  R1,852.48
You save:  R555.80
Лв131.68
List Price:  Лв188.12
You save:  Лв56.44
₩102,198.93
List Price:  ₩146,004.73
You save:  ₩43,805.79
₪256.56
List Price:  ₪366.53
You save:  ₪109.97
₱4,090.81
List Price:  ₱5,844.26
You save:  ₱1,753.45
¥10,994.99
List Price:  ¥15,707.80
You save:  ¥4,712.81
MX$1,408.98
List Price:  MX$2,012.91
You save:  MX$603.93
QR255.09
List Price:  QR364.43
You save:  QR109.34
P967.82
List Price:  P1,382.66
You save:  P414.84
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,562.49
List Price:  E£5,089.49
You save:  E£1,527
ብር8,907.19
List Price:  ብር12,725.10
You save:  ብር3,817.91
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$69,323.69
List Price:  CLP$99,038.09
You save:  CLP$29,714.40
CN¥510.80
List Price:  CN¥729.75
You save:  CN¥218.94
RD$4,245.36
List Price:  RD$6,065.06
You save:  RD$1,819.70
DA9,465.07
List Price:  DA13,522.10
You save:  DA4,057.03
FJ$162.39
List Price:  FJ$232
You save:  FJ$69.60
Q539.11
List Price:  Q770.19
You save:  Q231.08
GY$14,638.77
List Price:  GY$20,913.42
You save:  GY$6,274.65
ISK kr9,772.70
List Price:  ISK kr13,961.60
You save:  ISK kr4,188.90
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,291.33
List Price:  L1,844.84
You save:  L553.50
ден4,143.97
List Price:  ден5,920.21
You save:  ден1,776.24
MOP$559.97
List Price:  MOP$800
You save:  MOP$240.02
N$1,289.45
List Price:  N$1,842.15
You save:  N$552.70
C$2,574.80
List Price:  C$3,678.44
You save:  C$1,103.64
रु9,534.71
List Price:  रु13,621.60
You save:  रु4,086.89
S/260.99
List Price:  S/372.86
You save:  S/111.86
K283.85
List Price:  K405.52
You save:  K121.66
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,936.45
List Price:  ZK2,766.47
You save:  ZK830.02
L335.12
List Price:  L478.77
You save:  L143.64
Kč1,694.03
List Price:  Kč2,420.15
You save:  Kč726.12
Ft27,771.44
List Price:  Ft39,675.18
You save:  Ft11,903.74
SEK kr774.38
List Price:  SEK kr1,106.30
You save:  SEK kr331.92
ARS$71,792.58
List Price:  ARS$102,565.23
You save:  ARS$30,772.64
Bs484.55
List Price:  Bs692.24
You save:  Bs207.69
COP$307,165.41
List Price:  COP$438,826.54
You save:  COP$131,661.12
₡35,530.54
List Price:  ₡50,760.09
You save:  ₡15,229.55
L1,777.33
List Price:  L2,539.15
You save:  L761.82
₲546,250
List Price:  ₲780,390.60
You save:  ₲234,140.59
$U3,115.91
List Price:  $U4,451.49
You save:  $U1,335.58
zł287.82
List Price:  zł411.19
You save:  zł123.37
Already have an account? Log In

Transcript

Welcome back. In this video, we are going to understand about JMS module. How to send messages to a JMS broker manage queue and get response from the queue or received messages from the various aspects. So in this lab, I'll be using Apache active mq as my Message Broker. The installation of Apache active mq is very simple. So you can just go to active mq website, and you can download this zip file.

So I have the zip file already downloaded. Let's start here. Okay, there's salt. And if you want to start active mq, it's very simple. You can just go into bin directory. Mine is Windows 64.

So go to Windows 64. CMD then I like secured active on cue dot back. That's all this will start up which I think I'll open with CMD again here, go to this Okay, go to the SR 64 I CD to this then I just started skirt active. Back that's all this is start my active mq it's right hundred stocks. Okay it started so actually active mq will be having a web UI at 8161 so I'll just go to localhost 8161 Yep. If I click on Manage active mq broker Ask me for username and password.

The default username and password is admin admin. So I'm giving this admin admin okay. And here we'll go to queues there are no queues I want to create a queue with name in queue Okay. Now, what I want to do is I want to send a message into this in queue through my mule flow. Let us see very simple so I would be working on James stack project. I have an XML already have this XML is empty.

So, firstly what I want to do is I want drag and drop or HTTP listener. Okay. I will do Conficker as usual With a great one port. So take all the defaults and click on requests and then the path slash JMS send. Then I want to use JMS module. And here, we don't see any JMS module here.

So I'll click on Add modules, and then drag and drop, James. Yep. So it is added. Now I want to publish on methods. So there is our president calls publish. I will drag and drop this publish.

So here again, I need to trigger a j Miss connector configuration. So click on it yep. So what I want is I can select what type of connection active MPI want to select. And then here I need to add add jobs after train gather configure to add a Maven dependency, yep, here it is coming. I take the defaults. Or if you are not getting it, you can just select from your URL, you can get it I have active mq client configured finish.

So it should be automatically added in the build path. Okay, then come down. Here. Actually, if you've worked with Jay Massey to configure a connection factory, your configure connection factory configuration, I will edit in line You're going to configure the broker URL if you are having access to running inline that means if it is running in the same JVM, you can use VM colon colon slash slash local host. But I have activity running externally. So the standard values TCP colon slash slash localhost colon 61616.

So this is a URL at which broker is listening. Don't get confused actually. 816 swells a web UI and 64616 is a broker. So you can actually configure other things also if you are brokers products, particular the username and password. You can you use a name password, right? So otherwise we'll take all the defaults right now I'll click OK. Then I want to send message to which destination I want to send queue with naming queue.

And destination type is queue or topic I selected. And then that's all I have configured, you can see that the body of the JMS message is configured to be payload bodies failed or whatever is the payload of the mail method that will be sent us boy. Okay, so that's it now why just run and check what will happen. After this publish, first of all, I'll drag and drop a locker here Bring a payload what is hash payload and simply write out let me double check. Okay, so I need to give a request, Jamison. So in this case, I'll use postman to make a POST request because whatever I send as post body will become the body of the JMS message because if you see in the publish, what should go as part of JMS message, whatever is the payload.

So I'll make a POST request using postman. So whatever post body I send that should go as a body to JMS message serves a Okay, so I'll give a request to slash, JMS sent. And then I'll make it a POST request. Body raw. This send Hello. Send a wait for response responses on James, send me right So I made a POST request.

Yep, I got the response. Same, because I didn't do any transformation what our published it came in response. Let us see the queue and refresh. See me into that one pending message. I will go to the CTO of the call this message is the same hello world. Yes.

So I am able to send message by using publish operation on the JMS connector. Great. Now I want to listen for messages and get all the methods. So if you want to listen for messages from broker jamis module that is That is normal. So, I just drag and drop again this I have use same connector at which displays I want to I want less nothing Q and consumer type is q consumer that's all I will not you right now, anything. Here you can see the number of consumer says for the this concurrently for consumer trends will be polling for any messages in the game is broken.

Okay. Once a JMS message comes, the listener will convert a miss message to mule message and we'll kick up the flow. What I'll do is I just drag and drop a logger and I print here message received and concatenate plus plus fail. So, now let me run this better. I'll stop and start again. Stocks Okay, and run it again.

Okay, it started and you can see here there's a locker return received Hello HelloWorld. So automatically the messages received, I fled the console. I will go to here and I will refresh. Now you can see that one message was in queue and one was dq also. And the number of pending messages is zero and number of consumers is four. Did you remember I configured that Hear for listener by default actually number of consumers right now for clarity I'll make it as one.

And if I restart, please stop again and then restart will observe what will be the number of consumers. Okay, it started. Now let's observe here, refresh. So I guess the number of consumers is one. That's okay. What I want to do is there is a listener already started here and is continuously listening for me.

I want to send some dummy messages to in queue. So there is a link called a senator here. I want to send some 50 messages to so in audio and text Low simple send. So now you can see that the 15 messages should come here. So you can see the 50 locks automatically got printed, is it but how many threads you can see there are threads up to number five number six thread also is there. So algos, I can say can see up to six threads concurrently have processed all of your messages.

So if I go and refresh here, zero messages, so all the messages were received and concurrently processed by multiple threats right now, that's fine is there is that and published, but this publish one part is doing is it Just publishing it's not waiting for response what I want to do is I want filler message and I want to wait for response. So, in such cases it should not use publish, delete this publish, you should just publish consume you want to publish and wait for response. So here I will double click on Publish consume and destination is in Okay. Now, let me run this again as top and start. So, in this case, what am I expecting you to publish the message to mq and the for response, okay. So, what I want to do is to submit a response after this listener I will just drag and drop a transformer Maybe simple transformer I want to append a pedestrian.

Simply drag and drop set payload simply. payload is payload plus plus packet ending it with press one. So once that message comes up, the message is transformed response and this should be sent as a source. Now, I will restart Okay, so test what I'll do is I'll send one message using postman hello world let's see what was forms and get responses hello world response if I see the console Yeah. That is your flies printing whistled and hello response right. Okay, but how did the response come?

Publish consume component is publishing a message and waiting for a response in Temporary response queue like user temporary reply, re configure reply to somewhere here now is none. I can even configure my own. Like, if I don't configure reply to header, what will happen? temporary queue will be created and the response comes to temporary cue a temporary queue will be deleted. Now, I want to configure it by two, I will create a new line destination is my ply queue. So I'm saying I want response in my reply queue.

Okay, let me reset, stop and start again. Okay, so again as you get request for post request service same thing. Yep, I got the response. Let us see the console. Again. It is same but now let's see here on the active empezar my replay right now.

Yes, the replay actually came here it was in queued and it was like you're awesome. So here in publish, consume if you want response if you want to reply, in some reply to your own reply, you can configure reply to and specify the key. Otherwise, if you don't configure that means if I just configured none that in such Cases replay, we'll go to some temporary key. This published consume component is going to create one temporary cue, wait for response entirely. Okay, that is JMS listener will send the response back to that one. Okay.

Okay, I want to do one more feature in JMS listener. This will be listening for all the messages we have configured for all the messages of in queue. But I don't want to receive all the messages that are coming to interview, I want to select based on some selection criteria. I want to select messages only which are having some say some headers. Take an example. Every method also has a prayer key right?

I want this jamis listener to select one The messages have priority say eight. What to do. So what I can do is the selector I can specify here select j was prt is equals to say eat NASA Now this flow receive only the messages at priority eight sea. In the meanwhile, try to send one message with priority to it. So, gotta close there are zero messages in queue right now. I click on Send to include one method I want to send and free RP eight.

I just send a message something like a send something up, I just read. Okay. So reset consumes refresh See here? Already it is I configured this message. Oh, I think I do reply to it. Okay, so the wrong method, so maybe I'll just delete this.

I create one more view in queue. Now to be very clear center and queue and I think was Bhatia here by mistake after configuring here you create send a message. This should be automatically consumed. See? Yeah, so I'm not printing with this zero and I should see that it is. Consume.

Right? Okay. Now what I'll do is I'll send one method with some other priority. Prayer, it says seven Hmm, method is something that we Okay, this should not be considered. Right. So I configured my JMS listener with a JMS selector to selectively receive messages with this properties.

So I just gave an example of JMS priority. You can use any of the methods property to sec. Okay, so hope you understood what is a JMS seller. So we have understood how to publish how to use publish consume and how to use JMS listener. How to use Jamie's selector and how to damos headers and symphonies. So you have a lab for games now, after this video, just open this document and complete the climax.

See when next week

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.