private void InnerUnsubscribeTopic(string topic) { if (this.topics.ContainsKey(topic)) { lock (topicsLocker) { if (this.topics.TryRemove(topic, out bool value)) { RabbitMQUtils.UnbindQueueFromExchange(this.queueName, topic, this.Channel.Value); } } } }
private void InnerSubscribeTopic(string topic) { if (!this.topics.ContainsKey(topic)) { lock (topicsLocker) { if (!this.topics.ContainsKey(topic)) { RabbitMQUtils.DeclareExchange(topic, this.Channel.Value); RabbitMQUtils.BindQueueToExchange(this.queueName, topic, this.Channel.Value); this.topics[topic] = true; } } } }
private void DeclareQueueAndRegisterConsumer() { this.queueName = RabbitMQUtils.DeclareQueue(this.Channel.Value); var consumer = new EventingBasicConsumer(Channel.Value); consumer.Received += (object model, BasicDeliverEventArgs eventArgs) => { try { var message = Encoding.UTF8.GetString(eventArgs.Body); RaiseOnMessage(new PubSubMessage(eventArgs.Exchange, message)); } catch (Exception ex) { EventLogger.WriteError($"Error handling Rabbit consumer event for queue: {this.queueName}. Cache invalidation skipped."); EventLogger.WriteError(ex); } }; RabbitMQUtils.BasicConsume(this.queueName, consumer, this.Channel.Value); this.consumerTag = consumer.ConsumerTag; }
public void Dispose() { if (this.Channel.IsValueInitialized) { Action job = () => { if (this.consumerTag != null) { RabbitMQUtils.BasicCancel(this.consumerTag, this.Channel.Value); } if (this.queueName != null) { RabbitMQUtils.DeleteQueue(this.queueName, this.Channel.Value); } }; executor.AddJob(job); } }
public void Publish(string topic, string message) { RabbitMQUtils.DeclareExchange(topic, channel.Value); RabbitMQUtils.Publish(topic, message, this.channel.Value); }