Java Messaging Service – Part 5 – JMS Vs MDB Listener
In this article, we will talk some basics about the differences between Web Server and Application Server. We will also conclude with understanding when to go for JMS Listener and when for JMS MDB Listener.
This post is going to be totally theoretical!
Basically there are two server types – Web server and Application server.
What are the main differences between Web server and Application server?
*Multithreading – Is a Java feature that’s allows concurrent execution of same program. Each part of the program is referred as thread.
For more details, check the link – https://www.geeksforgeeks.org/multithreading-in-java/
**Apache tomcat – Web server or App server? – Always a discussion topic. To me Apache Tomcat is an Application server that do not provide (do not adhere to) all of the J2EE standards. Tomcat can never be isolated as web server alone!
We will discuss all the above points extensively
1. Web servers are mainly meant to serve static HTML content, while application servers serve dynamic content
So what is this ‘static and dynamic HTTP contents’?
We know that Pega personal edition package consists of two applications.
prhelp.war and prweb.war
prhelp application is the best example of static content. It just provides the right HTML page, when referred.
You will see list of all HTML pages under each topic inside the application directory –
Locally you can also click through the HTML pages to see the help content.
Once your server is up and running, you can also do the same using the localhost running help application
http://localhost:8080/prhelp/procomhelpmain.htm#rule-/rule-utility-/rule-utility-function/main.htm
These are all just static content. It doesn’t need any complex internal processes to serve the HTML request. To run this application, a simple web server is highly enough.
Let’s switch to our Pega application. We know how much processing we do in a Pega application – Database actions, Web services lot and lot of actions. You can relate prweb application as serving the dynamic content.
2. App server adheres to J2EE standards while Web servers do not
What is J2EE standards?
J2EE – Java Enterprise Edition
As the name suggests it is used in enterprise applications under a set of specifications.
The specifications define APIs and their interactions.
You will see there are different versions of J2EE introducing some new components or features in each release.
It follows a certain set of standards and the application servers that satisfies those requirements are called Java EE complaint.
Some of the notable specifications are
1. WebSocket – A set of APIs that service WebSocket connections.
2. Enterprise JavaBean – A set of APIs that is responsible for security, transaction management, object pooling etc.
There are two main types of enterprise bean – Session bean and Message Driven bean
Session bean –
Contains business logic and gets invoked by other clients.
Message driven bean –
Contains the business logic but gets invoked by messages.
3. Java Persistence API (JPA) – This API is mainly used in persisting the business objects. JPA can be used with both relational databases and no-SQL databases.
4. Java Transaction API (JTA) – This API is used to manage transactions between distributed systems. You can relate transactions to commit/rollback actions
5. Java Messaging service (JMS) – API that supporting sending and receiving messages.
All the App servers – WebSphere, WebLogic adhere to the J2EE standards and can make use of all the specifications to run an enterprise application.
Web Servers cannot use these J2EE standards.
3. Web Server encompass web container only where as App Server encompass web container as well as EJB container
What is Web Container?
Visualize web container as a virtual component in the server.
Web container interacts with web servlets.
We are used to the servlet term in Pega. Some notable servlets are
PRServlet – Supports HTTP interaction requests.
PRSOAPServlet – Responds to SOAP requests from SOAP clients.
PRTraceServlet – Implements the tracer debugging tool
There are other servlets that support LDAP, diagnostics etc.
So Web containers main role is to map the requests with the right servlets
You can browse through Web containers for more details – https://en.wikipedia.org/wiki/Web_container
What is EJB container?
It maintains the lifecycle of enterprise beans – creating authorized access, saving etc.
As we saw before there are two main type of Enterprise Java Bean – Session bean and message driven bean.
Session bean –
Contains business logic and gets invoked by other clients.
Message driven bean –
Contains the business logic but gets invoked by messages.
I will conclude with the differences between Web server and App Server.
App Servers provide a lot of capacity than Web Servers.
Pega platform can be deployed as either web application (Web server) or an enterprise application (App server)
The installation package for web application is .war file and the installation package for enterprise application is .ear file.
We have already seen before that the Personal edition is packaged as war file.
Please check the link for ear file description –
https://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html
Tip: Also please browse through google to understand the difference between ear and war file.
The deployment descriptor files vary between war and ear deployment
Why did I bring these different topics for Java Messaging Services
JMS Service can be implemented in two ways
- Using the JMS Listener – Used especially in non –J2EE complaint servers
- Using JMS MDB listener – Used in J2EE complaint App servers
Now you know clearly when to use JMS Listener and JMS MDB Listener.
Differences between JMS and JMS MDB Listener?
– Use JMS Listener when you deploy the Pega platform as a Web application. Use JMS MDB Listener when you deploy Pega platform as a Enterprise application.
– With JMS listener – A java thread is created and the listener waits for any incoming message. With JMS MDB Listener – the deployed Message Driven bean routes the message to the right service rule.
So for JMS MDB Listener – you need to generate a fragment for the MDB and inject it into the deployment descriptor file.
Also we saw in the previous article on JMS connector, when to go for JMS or MQ connector.
Exactly the same explanation for JMS and MQ listener. In Short, MQ is a special implementation for IBM MQ provider and will be used only when your App server is IBM WepSphere.
Since we are using Personal edition – Tomcat server, we cannot make use of J2EE features like EJB and hence JMS MDB is not possible in personal edition. In the next article, we will start creating a JMS listener.