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