Created
July 28, 2012 21:34
-
-
Save mplacona/3194895 to your computer and use it in GitHub Desktop.
RabbitMQ C# "Add to queue example"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Declare queue name. This can be anything you like | |
string QueueName = "QTransactions"; | |
// Create a new connection factory for the queue | |
var factory = new ConnectionFactory(); | |
// Because Rabbit is installed locally, we can run it on localhost | |
factory.HostName = "127.0.0.1"; | |
using (IConnection connection = factory.CreateConnection()) | |
using (IModel channel = connection.CreateModel()) | |
{ | |
// mark all messages as persistent | |
const bool durable = true; | |
channel.QueueDeclare(QueueName, durable, false, false, null); | |
// Set delivery mode (1 = non Persistent | 2 = Persistent) | |
IBasicProperties props = channel.CreateBasicProperties(); | |
props.DeliveryMode = 2; | |
string msg = args[0]; | |
byte[] body = System.Text.Encoding.UTF8.GetBytes(msg); | |
channel.BasicPublish("", QueueName, props, body); | |
Console.WriteLine(" [x] Sent {0}", msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment