Skip to content

Instantly share code, notes, and snippets.

@mplacona
Created July 28, 2012 21:36
Show Gist options
  • Save mplacona/3194899 to your computer and use it in GitHub Desktop.
Save mplacona/3194899 to your computer and use it in GitHub Desktop.
RabbitMQ ColdFusion "Add to queue example"
<cfscript>
QueueName = "QTransactions";
durable = true;
loadPaths = arrayNew(1);
loadPaths[1] = expandPath("lib/rabbitmq-java-client-bin-2.8.4/rabbitmq-client.jar");
// load jars
javaLoader = createObject("component", "lib.javaloader.JavaLoader").init(loadPaths);
// Create factory
factory = javaloader.create("com.rabbitmq.client.ConnectionFactory").init();
factory.setHost("127.0.0.1");
// Create properties
messageProperties = javaloader.create("com.rabbitmq.client.MessageProperties").init();
props = messageProperties.PERSISTENT_TEXT_PLAIN;
// Connect
connection = factory.newConnection();
channel = connection.createChannel();
// Declare queue
channel.QueueDeclare(QueueName, durable, false, false, createJavaNull());
// Create string
objStringByteArray = createByteArray("this is my CF message 12345");
// Publish
try{
channel.basicPublish("", QueueName, props, objStringByteArray);
}
finally{
// Close connection
channel.close();
connection.close();
}
</cfscript>
@mb-ahasan
Copy link

Do u have a sample of how to consume from the queue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment