<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19120">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Hi there,</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>I came across an interesting issue that I was
hoping someone could help me with.</FONT></DIV>
<DIV><FONT size=2 face=Arial>I think its related to Channel thread-safety.
Here's the issue.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>I want to create an lightweight web service
endpoint using Gretty that sends (json) messages to rabbitmq.</FONT></DIV>
<DIV><FONT size=2 face=Arial>It works, but when i benchmark it with 'ab -n
1000 -c 100 <A href="http://x.x.x.x/'">http://x.x.x.x/'</A> there are 1003
messages in the queue!</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Gretty relies on Netty (<A
href="http://www.jboss.org/netty">http://www.jboss.org/netty</A>) which is an
asynchronous event-driven framework that uses NIO.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>I've included the (working, no error) Gretty code
below. Could I ask for your insight as to why there are more messages in
the queue than the producer (ab) sent?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Thanks for your time,</FONT></DIV>
<DIV><FONT size=2 face=Arial>Burt Prior</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>server.groovy:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>import org.mbte.gretty.httpserver.*</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>//<BR>// server.groovy<BR>// web service endpoint
for activity requests<BR>// 9/15/11: bprior<BR>//<BR>// $ groovy
server.groovy<BR>//<BR>// then try benchmark:<BR>// $ ab -n 1000 -c 100 <A
href="http://192.168.1.129:8080/">http://192.168.1.129:8080/</A><BR>//</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>import
com.rabbitmq.client.ConnectionFactory;<BR>import
com.rabbitmq.client.Connection;<BR>import
com.rabbitmq.client.Channel;</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>@GrabResolver(name='gretty',
root='http://groovypp.artifactoryonline.com/groovypp/libs-releases-local')<BR>@Grab('org.mbte.groovypp:gretty:0.4.279')</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>@Grab(group='com.rabbitmq', module='amqp-client',
version='2.6.1')</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>ConnectionFactory factory = new
ConnectionFactory();<BR>factory.setHost("dallas");<BR>Connection connection =
factory.newConnection();<BR>Channel channel =
connection.createChannel();</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>channel.queueDeclare("hello", false, false, false,
null);</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>GrettyServer server = []<BR>server.groovy =
[<BR> localAddress: new InetSocketAddress("dallas", 8080),<BR>
defaultHandler: {<BR> response.redirect
"/"<BR> },<BR> "/:name": {<BR> get
{<BR> String message = "{msg:
{actorId:\"bprior\",actorType:\"PERSON\"}}";<BR> <BR> channel.basicPublish("",
"hello", null, message.getBytes());<BR> //response.text =
"Hello
${request.parameters['name']}"<BR> }<BR> }<BR>]<BR>server.start()<BR>println
"factory:"+factory<BR>println "server started..."</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV></BODY></HTML>