Exemplo n.º 1
0
        public async Task Connect()
        {
            await Task.Run(() =>
            {
                try
                {
                    this._Connection = _RabbitMQOptions.ConnectionFactory.CreateConnection();

                    this._PublishModel   = this._Connection.CreateModel();
                    this._SubscribeModel = this._Connection.CreateModel();

                    this._PublishModel.ExchangeDeclare(this._RabbitMQOptions.ExchangeName, ExchangeType.Fanout, durable: true);
                    this._SubscribeModel.QueueDeclare(this._QueueName, durable: false, exclusive: false, autoDelete: true, arguments: new Dictionary <string, object>());
                    this._SubscribeModel.QueueBind(this._QueueName, this._RabbitMQOptions.ExchangeName, string.Empty);

                    var consumer       = new EventingBasicConsumer(this._SubscribeModel);
                    consumer.Received += Consumer_ReceivedAsync;
                    this._SubscribeModel.BasicConsume(this._QueueName, autoAck: false, consumer);
                }
                catch (Exception ex)
                {
                    RabbitMQLog.ConnectionFailed(this._Logger, ex);
                }
            });
        }
Exemplo n.º 2
0
 public Task UnSubscribeUser(HubConnectionContext connection)
 {
     return(Task.Run(() =>
     {
         _Users.TryRemove(connection.UserIdentifier, out HubConnectionContext value);
         RabbitMQLog.Unsubscribe(_Logger, "UnSubscribeUser:" + connection.ConnectionId);
     }));
 }
Exemplo n.º 3
0
 public Task SubscribeToUser(HubConnectionContext connection)
 {
     return(Task.Run(() =>
     {
         _Users.TryAdd(connection.UserIdentifier, connection);
         RabbitMQLog.Subscribing(_Logger, "SubscribeToUser:" + connection.ConnectionId);
     }));
 }
Exemplo n.º 4
0
 public Task UnSubscribeConnection(HubConnectionContext connection)
 {
     return(Task.Run(() =>
     {
         _Connections.TryRemove(connection.ConnectionId, out HubConnectionContext value);
         RabbitMQLog.Unsubscribe(_Logger, "UnSubscribeConnection:" + connection.ConnectionId);
     }));
 }
Exemplo n.º 5
0
 public Task SubscribeToConnection(HubConnectionContext connection)
 {
     return(Task.Run(() =>
     {
         _Connections.TryAdd(connection.ConnectionId, connection);
         RabbitMQLog.Subscribing(_Logger, "SubscribeToConnection:" + connection.ConnectionId);
     }));
 }
Exemplo n.º 6
0
        public async Task SubscribeToUser(HubConnectionContext connection)
        {
            await _UserLock.WaitAsync();

            try
            {
                HubConnectionStore subscription = this._Users.GetOrAdd(connection.UserIdentifier, _ => new HubConnectionStore());
                subscription.Add(connection);
                RabbitMQLog.Subscribing(_Logger, "SubscribeToUser:" + connection.ConnectionId);
            }
            finally
            {
                _UserLock.Release();
            }
        }
Exemplo n.º 7
0
        public async Task UnSubscribeUser(HubConnectionContext connection)
        {
            await _UserLock.WaitAsync();

            try
            {
                if (_Users.TryGetValue(connection.UserIdentifier, out var subscription))
                {
                    subscription.Remove(connection);
                    RabbitMQLog.Unsubscribe(_Logger, "UnSubscribeUser:" + connection.ConnectionId);
                }
            }
            finally
            {
                _UserLock.Release();
            }
        }