JmsCategory

Introduction

JmsCategory is a groovy extension for the java jms api. It simplifies the usage of jms api by extending the api and doing all the resource handling stuff. JmsCategory extends the jms Interfaces and still allows the access to all jms api methods.

Examples

The following script sends a simple TextMessage:

import net.sf.gtools.jms.JmsCategory
import org.apache.activemq.ActiveMQConnectionFactory

@Grab(group='net.sf.gtools.jms', module='JmsCategory', version='0.2')
def sendMessage() {
  use(JmsCategory) {
    def jms = new ActiveMQConnectionFactory('tcp://localhost:61616')
    jms.connect { c ->
      c.queue("TEST-queue") { q ->
        def msg = createTextMessage("test")
        q.send(msg)
      }
    }
  }
}

sendMessage()

Receive a TextMessage:

jms.connect { c ->
  c.queue("TEST-queue") { q ->
    println q.receive().text
  }
}

Receive a TextMessage via Listener:

jms.connect { c ->
  c.queue("TEST-queue") { q ->
    q.listen { msg ->
      println "received message: $msg"
    }
    // endless loop
    while(true) {
      Thread.sleep(10)
    } 
  }
}

Using a Transaction:

jms.connect { c ->
  c.queue("TEST-queue", ["transacted": true]) { q ->
    q.send(createTextMessage("first message"))
    // critical code goes here
    q.send(createTextMessage("second message"))    
  }
}

Using a Selector:

jms.connect { c ->
  c.queue("TEST-queue", ['selector': "priority = 'important'"]) { q ->
    def m = q.receive(100)
  }
}

Installation via maven

Add this to your pom.xml:

<dependency>
    <groupId>net.sf.gtools.jms</groupId>
    <artifactId>JmsCategory</artifactId>
    <version>0.2</version>
</dependency>

Installation from Sourcecode

Download JmsCategory and attach the jar file to your classpath. You also have to attach the libraries of a jms client implementation (e.g. activemq).

Install via groovy grape:

License

JmsCategory is licensed under the LGPL.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.