public void AddConsumer(MessageConsumer consumer) { ConsumerId id = consumer.ConsumerId; // Registered with Connection before we register at the broker. consumers[id] = consumer; connection.addDispatcher(id, this); }
public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal) { if (destination == null) { throw new InvalidDestinationException("Cannot create a Consumer with a Null destination"); } ConsumerInfo command = CreateConsumerInfo(destination, selector); command.NoLocal = noLocal; ConsumerId consumerId = command.ConsumerId; MessageConsumer consumer = null; // Registered with Connection before we register at the broker. connection.addDispatcher(consumerId, this); try { consumer = new MessageConsumer(this, command); // lets register the consumer first in case we start dispatching messages immediately consumers[consumerId] = consumer; this.Connection.SyncRequest(command); if (this.Started) { consumer.Start(); } return(consumer); } catch (Exception) { if (consumer != null) { consumer.Close(); } throw; } }