1. jms-spec
  2. JMS_SPEC-134

Declarative Annotation Based JMS Listeners


    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:


      MDB is currently the only declarative way of listening for JMS messages. While the MDB model is adequate, it has a few shortcomings (primarily related to it's true age). The first is that since it is rather generic to JCA, it makes the syntax less than ideal for JMS (ironically, the vast majority of MDB use is for JMS). The MDB model is highly coupled to the EJB component model, which makes generic use in managed beans needlessly difficult. Lastly and perhaps most importantly, reimaging the MDB model using CDI/annotations in a manner specific to JMS introduces the possibility of significant usability improvements/API modernization.

      It is perhaps best to demonstrate these concepts using some simple code examples:

      @Pooled // Documented here:
      public class MyListenerComponent {
        @JmsListener(destinationLookup="...", clientId="...", subsciptionName="...", messageSelector="...", ...)
        public void listen (Message message) {
      @MaxConcurrency(...) // Documented here:
      public class MyListenerComponent {
        public void listen (String message) { // Message payload automatically type-checked and unwrapped
      @RequestScoped // A message received is a "request"
      public class MyListenerComponent {
        // Message payload automatically type-checked and unwrapped, 
        // message contents automatically injected, type-checked, unwrapped.
        public void listen (byte[] message, 
                            @JmsMessageProperty boolean myFlag, 
                            @JmsMessageProperty("myFlag2") boolean myFlag2,
                            @JmsCorrelationId String myCorrelationId,
                            ) {
      public class MyListenerComponent {
        @JmsListener(destinationLookup="...", batchSize="...", retry="...", retryDelay="...", ...) 
        // Batch delivery, retry, retry delay, DLQ, etc new features.
        public void listen (Message... messages) {

      As suggested in the examples above, decoupling from the EJB component model also allows for a great deal of flexibility in putting together the component life-cycle, programming model, features and re-use.

      Although I am entering this in JMS as I feel it is the correct place to get this done, I assume that this body of work will require a great deal of collaboration with the EJB, CDI and platform expert groups.

      Do let me know if anything needs to be explained further - I am happy to help.

      Please note that these are purely my personal views and certainly not of Oracle's as a company.

        Issue Links



            • Assignee:
            • Votes:
              11 Vote for this issue
              2 Start watching this issue


              • Created: