コード例 #1
0
 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);
             }
         }
     }
 }
コード例 #2
0
 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;
             }
         }
     }
 }
コード例 #3
0
        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;
        }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 public void Publish(string topic, string message)
 {
     RabbitMQUtils.DeclareExchange(topic, channel.Value);
     RabbitMQUtils.Publish(topic, message, this.channel.Value);
 }