public RabbitMQConsumer(string host, int port, string username, string password, string exchangeName, string queueName, string routingKey) { _queueName = queueName; _rabbitConnection = RabbitMQUtility.CreateConnection(host, port, username, password); _subscribeModel = _rabbitConnection.CreateModel(); _subscribeModel.QueueBind(_queueName, exchangeName, routingKey); }
public RabbitMQPublisher(string host, int port, string username, string password, bool isPersistent = true) { _rabbitConnection = RabbitMQUtility.CreateConnection(host, port, username, password); _publishModel = _rabbitConnection.CreateModel(); _basicProperties = _publishModel.CreateBasicProperties(); _basicProperties.Persistent = isPersistent; _addresses = new Dictionary <string, PublicationAddress>(); }
public bool pushToQueue <T>(string routingKey, T data) { try { _publishModel.BasicPublish(_addresses[routingKey], _basicProperties, RabbitMQUtility.ConvertToBinary(data)); return(true); } catch { return(false); } }
public void Init <T>(Func <T, bool> Handler) { _consumer = new EventingBasicConsumer(_subscribeModel); _consumer.Received += (sender, msg) => { T data = RabbitMQUtility.Deserialize <T>(msg.Body.ToArray()); if (data != null) { if (Handler(data)) { _subscribeModel.BasicAck(msg.DeliveryTag, false); } } }; }