Hi,
I managed to run this from a TomEE. [Based on
http://activemq.apache.org/hello-world.html]
No need to load libs.
[]s,
Thiago.
...
import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.DeliveryMode
import javax.jms.Session
import javax.jms.TextMessage
// Create a ConnectionFactory
def connectionFactory = new ActiveMQConnectionFactory("vm://localhost")
def consumerTr = Thread.start({
// Create a Connection
def connection = connectionFactory.createConnection()
connection.start()
// Create a Session
def session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
// Create the destination (Topic or Queue)
def destination = session.createQueue("TEST.FOO")
// Create a MessageConsumer from the Session to the Topic or Queue
def consumer = session.createConsumer(destination)
// Wait for a message
def message = consumer.receive(1000)
if (message instanceof TextMessage) {
System.out.println("Received: ${message.text}")
} else {
System.out.println("Received: ${message}")
}
consumer.close()
session.close()
connection.close()
})
Thread.start {
// Create a Connection
def connection = connectionFactory.createConnection()
connection.start()
// Create a Session
def session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
// Create the destination (Topic or Queue)
def destination = session.createQueue("TEST.FOO")
// Create a MessageProducer from the Session to the Topic or Queue
def producer = session.createProducer(destination)
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT)
// Create a messages
def text = "Hello world! From: ${Thread.currentThread().name} :
${this.hashCode()}"
def message = session.createTextMessage(text)
// Tell the producer to send the message
System.out.println("Sent message: ${message.hashCode()} :
${Thread.currentThread().name}")
producer.send(message)
// Clean up
session.close()
connection.close()
}
consumerTr.join()
...
On Mon, Mar 9, 2015 at 12:12 PM, thufir <[email protected]> wrote:
> For this producer:
>
> |@Grapes([
> @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory',
> version= '0.2'),
> @Grab(group = 'org.apache.activemq', module =
> 'activemq-all', version= '5.9.0'),
> @Grab(group = "junit", module = "junit", version= "4.11"),
> @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory',
> version= '0.2'),
> @Grab(group = 'org.apache.activemq', module =
> 'activemq-all', version= '5.9.0'),
> @Grab(group = "junit", module = "junit", version= "4.11"),
> @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory',
> version= '0.2'),
> @Grab(group = 'org.apache.activemq', module =
> 'activemq-all', version= '5.9.0'),
> @Grab(group = "junit", module = "junit", version= "4.11"),
> @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory',
> version= '0.2'),
> @Grab(group = 'org.apache.activemq', module =
> 'activemq-all', version= '5.9.0'),
> @Grab(group = "junit", module = "junit", version= "4.11")
> ])
> import net.sf.gtools.jms.JmsCategory
> import org.apache.activemq.ActiveMQConnectionFactory
>
> class GroovyJMSExample {
> def static 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)
> }
> }
> }
> }
>
> static void main(String[] args) {
> sendMessage()
> }
> }|
>
>
>
>
> http://stackoverflow.com/a/28941062/262852
>
>
> it will work fine with either OpenEJB or TomEE because both use ActiveMQ?
>
>
>
> thanks,
>
> Thufir
>