$show=/label

Latest 20+ JMS Interview Questions and Answers

SHARE:

A quick walk through to JMS(Java Message Service) frequently asked interview questions and answers. The lastest questions from 2020 are added to the list.

1. Introduction


In this tutorial, We'll learn about JMS interview questions that are frequently asked in 2020. As part of the interview, There are chances to ask some of the questions on JMS area if you have 6 years plus. But, even less experience, it is good to have in the profile on JMS experience. The interviewer will check as messaging is a key aspect of enterprise Java development.
JMS is a popular open-source Messaging API and many vendors such as Apache Active MQ, Websphere MQ, Sonic MQ provides an implementation of Java messaging API or JMS.


Usually, Any interview starts with a basic. If all questions are answered properly then we will go onto the JMS experience project-based questions.

Basics mean What is Topic? What is the Queue? What is Publisher? What is Subscriber? What are a Publisher and Subscriber model? How to configure MQ?
Next level means Questions on a project where you have implemented JMS concepts?


2. JMS Interview Questions


2.1 WHat is the meaning of JMS?

JMS is a Java Messaging Service that is provided by Sun Microsystems that provides communication among the computers in a network. This is a standard to interact with the client system. Here, the J2EE application gets the ability with JMS to create, send or receive, read the messages.

2.2 What are the Messaging types provided by JMS?

JMS comes with two types of messages.

A) Synchronous
B) Asynchronous

2.3 What is the difference between Synchronous and Asynchronous Messaging Types?


Synchronous Messages:


Synchronous messaging involves a client that waits for the server to respond to a message. Messages are able to flow in both directions, to and from. Essentially it means that synchronous messaging is a two-way communication. i.e. Sender sends a message to the receiver and the receiver receives this message and gives a reply to the sender. The sender will not send another message until it gets a reply from the receiver.

Asynchronous Messages


Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server. So even if the client is down, the messaging will complete successfully. Asynchronous Messaging means that it is a one-way communication and the flow of communication is one way only.


2.4 What are the types of messaging model do JMS provide?


It provides mainly two messaging models as below in the messaging world and these two are the commonly used.

A) Point-to-Point Model
B) Publish and Subscribe Model

Point-to-Point Model

The P2P messaging model consists of message senders, receivers, queues, and messages. A JMS client that generates messages is called the sender; a JMS client that consumes messages is called the receiver. In the P2P model, a sender sends a message to a destination called the queue; a receiver retrieves the message from the same queue

Publish and Subscribe Model

The pub/sub model consists of message publishers, subscribers, and topics. A message producer is called a publisher; a message consumer is called a subscriber. The destination where a publisher sends messages and the subscribers retrieve the messages is called the topic. The pub/sub model is based on the concept of nodes in a content hierarchy, where a publisher publishes messages to a destination and the messages are broadcast to all registered subscribers.

Read More

Point-to-Point Model


2.5 What is the difference between topic and queue?


A queue means a message goes to one and only one possible subscriber. A topic goes to each and every subscriber. Topics are for the publisher-subscriber model, while queues are for point-to-point. The same published message is received by all-consuming subscribers.

Topic: A distribution mechanism for publishing messages that are delivered to multiple subscribers.

What is the difference between topic and queue?



2.6 What is the use of the JMS provider?


A JMS provider is a messaging system that implements the JMS interfaces and provides administrative and control features. An implementation of the Java EE platform includes a JMS provider. JMS clients are the programs or components, written in the Java programming language, that produce and consume messages.

It also specifies the level of encryption, the security level of the message and the best-data type for the non-JMS client.

2.7 What are the components in JMS Architecture?


Message producers
Message consumers
JMS messages
Administered JMS objects
JNDI naming service

2.8 Tell an example of using point to point model in JMS?

2.9 What are the core JMS objects required to JMS-enabled application?

2.10 What is JMS administered object?


JMS administered object is a pre configured JMS object that is created by an administrator for the use of JMS clients and placed in JNDI namespace.

2.11 What are the important parts of the JMS application?


Connection
Session
Message
Message Producer
Message Consumer
Connection factory and destination

2.12 What is the JMS session and what are the uses?


A session is a single-threaded context for producing(producing) and consuming(receiving) messages. A JMS session could be a locally transacted, non-transacted or distributed transacted.

Uses:


A session serves several purposes:

It is a factory for its message producers and consumers.
It supplies provider-optimized message factories.
It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.
It defines a serial order for the messages it consumes and the messages it produces.
It retains messages it consumes until it has been acknowledged.
It serializes the execution of message listeners registered with its message consumers.
A session can create and service multiple message producers and consumers.

2.13 What is the difference between durable and non-durable subscriptions?


A durable subscription gives a subscriber the freedom of receiving all messages from a topic and stores the messages permanently, while a non-durable subscription does not make any guarantees about messages sent by others when a client gets disconnected by others and these do not store the messages.

Note: We compared performance for durable and non-durable subscribers in two cases: persistent and nonpersistent 10k-sized messages. Both cases use AUTO_ACKNOWLEDGE acknowledgment mode. We found a performance impact only in the case of persistent messages, which slowed messages conveyed to durable subscribers by about 30%.

2.14 What is Byte Message?


A BytesMessage object is used to send a message containing a stream of uninterpreted bytes. It inherits from the Message interface and adds a bytes message body. The receiver of the message supplies the interpretation of the bytes.

The BytesMessage methods are based largely on those found in java.io.DataInputStream and java.io.DataOutputStream.

This message type is for client encoding of existing message formats. If possible, one of the other self-defining message types should be used instead.

Read More

2.15 Talk about different types of messages available in JMS API?


Different types of messages available in JMS API and those are TextMessage, BytesMessage, StreamMessage, ObjectMessage, and MapMessage.

A. TextMessage


TextMessage is used to store string values of any specific length. But this takes only String messages. This message type can be used to transport text-based messages, including those with XML content.

When a client receives a TextMessage, it is in read-only mode. If a client attempts to write to the message at this point, a MessageNotWriteableException is thrown. If clearBody is called, the message can now be both reads from and written to.

//Create a TextMessage
TextMessage sampleTextMsg = session.createTextMessage();

//Store values within TextMessage
sampleTextMsg.setText(“sample content”);

// Retrieve values from TextMessage
String storedText = sampleTextMsg.getText();

B. BytesMessage


//Create BytesMessage
BytesMessage sampleBytesMsg = session.createBytesMessage();

//Storing an array of numbers in BytesMessage
byte[] byteArray = new byte[]{66,68,70};
sampleBytesMsg.writeBytes(byteArray);

// Fetch the stored numbers by doing required casting
byte[] msgContent = new byte[3];
sampleBytesMsg.readBytes(msgContent);

C. StreamMessage


A StreamMessage object is used to send a stream of primitive types in the Java programming language. It is filled and read sequentially. The primitive types can be read or written explicitly using methods for each type.

//Create a StreamMessage
StreamMessage sampleStreamMsg = session.createStreamMessage();

//Store values within StreamMessage
sampleStreamMsg.writeBoolean(false);
sampleStreamMsg.writeBoolean(true);
sampleStreamMsg.writeBoolean(false);

// Retrieve values from StreamMessage
System.out.println(sampleStreamMsg.readBoolean());
System.out.println(sampleStreamMsg.readBoolean());
System.out.println(sampleStreamMsg.readBoolean());

D. ObjectMessage


Using ObjectMessage, an object can be wrapped as a message and transmitted across, but the object must be serializable.

//Create an ObjectMessage
ObjectMessage  sampleObjMsg = session.createObjectMessage();

//Create a ValueObject and initialize it with values
ValueObject vObj = new ValueObject(‘sampleField’,54);

//Store the ValueObject within ObjectMessage
sampleObjMsg.setObject(vObj));

//Retrieve the stored ValueObject from the ObjectMessage
vObj = (ValueObject) sampleObjMsg.getObject();


E. MapMessage


A MapMessage object is used to send a set of name-value pairs. The names are String objects, and the values are primitive data types of Java. The name should not be null.

//Create a MapMessage
MapMessage sampleMapMsg = session.createMapMessage();

//Set Key Value Pair with type String
sampleMapMsg.setString('SampleKey', 'SampleValue');

// Retrieve String value using Key
sampleMapMsg.getString('SampleKey');

//Set Key Value Pair without specifying type
sampleMapMsg.setObject('SampleKey1', 'SampleValue1');

// Retrieve Object value using Key
sampleMapMsg.getObject(‘'SampleKey1');

2.16 Difference between the P2P(Peer to Peer) model and subscribe model?


The main difference is P2P is highly reliable and should be used in only one to one scenario but where a subscriber model can be used in one to many scenarios.

2.17 What is a JMS client?


JMS client is a core component in JMS and it is used to send or receive messages. JMS supports two styles of messaging: the point−to−point and publish−and−subscribe messaging styles

2.18 Can we send e-mail as a message using JMS? Does JMS support Email as a message type?


No. JMS has no capability to inherit support for it.

2.19 How JMS is different from RPC?


Java Messaging Service (JMS)


JMS is asynchronous in nature. When a message has to be transmitted, the Sender will send the message to the receiver. With this, the Sender’s job is done and it will continue with its further processing. The receiver will receive the message and continue with its own processing. No acknowledgment is sent from the receiver to the sender after receiving the message. This is because JMS is asynchronous.

There is no coupling between the sender and receiver of the message in JMS. Thus, JMS allows new senders and receivers to be added dynamically thereby managing variations in complexity over a period of time.  Hence, JMS is loosely coupled.

When there is an unexpected failure, JMS will store the messages that are pending to be delivered. When the system is up, the stored messages will be transmitted to the corresponding receivers.


Remote Procedure Call (RPC)


RPC is synchronous in nature. Unlike JMS, the invoker of the remote procedure call will invoke the method and continue to wait until the invoked method completes its execution. Once when the invoked method execution is complete, then the control returns back to the invoker. This is because RPC is synchronous in behaviour.

RPC establishes tight coupling between the systems that interact with one another. When the invoker invokes a remote method, the invoker will get blocked until the response comes back to the invoker.

When there is an unexpected failure, the failure will impact the entire system. Thereby, the entire system will go down.


2.20 How to deliver a message to a non-java client in JMS?


If your Java code and the non-Java code can agree on a byte- or text-based message format, you can interchange the message between them. Yes, it can consume a java message.

3. Conclusion


In this article, We've seen the most commonly asked interview questions on JMS.

We'll be adding a few more questions and answers.

If you know any questions apart from these, please post in the comments sections. We will add with answers to this article.

COMMENTS

BLOGGER

About Us

Author: Venkatesh - I love to learn and share the technical stuff.
Name

accumulo,1,ActiveMQ,2,Adsense,1,API,37,ArrayList,18,Arrays,24,Bean Creation,3,Bean Scopes,1,BiConsumer,1,Blogger Tips,1,Books,1,C Programming,1,Collection,8,Collections,37,Collector,1,Command Line,1,Comparator,1,Compile Errors,1,Configurations,7,Constants,1,Control Statements,8,Conversions,6,Core Java,149,Corona India,1,Create,2,CSS,1,Date,3,Date Time API,38,Dictionary,1,Difference,2,Download,1,Eclipse,3,Efficiently,1,Error,1,Errors,1,Exceptions,8,Fast,1,Files,17,Float,1,Font,1,Form,1,Freshers,1,Function,3,Functional Interface,2,Garbage Collector,1,Generics,4,Git,9,Grant,1,Grep,1,HashMap,2,HomeBrew,2,HTML,2,HttpClient,2,Immutable,1,Installation,1,Interview Questions,6,Iterate,2,Jackson API,3,Java,32,Java 10,1,Java 11,6,Java 12,5,Java 13,2,Java 14,2,Java 8,128,Java 8 Difference,2,Java 8 Stream Conversions,4,java 8 Stream Examples,12,Java 9,1,Java Conversions,14,Java Design Patterns,1,Java Files,1,Java Program,3,Java Programs,114,Java Spark,1,java.lang,4,java.util. function,1,JavaScript,1,jQuery,1,Kotlin,11,Kotlin Conversions,6,Kotlin Programs,10,Lambda,2,lang,29,Leap Year,1,live updates,1,LocalDate,1,Logging,1,Mac OS,3,Math,1,Matrix,6,Maven,1,Method References,1,Mockito,1,MongoDB,3,New Features,1,Operations,1,Optional,6,Oracle,5,Oracle 18C,1,Partition,1,Patterns,1,Programs,1,Property,1,Python,2,Quarkus,1,Read,1,Real Time,1,Recursion,2,Remove,2,Rest API,1,Schedules,1,Serialization,1,Servlet,2,Sort,1,Sorting Techniques,8,Spring,2,Spring Boot,23,Spring Email,1,Spring MVC,1,Streams,31,String,61,String Programs,28,String Revese,1,StringBuilder,1,Swing,1,System,1,Tags,1,Threads,11,Tomcat,1,Tomcat 8,1,Troubleshoot,26,Unix,3,Updates,3,util,5,While Loop,1,
ltr
item
JavaProgramTo.com: Latest 20+ JMS Interview Questions and Answers
Latest 20+ JMS Interview Questions and Answers
A quick walk through to JMS(Java Message Service) frequently asked interview questions and answers. The lastest questions from 2020 are added to the list.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqxvCRK3Qh7QfeX1c4GSJVMC757YPX1dOtTj278kb7vrs4abHMH56VU0AmGnHbaQxfwVTnn6V8Rju9L5lpdw4F4qVs5L_qKVupb62OSMBNxHZsiuLfqvFmlyFzFN8bD7iYVTNbO_JfoFY/s640/Point-to-Point+Model.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqxvCRK3Qh7QfeX1c4GSJVMC757YPX1dOtTj278kb7vrs4abHMH56VU0AmGnHbaQxfwVTnn6V8Rju9L5lpdw4F4qVs5L_qKVupb62OSMBNxHZsiuLfqvFmlyFzFN8bD7iYVTNbO_JfoFY/s72-c/Point-to-Point+Model.png
JavaProgramTo.com
https://www.javaprogramto.com/2020/04/jms-interview-questions.html
https://www.javaprogramto.com/
https://www.javaprogramto.com/
https://www.javaprogramto.com/2020/04/jms-interview-questions.html
true
3124782013468838591
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content