[groovy-user] JMS usage 101

100 views
Skip to first unread message

thufir

unread,
Mar 9, 2015, 5:16:04 AM3/9/15
to us...@groovy.codehaus.org
I know that this fails to connect to glassfish (or activemq), I'll
figure that out, but, is this how to use JMS in groovy? I saw that
there was a special JMS groovy project, just wasn't sure whether it's
being used.



thufir@doge:~$
thufir@doge:~$ groovy -v
Groovy Version: 2.4.1 JVM: 1.7.0_75 Vendor: Oracle Corporation OS: Linux
thufir@doge:~$
thufir@doge:~$ java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~utopic1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
thufir@doge:~$
thufir@doge:~$ groovy IdeaProjects/groovy/src/hi.groovy
Caught: javax.jms.JMSException: Cannot send, channel has already failed:
tcp://127.0.0.1:3700
javax.jms.JMSException: Cannot send, channel has already failed:
tcp://127.0.0.1:3700
at
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:72)
at
org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1423)
at
org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1510)
at
org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:524)
at net.sf.gtools.jms.JmsCategory.connect(JmsCategory.groovy:64)
at GroovyJMSExample$_sendMessage_closure1.doCall(hi.groovy:21)
at GroovyJMSExample$_sendMessage_closure1.doCall(hi.groovy)
at GroovyJMSExample.sendMessage(hi.groovy:19)
at GroovyJMSExample.main(hi.groovy:31)
Caused by: org.apache.activemq.transport.InactivityIOException: Cannot
send, channel has already failed: tcp://127.0.0.1:3700
at
org.apache.activemq.transport.AbstractInactivityMonitor.doOnewaySend(AbstractInactivityMonitor.java:297)
at
org.apache.activemq.transport.AbstractInactivityMonitor.oneway(AbstractInactivityMonitor.java:286)
at
org.apache.activemq.transport.TransportFilter.oneway(TransportFilter.java:85)
at
org.apache.activemq.transport.WireFormatNegotiator.oneway(WireFormatNegotiator.java:104)
at
org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:68)
at
org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81)
at
org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86)
at
org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1394)
... 7 more
thufir@doge:~$



code:

@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")
importnet.sf.gtools.jms.JmsCategory
@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")
importnet.sf.gtools.jms.JmsCategory
importorg.apache.activemq.ActiveMQConnectionFactory

classGroovyJMSExample {
def staticsendMessage() {
use(JmsCategory) {
defjms =newActiveMQConnectionFactory('tcp://localhost:3700')
jms.connect { c ->
c.queue("TEST-queue") { q ->
defmsg = createTextMessage("test")
q.send(msg)
}
}
}
}

static voidmain(String[] args) {
sendMessage()
}
}


gist for the project from IDEA:

https://gist.github.com/THUFIR/c92cc120249f322546e6


I copied this code from:

stackoverflow.com/q/19680276/262852

(all I did was to make the method static so that it would run.)


thanks,

Thufir



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


thufir

unread,
Mar 9, 2015, 7:31:02 AM3/9/15
to us...@groovy.codehaus.org
I've googled on this error message, and don't know quite what to make of
it. In any event, some better code:

thufir@doge:~$
thufir@doge:~$ activemq status
INFO: Loading '/home/thufir/apache-activemq-5.11.1/bin/env'
INFO: Using java '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'
ActiveMQ not running
thufir@doge:~$
thufir@doge:~$ activemq start
INFO: Loading '/home/thufir/apache-activemq-5.11.1/bin/env'
INFO: Using java '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and
log4j.properties to get details
INFO: pidfile created :
'/home/thufir/apache-activemq-5.11.1/data/activemq.pid' (pid '18920')
thufir@doge:~$
thufir@doge:~$ activemq status
INFO: Loading '/home/thufir/apache-activemq-5.11.1/bin/env'
INFO: Using java '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'
ActiveMQ is running (pid '18920')
thufir@doge:~$
thufir@doge:~$ groovy IdeaProjects/groovy/src/jms.groovy
Caught: org.apache.activemq.ConnectionFailedException: The JMS
connection has failed: java.io.EOFException
org.apache.activemq.ConnectionFailedException: The JMS connection has
failed: java.io.EOFException
at
org.apache.activemq.ActiveMQConnection.checkClosedOrFailed(ActiveMQConnection.java:1480)
at
org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:523)
at net.sf.gtools.jms.JmsCategory.connect(JmsCategory.groovy:64)
at GroovyJMSExample$_sendMessage_closure1.doCall(jms.groovy:22)
at GroovyJMSExample$_sendMessage_closure1.doCall(jms.groovy)
at GroovyJMSExample.sendMessage(jms.groovy:20)
at GroovyJMSExample.main(jms.groovy:32)
Caused by: java.io.EOFException
at
org.apache.activemq.openwire.v10.BaseDataStreamMarshaller.looseUnmarshalConstByteArray(BaseDataStreamMarshaller.java:602)
at
org.apache.activemq.openwire.v10.WireFormatInfoMarshaller.looseUnmarshal(WireFormatInfoMarshaller.java:130)
at
org.apache.activemq.openwire.OpenWireFormat.doUnmarshal(OpenWireFormat.java:373)
at
org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:285)
at
org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:221)
at
org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:213)
at
org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
thufir@doge:~$
thufir@doge:~$ cat IdeaProjects/groovy/src/hi.groovy
cat: IdeaProjects/groovy/src/hi.groovy: No such file or directory
thufir@doge:~$
thufir@doge:~$ cat IdeaProjects/groovy/src/jms.groovy
@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:3700')
jms.connect { c ->
c.queue("TEST-queue") { q ->
def msg = createTextMessage("test")
q.send(msg)
}
}
}
}

static void main(String[] args) {
sendMessage()
}
}
thufir@doge:~$


adapted from:

http://stackoverflow.com/questions/19680276/

thufir

unread,
Mar 9, 2015, 7:49:22 AM3/9/15
to us...@groovy.codehaus.org
Sorry to spam the list, I went back to the original:

http://stackoverflow.com/a/28941062/262852

and changed to the port used in the example, 61616, instead of 3700 as I
was using. It runs cleanly, albeit without output:

thufir@doge:~$
thufir@doge:~$ activemq status
INFO: Loading '/home/thufir/apache-activemq-5.11.1/bin/env'
INFO: Using java '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'
ActiveMQ is running (pid '18920')
thufir@doge:~$
thufir@doge:~$ groovy IdeaProjects/groovy/src/jms.groovy
thufir@doge:~$



-Thufir
Reply all
Reply to author
Forward
0 new messages