You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by thufir <ha...@gmail.com> on 2015/03/09 17:12:31 UTC
groovy hello world with ActiveMQ for TomEE and OpenEJB
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
Re: groovy hello world with ActiveMQ for TomEE and OpenEJB
Posted by thufir <ha...@gmail.com>.
On 2015-03-09 01:46 PM, Thiago Veronezi wrote:
> Ops... replace "vm://localhost" by "tcp://localhost:61618" to use the
> broker created by tomee.:)
>
> []s,
> Thiago.
Interesting.
thanks,
Thufir
Re: groovy hello world with ActiveMQ for TomEE and OpenEJB
Posted by Thiago Veronezi <th...@veronezi.org>.
Ops... replace "vm://localhost" by "tcp://localhost:61618" to use the
broker created by tomee. :)
[]s,
Thiago.
On Mon, Mar 9, 2015 at 2:36 PM, Thiago Veronezi <th...@veronezi.org> wrote:
> 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 <ha...@gmail.com> 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
>>
>
>
Re: groovy hello world with ActiveMQ for TomEE and OpenEJB
Posted by Thiago Veronezi <th...@veronezi.org>.
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 <ha...@gmail.com> 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
>