Tuesday, February 11, 2025
HomeJavaPrime 16 JMS (Java Messaging Service) Interview Questions and Solutions

Prime 16 JMS (Java Messaging Service) Interview Questions and Solutions


Java messaging Service or JMS interview questions is among the essential components of any Core Java or J2EE interview as messaging is a key facet of enterprise Java growth. JMS is a well-liked open-source Messaging API and numerous distributors like Apache ActiveMQ, Websphere MQ, Sonic MQ offers an implementation of Java messaging API or JMS. Any Java messaging providers or JMS interview will be divided into two components the place the primary half focuses on fundamentals of JMS API and messaging idea like What’s matter, What’s Queue, publish-subscribe or level to level mannequin, and so on, Whereas the second half is expounded to JMS expertise with explicit JMS supplier.

On this article, I’ll share the checklist of JMS interview questions, which not solely assist to solutions some questions on interviews but in addition assist to grasp Java Messaging higher.

Btw, If you’re a brand new Java Messaging Service then I additionally suggest you to first undergo a basic course like Java Messaging Service – JMS Fundamentals course by Bharat Thippireddy on Udemy. It covers every thing knowledgeable Java developer must learn about JMS and it is also very reasonably priced and you should buy in simply $10 on Udemy gross sales.

Prime 10 JMS (Java Messaging Service) Interview Questions and Solutions

With out losing any extra of your time, here’s a checklist of 10 incessantly requested JMS questions from Java Interviews. These questions are equally helpful for each rookies and skilled programmers.

1. Distinction between synchronous and asynchronous messaging? How do you do this in JMS?

Because the title suggests synchronous messaging is synchronous, which suggests Sender waits for a response from the Receiver, as a substitute of doing the rest. Alternatively in Asynchronous processing, Sender simply sends the message and begins doing different issues, as a substitute of ready for a response like possibly ship one other message. JMS helps each synchronous and asynchronous messaging

2. Distinction between publish-subscribe and point-to-point messaging?

publish-subscribe or pub/sub and level to level or just PTP, are two most used structure within the messaging world. As there title recommend, if communication occurs between two events i.e. one sender and just one receiver then it is referred to as a Level to Level messaging, whereas when you have many receivers, who’re excited by a message despatched by one producer, than you employ a publish-subscribe mannequin, the place you employ Subjects, which is subscribed by every client.

Nearly all messaging merchandise assist each types of messaging in a method or one other. Tibco Rendezvous helps level to level messaging as request/reply mode, whereas in JMS primarily based messaging merchandise you may merely use Queue for level to level messaging.

3. What’s JMS administered object?

JMS administered objects are these objects that are managed i.e. created, up to date, or destroyed by admins who handle JMS supplier or Dealer. Normally JMS supplier like Tibco, Websphere MQ offers instruments to create and handle these objects.

A standard instance of JMS administered objects are Connection Factories, Vacation spot like Matter and Queue, which is created by messaging or middleware staff and later accessed in Java applications utilizing JNDI and JMS API.

Top 16 JMS (Java messaging Service) Interview Questions and Answers

4. Distinction between Matter and Queue in JMS?

Matter and Queue are two sorts of vacation spot, the place a Sender sends messages. in Level to Pointe messaging, also referred to as PTP messaging, Sender and Receiver communicates utilizing Queue, whereas on publish-subscribe messaging, also referred to as pub/sub messaging, Receiver subscribes on a Matter.

The subject is used, when a couple of customers are excited by receiving the identical messages. In JMS, each Queue and Matter are interfaces, which prolong Vacation spot and subsequently encapsulate the title of the Matter or Queue.

Since Vacation spot is a JMS administered object, the creation of Matter and Queue is normally ruled by JMS Supplier administrator. Normally messaging or middleware staff, which administers dealer, creates Matter and Queue on request of the appliance staff and permits them to entry utilizing JNDI.

A JMS consumer can specify a Queue or Matter title whereas creating Message Producer or Shopper e.g. by utilizing Session.createConsumer(Vacation spot queueOrTopic) or Session.createProducer(Vacation spot queueOrTopic).

5. What sort of message is supported by JMS API?

JMS Specification helps several types of messages e.g. BytesMessage, MapMessage, ObjectMessage, StreamMessage, and TextMessage, all these are sub interface of Message interface and applied by JMS supplier.

Additionally, a JMS message consists of three components Header, properties, and physique. The one header is necessary for a JMS message although. TextMessage is among the commonest message sort, which is used amongst JMS shoppers. TextMessage is a wrapper round java.lang.String and offers handy strategies like getText() to get the message physique’s String. TextMessage can be used to move XML content material in most purposes.

6. Does JMS assist Assure message supply?

JMS offers completely different choices to ensure message supply like PERSISTENT and NON_PERSISTENT ship mode to ensure the message shouldn’t be misplaced throughout transportation. IT additionally offers JMS supplier to specify retention coverage for Queue and Matter, which may retain messages till it acknowledged or expired, or until sure supply try. sturdy subscription is one other approach to make sure your Receiver, receives a message even whether it is inactive when the writer publishes the message.

7. Distinction between PERSISTENT and NON_PERSISTENT messages?

PERSISTENT messages are these which despatched with supply mode DeliverMode.PERSISTENT and equally for the non-persistent messages. A consumer makes a message PERSISTENT if message loses in transit in not reasonably priced, whereas a consumer marks a message NON_PERSITENT if occasional message loses is OK.

When JMS Supplier receives a PERSISTENT message, it persists it to ensure that it reaches the vacation spot, even within the case of a dealer happening. By the best way, message retention at vacation spot Queue or Matter shouldn’t be ruled by supply mode, and it is set administratively. See Java Messaging Service – JMS Fundamentals for extra particulars.

8. Which Acknowledge modes are supported by JMS API? How does CLIENT_ACKNOWLEDGE mode work?

JMS helps 4 sorts of acknowledging modes like AUTO_ACKNOWLEGE, CLIENT_ACKNOWLEGE, DUPS_OK_ACKNOWLEDGE, and SESSION_TRANSACTED acknowledgment mode.

With AUTO_ACKNOWLEDGE mode, JMS session routinely acknowledges a consumer’s receipt of a message both when the session efficiently returned from obtain() methodology or the message listener session has referred to as, which course of message, returns.

The CLIENT_ACKNOWLEDGE mode offers you extra management, the place a message is acknowledged by calling acknowledge() methodology of the message itself, which suggests you may ACK message as soon as you might be completed with processing it.

The message shouldn’t be faraway from the Queue, which is in Server till it acknowledged and redelivered if the consumer did not acknowledge it. By the best way, there’s a catch, when you acknowledge a message, all messages are acknowledged and subsequently faraway from Queue on Server.

9. If in case you have a transacted session what occurs in case you get an exception whereas processing a message?

If JMS Session is transacted, during which case it returns SESSION_TRANSACTED from getAcknowledgeMode(), acknowledgment mode is ignored.

In transacted periods, commit() and rollback() strategies are used for committing receipt of a message. A name to commit(), confirms receipt of all messages on that session.

Equally, if an Exception is thrown from onMessage(), it could be thought of as rollback, and the message will stay in Queue for supply.

10. Do you could acknowledge the message explicitly whereas utilizing transacted JMS Session?

It is a follow-up of the earlier JMS Interview Query. No, you needn’t acknowledge the message explicitly by calling the acknowledge() methodology in case you are utilizing a transacted JMS Session. As I mentioned above, commit() and rollback() is used for acknowledging messages.

By the best way, in case you are utilizing Spring JMS services similar to AbstractMessageListenerContainer or DefaultMessageListenerContainer and have their sessionTransacted property as true, then each profitable onMessage() execution will acknowledge the message and assured redelivery in case of exception thrown.

11. How do you discover if a message is redelivered by JMS supplier?

JMSRedelivered property from Message header can be utilized by JMS supplier to point redelivery of a Message. Some JMS Suppliers additionally use, properties like supply Depend to point the variety of occasions a message is delivered if the supply Depend is greater than 1 than it may be used to determine if messages have been redelivered or not. Having mentioned that, it could doable that completely different JMS suppliers to point supply depend.

12. What occurs if a sturdy subscriber shouldn’t be operating? will JMS Server discard the message?

A sturdy subscription is created by the subscriber to make sure that it receives all of the messages printed by the writer, even through the interval when the Receiver is inactive or down. JMS Supplier or Dealer will retain all messages printed by a writer for a sturdy subscriber till messages get acknowledge or expired.

Every sturdy subscriber is understood by a novel title (Consumer id) and JMS Supplier retains a file of all these sturdy subscriptions to make sure message supply, even when they aren’t lively.

13. Does JMS Session object is thread-safe? Can we share JMS Session amongst a number of threads?

A Session object in JMS is a single-threaded context for creating message producers and customers. It isn’t thread-safe, and never suggested to share amongst a number of threads.

14. What’s JMS Selector? How does it work? Any instance of Utilizing JMS Selector?

JMS Selector is a filtering facility offered by JMS Supplier or dealer. Suppose a consumer is simply excited by listening to some particular messages and never all site visitors from Server than it may well both filter messages upon receiving, or it may well use JMS selector to do the filtering on Dealer itself. JMS Selector permits you to specify filtering standards within the type of String, which is a subset of SQL conditional expression.

For instance, in case you are excited by messages that are for shares begins with A, you may particular situation as SYMBOL like “A%”, the place SYMBOL is a user-defined Message property set by Sender.

Since JMS Selector can’t choose messages primarily based upon the content material of the message physique, it is the sender’s duty to populate an agreed Message Property for every message. Since choice is finished on the dealer facet, a JMS selector is offered to the dealer by the buyer whereas subscribing to a subject or listening to Queue.

After that, this client will solely obtain the message which passes the situation specified as a part of the JMS selector string. JMS Selector could be a useful function to implement load balancing, for instance, you may create a number of situations of your utility, every listening on a subset of shares, specified by JMS Selector.

15. Suppose your utility is speaking with one other utility utilizing JMS and sending and receiving XML messages. What’s going to you do to enhance efficiency?

Effectively, giant XML messages actually eat lots of bandwidth, when they’re transferred from consumer to dealer (JMS Supplier) and farther from dealer to recipient. You’ll be able to cut back this bandwidth by compressing messages earlier than sending it on the client-side.

Since XML messages compress so much, it is price doing on the client-side with the expense of some CPU time. Java even offers a compression facility in type of java.util.zip package deal. However keep in mind that compression and decompression on each the sender and receiver facet should use the identical algorithm.

Additionally, If you’re utilizing the PERSISTENT supply mode, then messages are continued on the server-side, earlier than delivering to customers, compressed messages take much less time and area on the server-side throughout persistence.

16. Which JMS Supplier have you ever labored with? Like IBM’s WMQ, Apache ActiveMQ, Sonic MQ, and so on

This messaging query is often requested firstly of the interview, to get an thought of whether or not you may have sensible expertise in JMS or not. If in case you have used JMS then, it should be through a JMS supplier like Websphere MQ from IBM or Tibco EMS. You’ll be able to reply this query primarily based upon your expertise with a selected JMS Supplier.

That is all on this checklist of Java Messaging and JMS Interview Questions and Solutions. Bear in mind messaging is among the essential matters in any Java interview and primarily based upon your expertise on completely different messaging know-how like Tibco RV, Tibco EMS, Websphere MQ, chances are you’ll be requested related questions.

Given JMS is a regular approach of dealing with messages amongst Java utility, good data of JMS fundamentals, messaging fundamentals, and prior expertise in utilizing JMS can actually make it easier to do to nicely in any Java J2EE interview.

Different Interview Questions Articles chances are you’ll wish to discover

  • 130+ Java Interview Questions from the final 5 years (questions)
  • 21 String Programming Interview Questions (questions)
  • Prime 10 Spring Framework Interview Questions with Solutions (see right here)
  • 25 Software program Design Interview Questions for Programmers (questions)
  • 50+ Knowledge Construction and Algorithms Issues from Interviews (questions)
  • 10 Hibernate Interview Questions for Java EE builders (see right here)
  • 20+ Linked Checklist Interview Questions for Java builders (checklist)
  • Prime 20 Java Design Sample Questions requested on Interviews (see right here)
  • 100+ Coding Issues and few tricks to crack interview (issues)
  • Overview these 50 Java questions earlier than interviews (assessment)
  • 10 SQL Question Interview Questions (SQL)
  • 10 JDBC Interview Questions for Java Programmers (questions)
  • 75 Programming Interview Questions with options (questions)
  • 15 Java NIO and Networking Interview Questions with Solutions (see right here)
  • 15 Knowledge Construction and Algorithm Questions from Java Interviews (learn right here)
  • Prime 10 Trick Java Interview Questions and Solutions (see right here)
  • 50+ Java Collections Interview Questions (see right here)
  • Prime 40 Core Java Cellphone Interview Questions with Solutions (checklist)

Thanks for studying this text thus far. In case you like these Java Generics and Collections interview questions then please share with your mates and colleagues. If in case you have any questions or suggestions then please drop a
observe.


P.S. –
If you’re new to Java world or need to be taught Java and in search of some on-line programs then I extremely suggest The Full Java Masterclass course by Tim Buchalaka on Udemy. It is probably the most up-to-date course and likewise covers every thing knowledgeable Java developer must know.  It is also very reasonably priced and you should buy in simply $10 on Udemy gross sales. 



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments