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
€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. 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.