Example #1
0
		public void AddSubscription(ServerSideSubscription subscription)
		{
			lock (_lockObject)
			{
				_subscriptions.Add(subscription);
			}
		}
Example #2
0
		public void RemoveSubscription(ServerSideSubscription subscription)
		{
			lock (_lockObject)
			{
				_subscriptions.Remove(subscription);
			}
		}
		private void HandleSubscribeCommand(StompFrame frame)
		{
			var id = frame.Headers[StompHeader.Id];
			var destination = frame.Headers[StompHeader.Destination];
			var ack = frame.Headers[StompHeader.Ack];

			if (string.IsNullOrEmpty(id))
			{
				var errorFrame = StompFrameUtils.CreateMissingHeaderError(StompHeader.Id, frame);
				SendFrame(errorFrame);
				Disconnect();
				return;
			}

			if (string.IsNullOrEmpty(destination))
			{
				var errorFrame = StompFrameUtils.CreateMissingHeaderError(StompHeader.Destination, frame);
				SendFrame(errorFrame);
				Disconnect();
				return;
			}

			if (_subscriptions.ContainsKey(id))
			{
				var message = "Subscription already exists: " + id;
				var errorFrame = StompFrameUtils.CreateErrorFrame(message, frame);
				SendFrame(errorFrame);
				Disconnect();
				return;
			}

			var messageQueue = _serverData.FindMessageQueue(destination);

			var subscription = new ServerSideSubscription(this, id, messageQueue, ack);
			_subscriptions.Add(id, subscription);
			SendReceiptIfNecessary(frame);

		}