Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Last active December 13, 2015 16:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanguill/4942173 to your computer and use it in GitHub Desktop.
Save ryanguill/4942173 to your computer and use it in GitHub Desktop.
the simple example for rabbitmq I set up. rabbitmq configuration was out-of-box, no changes, running on a virtualbox centos 6.3 vm with a gig of ram. Example of results:100000 messages sent in 13847 ms ( 7221.78089117 messages/second ). 100000 messages received in 20865 ms. ( 4792.71507309 messages/second )
<!---
--- NOTE: YOU NEED THE JAVA LIBRARY FROM HERE: http://www.rabbitmq.com/java-client.html
--- http://www.rabbitmq.com/tutorials/tutorial-one-java.html
--- https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/java/Recv.java
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
public class Recv {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
}
--->
<cfset v = variables/>
<cfset v.starttc = getTickCount()/>
<cfset v.QUEUE_NAME = "cf_test"/>
<cfset v.factory = createObject("java", "com.rabbitmq.client.ConnectionFactory").init()/>
<cfset v.factory.setUsername("username") />
<cfset v.factory.setPassword("password") />
<cfset v.factory.setHost("host ip or hostname")/>
<cfset v.connection = v.factory.newConnection()/>
<cfset v.channel = v.connection.createChannel()/>
<cfset v.channel.queueDeclare(v.QUEUE_NAME, true, false, false, javaCast('null', 0))/>
<cfset v.consumer = createObject("java","com.rabbitmq.client.QueueingConsumer").init(v.channel) />
<cfset v.channel.basicConsume(v.QUEUE_NAME, false, v.consumer) />
<cfset v.continue = true />
<cfset v.counter = 0 />
<cfset v.lastDeliveryTag = "" />
<cfoutput>
<cfloop condition="#v.continue#">
<cfset v.delivery = v.consumer.nextDelivery(1000) />
<cfif isDefined("v.delivery")>
<cfset v.counter++ />
<cfset v.message = createObject("java","java.lang.String").init(v.delivery.getBody()) />
<cfset v.lastDeliveryTag = v.delivery.getEnvelope().getDeliveryTag() />
<cfset v.channel.basicAck(v.delivery.getEnvelope().getDeliveryTag(),false) />
<!---
<cfif v.counter MOD 100 EQ 0>
Message: #v.counter#: #v.message#<br />
</cfif>
--->
<cfelse>
<cfset v.continue = false />
</cfif>
<cfif v.counter MOD 1000 EQ 0>
#v.counter# - #(v.counter / (getTickCount() - v.starttc)) * 1000# messages/second<br />
<cfflush />
</cfif>
</cfloop>
<!---
<cfif len(trim(v.lastDeliveryTag))><!--- if we didnt get a single message, this wouldnt be there --->
<cfset v.channel.basicAck(v.lastDeliveryTag,true) />
acking tag: #v.lastDeliveryTag#<br />
</cfif>
--->
<cfset v.channel.close()/>
<cfset v.connection.close()/>
<cfset v.totalTime = getTickCount() - v.starttc/>
<hr />
#v.counter# messages received in #v.totalTime# ms. ( #(v.counter / v.totalTime) * 1000# messages/second )<br />
</cfoutput>
<!---
--- NOTE: YOU NEED THE JAVA LIBRARY FROM HERE: http://www.rabbitmq.com/java-client.html
---http://www.rabbitmq.com/tutorials/tutorial-one-java.html
---https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/java/Send.java
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
--->
<cfoutput>
<cfset v = variables />
<cfset v.messagesToSend = 100000 />
<cfset v.starttc = getTickCount() />
<cfset v.QUEUE_NAME = "cf_test" />
<cfset v.factory = createObject("java","com.rabbitmq.client.ConnectionFactory").init() />
<cfset v.factory.setUsername("username") />
<cfset v.factory.setPassword("password") />
<cfset v.factory.setHost("host ip or hostname")/>
<cfset v.connection = v.factory.newConnection() />
<cfset v.channel = v.connection.createChannel() />
<cfset v.messagePropertiesEnum = createObject("java","com.rabbitmq.client.MessageProperties") />
<cfset v.channel.queueDeclare(v.QUEUE_NAME, true, false, false, javaCast('null', 0)) />
<cfset v.channel.basicQos(1) />
<cfloop from="1" to="#v.messagesToSend#" index="v.i">
<cfset v.message = "#v.i#: Hello from ColdFusion! #now()#" />
<cfset v.channel.basicPublish("", v.QUEUE_NAME, v.messagePropertiesEnum.PERSISTENT_TEXT_PLAIN, v.message.getBytes()) />
<cfif v.i mod 1000 eq 0>
#v.i# - #(v.i / (getTickCount() - v.starttc)) * 1000# messages/second<br />
<cfflush />
</cfif>
</cfloop>
<cfset v.channel.close() />
<cfset v.connection.close() />
<cfset v.totalTime = getTickCount() - v.starttc />
#variables.messagesToSend# messages sent in #v.totalTime# ms ( #(v.messagesToSend / v.totalTime) * 1000# messages/second ).
</cfoutput>
<cfinclude template="receive-test.cfm" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment