Skip to content

Instantly share code, notes, and snippets.

@acken
Created September 27, 2011 16:42
Show Gist options
  • Select an option

  • Save acken/1245569 to your computer and use it in GitHub Desktop.

Select an option

Save acken/1245569 to your computer and use it in GitHub Desktop.
Rabbit enqueue
using System;
using RabbitMQ.Client;
using RabbitMQ.Client.MessagePatterns;
using RabbitMQ.Client.Framing.v0_9;
using System.Threading;
using System.Text;
namespace SladrehankEnqueuer.Core
{
public class Enqueuer
{
private IConnection _connection;
private IModel _channel;
private bool _stop = false;
public void Start()
{
ConnectionFactory cf = new ConnectionFactory();
cf.Address = "127.0.0.1";
_connection = cf.CreateConnection();
_channel = _connection.CreateModel();
var client = new SimpleRpcClient(_channel, "SladrehankEnqueuer");
client.TimeoutMilliseconds = 5000;
_channel.ExchangeDeclare("gluon_exchange", ExchangeType.Direct);
_channel.QueueDeclare("SladrehankQueue");
_channel.QueueBind("SladrehankQueue", "gluon_exchange", "gluon", false, null);
}
public void Stop()
{
_channel.Close(Constants.ReplySuccess, "Closing the channel");
_connection.Close(Constants.ReplySuccess, "Closing the connection");
}
public void Enqueue(string message)
{
_channel.BasicPublish("gluon_exchange", "gluon", null, Encoding.UTF8.GetBytes(message));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment