This docs is for v0.2+

Changes

v0.2

  1. It is no longer a mandatory to provide a JMS ConnectionFactory. For a single JVM simple usage, you may use the default in-memory, non-persistent ActiveMQ connection factory, or you could configure your JMSProvider in several ways.
  2. The library is no longer used as a Groovy Category. The Groovy Category are hidden. There are a few different ways to use:
    // 1
    jms{ //require static import of groovy.jms.JMS.jms
     // your jms code
    }
    
    // 2
    def jms = new JMS(){
     // your jms code
    }
    
    // and for further execution
    jms.run{
     // more jms code
    }
    
    
    // 3
    def jms = new JMS()
     jms.xxx ; // this is for using the Groovy Messaging Service API
     jms.close() //must be closed manually if JMS code are not executed in the JMS Context♠
    
  3. The base Category API are slightly modified and are refactored to the JMSCoreCategory. Two sets of new APIs: GroovyJMS API and Groovy Messaging Service API are provided. The latter are designed base on the Groovy Sql.

Usage

Concepts

JMS Connection Factory

To use GroovyJMS, you need to decide which JMS implementation you'll use. There are several options:

  1. use the default in-memory, not-persistent ActiveMQ broker and connection factory, this is created by the ActiveMQJMSProvider class. Notice that the ActiveMQJMSProvider will start a ActiveMQ broker if it is not existed already, and will add a "vm://localhost" transport connector URL if not existed. In this case, the syntax is as simple as:
    new JMS(){
     // your jms code
    }
    
  2. Provide a JMSProvider by
    1. specific a "groovy.jms.provider" system property that point to a class that implements groovy.jms.provider.JMSProvider
    2. set a JMSProvider to the JMS.provider static variable, e.g.
      JMS.provider = { return new ActiveMQConnectionFactory("vm://localhost") } as JMSProvider
      
  3. Provide Connection Factory or Connection in runtime. it is the most recommended approach. You may utilize your JEE container or dependency injection framework to inject the required JMS resources to your class, and support the connection or factory to GroovyJMS.
    def myConnection; //injected
    new JMS( myConnection ){
     // your jms code
    }
    
    // OR
    def myConnectionFactory; //injected
    new JMS( myConnectionFactory){
     // your jms code
    }
    

So how cool is GroovyJMS in compare to JMS?

Other important information

Unsupported Features or Limitation