Created
September 27, 2011 16:42
-
-
Save acken/1245569 to your computer and use it in GitHub Desktop.
Rabbit enqueue
This file contains hidden or 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
| 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