public ServiceBusRuntime(IServiceLocator serviceLocator) { try { serviceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; } catch (NullReferenceException) // 1.0 throws null ref exception if no provider delegate is set. { } if (serviceLocator == null) { serviceLocator = SimpleServiceLocator.With(new Delivery.DirectDeliveryCore()); // default to simple service locator with direct message delivery } _serviceLocator = serviceLocator; attachServices(); _subscriptionEndpoint = new SubscriptionEndpoint(Guid.Empty, "Subscription endpoint", null, null, (Type)null, new SubscriptionDispatcher(() => this.ListSubscriptions(true)), new PredicateMessageFilter(pr => false), true, null); _correlatorEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "Correlator", null, null, (Type)null, new ActionDispatcher((se, md) => { _correlator.Reply((string)md.Context[MessageDelivery.CorrelationId], md); }), new PredicateMessageFilter(pr => pr.Context.ContainsKey(MessageDelivery.CorrelationId)), true, null); Subscribe(_subscriptionEndpoint); Subscribe(_correlatorEndpoint); }
public void RemoveSubscription(SubscriptionEndpoint subscription) { if (_disposed) { throw new ObjectDisposedException("ServiceBusRuntime"); } if (subscription == null) { throw new ArgumentNullException("subscription"); } bool removed = false; try { using (TransactionScope ts = new TransactionScope()) { subscription.Dispatcher.StopInternal(); _subscriptions.Write(subscriptions => { subscriptions.Remove(subscription); subscription.Dispatcher.Runtime = null; removed = true; }); foreach (RuntimeService service in ServiceLocator.GetAllInstances <RuntimeService>()) { service.OnSubscriptionRemoved(subscription); } EventHandler <EndpointEventArgs> unsubscribedEvent = SubscriptionRemoved; if (unsubscribedEvent != null) { unsubscribedEvent(this, new EndpointEventArgs(subscription)); } ts.Complete(); } } catch { if (removed) { // Re-add subscription on failure _subscriptions.Write(subscriptions => { subscriptions.Add(subscription); }); } throw; } }
void deliverToSubscriptionEndpoint(TimeSpan timeout, PublishRequest publishRequest) { SubscriptionEndpoint se = _subscriptionEndpoint; publishRequest = PublishRequest.Copy(publishRequest, new KeyValuePair <MessageDeliveryContextKey, object>(MessageDelivery.PublishRequestId, publishRequest.PublishRequestId)); using (TransactionScope ts = new TransactionScope()) { MessageDelivery md = new MessageDelivery(Guid.NewGuid().ToString(), se.Id, publishRequest.ContractType, publishRequest.Action, publishRequest.Message, MaxRetries, 0, null, publishRequest.Context, DateTime.Now + timeout); DeliveryCore deliveryCore = ServiceLocator.GetInstance <DeliveryCore>(); deliveryCore.Deliver(md); ts.Complete(); } }
public SubscriptionEndpoint GetSubscription(Guid subscriptionEndpointId) { if (_disposed) { throw new ObjectDisposedException("ServiceBusRuntime"); } SubscriptionEndpoint endpoint = null; _subscriptions.Read(subscriptions => { endpoint = subscriptions.FirstOrDefault(s => s.Id == subscriptionEndpointId); }); return(endpoint); }
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { Dispatcher dispatcher; if (DispatcherType != null) { dispatcher = (Dispatcher)Activator.CreateInstance(DispatcherType); } else { dispatcher = new WcfProxyDispatcher(); } SubscriptionEndpoint subscription = new SubscriptionEndpoint(SubscriptionId ?? Guid.NewGuid(), Name, ConfigurationName, Address ?? serviceDescription.Endpoints[0].Address.Uri.ToString(), ContractType, dispatcher, WcfProxyDispatcher.CreateMessageFilter(ContractType), Transient); SubscriptionExtension extension = new SubscriptionExtension(subscription); extension.UnsubscribeOnClosing = UnsubscribeOnClosing; serviceHostBase.Extensions.Add(extension); }
public void RemoveSubscription(Guid subscriptionId) { if (_disposed) { throw new ObjectDisposedException("ServiceBusRuntime"); } SubscriptionEndpoint endpoint = null; _subscriptions.Read(subscriptions => { endpoint = subscriptions.FirstOrDefault(s => s.Id == subscriptionId); }); if (endpoint == null) { throw new SubscriptionNotFoundException(); } RemoveSubscription(endpoint); }
public SubscriptionExtension(SubscriptionEndpoint subscription) { Subscription = subscription; }
/// <summary> /// Called when a service is removed from the service bus /// </summary> /// <param name="endpoint"></param> protected internal virtual void OnSubscriptionRemoved(SubscriptionEndpoint endpoint) { }
protected Dispatcher(SubscriptionEndpoint endpoint) { _endpoint = endpoint; }
/// <summary> /// Called when a service is removed from the service bus /// </summary> /// <param name="endpoint"></param> protected virtual internal void OnSubscriptionRemoved(SubscriptionEndpoint endpoint) { }
public void Subscribe(SubscriptionEndpoint subscription) { if (_disposed) throw new ObjectDisposedException("ServiceBusRuntime"); if (subscription == null) throw new ArgumentNullException("subscription"); if (subscription.Dispatcher.Runtime != null) { throw new InvalidOperationException("Subscription is attached to a bus already"); } bool added = false; try { using (TransactionScope ts = new TransactionScope()) { _subscriptions.Write(subscriptions => { subscriptions.Add(subscription); subscription.Dispatcher.Runtime = this; added = true; }); if (_started) { subscription.Dispatcher.StartInternal() ; } foreach (RuntimeService service in ServiceLocator.GetAllInstances<RuntimeService>()) { service.OnSubscriptionAdded(subscription); } EventHandler<EndpointEventArgs> subscribedEvent = SubscriptionAdded; if (subscribedEvent != null) subscribedEvent(this, new EndpointEventArgs(subscription)); ts.Complete(); } } catch { if (added) { // Remove subscription on failure _subscriptions.Write(subscriptions => { subscriptions.Remove(subscription); }); } throw; } }
public void RemoveSubscription(SubscriptionEndpoint subscription) { if (_disposed) throw new ObjectDisposedException("ServiceBusRuntime"); if (subscription == null) throw new ArgumentNullException("subscription"); bool removed = false; try { using (TransactionScope ts = new TransactionScope()) { subscription.Dispatcher.StopInternal(); _subscriptions.Write(subscriptions => { subscriptions.Remove(subscription); subscription.Dispatcher.Runtime = null; removed = true; }); foreach (RuntimeService service in ServiceLocator.GetAllInstances<RuntimeService>()) { service.OnSubscriptionRemoved(subscription); } EventHandler<EndpointEventArgs> unsubscribedEvent = SubscriptionRemoved; if (unsubscribedEvent != null) unsubscribedEvent(this, new EndpointEventArgs(subscription)); ts.Complete(); } } catch { if (removed) { // Re-add subscription on failure _subscriptions.Write(subscriptions => { subscriptions.Add(subscription); }); } throw; } }
public ServiceBusRuntime(IServiceLocator serviceLocator) { try { serviceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; } catch(NullReferenceException) // 1.0 throws null ref exception if no provider delegate is set. { } if (serviceLocator == null) { serviceLocator = SimpleServiceLocator.With(new Delivery.DirectDeliveryCore()); // default to simple service locator with direct message delivery } _serviceLocator = serviceLocator; attachServices(); _subscriptionEndpoint = new SubscriptionEndpoint(Guid.Empty, "Subscription endpoint", null, null, (Type)null, new SubscriptionDispatcher(() => this.ListSubscriptions(true)), new PredicateMessageFilter(pr => false), true, null); _correlatorEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "Correlator", null, null, (Type)null, new ActionDispatcher((se, md) => { _correlator.Reply((string)md.Context[MessageDelivery.CorrelationId], md); }), new PredicateMessageFilter(pr => pr.Context.ContainsKey(MessageDelivery.CorrelationId)), true, null); Subscribe(_subscriptionEndpoint); Subscribe(_correlatorEndpoint); }
public void Subscribe(SubscriptionEndpoint subscription) { if (_disposed) { throw new ObjectDisposedException("ServiceBusRuntime"); } if (subscription == null) { throw new ArgumentNullException("subscription"); } if (subscription.Dispatcher.Runtime != null) { throw new InvalidOperationException("Subscription is attached to a bus already"); } bool added = false; try { using (TransactionScope ts = new TransactionScope()) { _subscriptions.Write(subscriptions => { subscriptions.Add(subscription); subscription.Dispatcher.Runtime = this; added = true; }); if (_started) { subscription.Dispatcher.StartInternal(); } foreach (RuntimeService service in ServiceLocator.GetAllInstances <RuntimeService>()) { service.OnSubscriptionAdded(subscription); } EventHandler <EndpointEventArgs> subscribedEvent = SubscriptionAdded; if (subscribedEvent != null) { subscribedEvent(this, new EndpointEventArgs(subscription)); } ts.Complete(); } } catch { if (added) { // Remove subscription on failure _subscriptions.Write(subscriptions => { subscriptions.Remove(subscription); }); } throw; } }