public void Start(int maximumConcurrencyLevel) { startSubscriptionThread = new Thread(() => { foreach (var tuple in events.GetConsumingEnumerable()) { var messageReceiver = Builder.Build <IMessageReceiver>(); Address address = Address.Parse(String.Format("topic://{0}/EVENTS/#/{1}/#", WebSphereMqAddress.GetQueueName(tuple.Item2), tuple.Item1.FullName)); var consumerSatellite = new EventConsumerSatellite(messageReceiver, address, tuple.Item1.FullName); messageReceiver.Init(address, settings, tryProcessMessage, endProcessMessage, consumerSatellite.CreateConsumer); satellites.Add(consumerSatellite); Logger.InfoFormat("Starting receiver for [{0}] subscription.", address); consumerSatellite.Start(maximumConcurrencyLevel); } }) { IsBackground = true }; startSubscriptionThread.SetApartmentState(ApartmentState.MTA); startSubscriptionThread.Name = "Start WebSphereMq Subscription Listeners"; startSubscriptionThread.Start(); }
public void Unsubscribe(Type eventType, Address publisherAddress) { EventConsumerSatellite consumerSatellite = satellites.Find( consumer => consumer.InputAddress == publisherAddress && consumer.EventType == eventType.FullName); if (consumerSatellite == null) { return; } consumerSatellite.Stop(); satellites.Remove(consumerSatellite); var connection = factory.GetPooledConnection(); using (ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge)) { session.Unsubscribe(eventType.FullName); session.Close(); } }