public void FileSystemDispatcher_Picks_Up_Existing_Messages() { BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement(); MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder; ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore()); var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder,typeof(IContract)),Config.IncomingFilePath), new PassThroughMessageFilter()); dispatchRuntime.Subscribe(subscription); ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore()); var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)),Config.IncomingFilePath, Config.ProcessedFilePath)); listenerRuntime.AddListener(listener); listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter())); var dispatchTester = new ServiceBusTest(dispatchRuntime); var listenerTester = new ServiceBusTest(listenerRuntime); string message = "test this thing"; dispatchTester.StartAndStop(() => { dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message); listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), () => { }); }); dispatchRuntime.RemoveSubscription(subscription); }
public void AssertEqual(ListenerEndpoint endpoint1, ListenerEndpoint endpoint2) { Assert.AreEqual(endpoint1.Id, endpoint2.Id); Assert.AreEqual(endpoint1.Name, endpoint2.Name); Assert.AreEqual(endpoint1.ConfigurationName, endpoint2.ConfigurationName); Assert.AreEqual(endpoint1.ContractType, endpoint2.ContractType); Assert.AreEqual(endpoint1.Address, endpoint2.Address); Assert.IsInstanceOfType(endpoint1.Listener.GetType(), endpoint2.Listener); // todo: should we require .Equals? }
public void CreateListener(ListenerEndpoint endpoint) { using (SqlConnection connection = getConnection()) { using (SqlCommand command = new SqlCommand("sp_listener_create", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@id", endpoint.Id); command.Parameters.AddWithValue("@address", endpoint.Address); command.Parameters.AddWithValue("@configuration_name", endpoint.ConfigurationName); command.Parameters.AddWithValue("@contract_type", endpoint.ContractTypeName); command.Parameters.AddWithValue("@name", endpoint.Name); command.Parameters.AddWithValue("@expiration", (object)endpoint.Expiration ?? DBNull.Value); command.Parameters.AddWithValue("@listener_data", getListenerPersistenceData(endpoint.Listener)); command.ExecuteNonQuery(); } } }
public void Can_Create_Remove_Update_And_Delete_Endpoints() { SqlSubscriptionDB db = new SqlSubscriptionDB(_connectionString, new Type[] { typeof(WcfProxyDispatcher) }, new Type[] { typeof(WcfServiceHostListener) }, new Type[] { typeof(PassThroughMessageFilter) }); Assert.AreEqual(0, db.LoadListenerEndpoints().Count()); Assert.AreEqual(0, db.LoadSubscriptionEndpoints().Count()); ListenerEndpoint listener = new ListenerEndpoint(Guid.NewGuid(), "listener", "ListenerConfig", "http://localhost/test", typeof(IContract), new WcfServiceHostListener()); db.CreateListener(listener); IEnumerable <ListenerEndpoint> listeners = db.LoadListenerEndpoints(); Assert.AreEqual(1, listeners.Count()); ListenerEndpoint savedListener = listeners.First(); Assert.AreEqual(listener.Name, savedListener.Name); Assert.AreEqual(listener.Id, savedListener.Id); Assert.AreEqual(listener.ContractType, savedListener.ContractType); Assert.AreEqual(listener.ConfigurationName, savedListener.ConfigurationName); Assert.AreEqual(listener.Address, savedListener.Address); SubscriptionEndpoint subscription = new SubscriptionEndpoint(Guid.NewGuid(), "subscription", "SubscriptionConfig", "http://localhost/test/subscription", typeof(IContract), new WcfProxyDispatcher(), new PassThroughMessageFilter()); db.CreateSubscription(subscription); IEnumerable <SubscriptionEndpoint> subscriptions = db.LoadSubscriptionEndpoints(); Assert.AreEqual(1, subscriptions.Count()); SubscriptionEndpoint savedSubscription = subscriptions.First(); Assert.AreEqual(subscription.Name, savedSubscription.Name); Assert.AreEqual(subscription.Address, savedSubscription.Address); Assert.AreEqual(subscription.ConfigurationName, savedSubscription.ConfigurationName); Assert.AreEqual(subscription.ContractType, savedSubscription.ContractType); // TODO: Compare dispatchers Assert.AreEqual(subscription.Id, savedSubscription.Id); Assert.AreEqual(subscription.Filter.GetType(), savedSubscription.Filter.GetType()); db.DeleteListener(listener.Id); }
ListenerEndpoint getListener(IDataReader dr) { ListenerEndpoint endpoint = new ListenerEndpoint( (Guid)dr["id"], dr["name"] as string, dr["configuration_name"] as string, dr["address"] as string, Type.GetType(dr["contract_type"] as string), getListenerFromPersistenceData((byte[])dr["listener_data"]), false, dr["expiration"] == DBNull.Value ? default(DateTime?) : Convert.ToDateTime(dr["expiration"])); if (endpoint.ContractType == null) { throw new InvalidOperationException("Contract type could not be loaded"); } return(endpoint); }
public void Can_Add_And_Remove_Subscriptions() { using(ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new WcfManagementService())) { ServiceBusTest tester = new ServiceBusTest(runtime); tester.StartAndStop(() => { Service.Use<IServiceBusManagementService>(managementService => { ListenerEndpoint endpoint = new ListenerEndpoint(Guid.NewGuid(), "name of endpoint", "NamedPipeListener", "net.pipe://test/someservice/", typeof(IContract), new WcfServiceHostListener()); managementService.AddListener(endpoint); ListenerEndpoint added = managementService.ListListeners().First(); tester.AssertEqual(endpoint, added); managementService.RemoveListener(endpoint.Id); Assert.IsEmpty(managementService.ListListeners()); }); }); } }
public void Can_Add_And_Remove_Subscriptions() { using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new WcfManagementService())) { ServiceBusTest tester = new ServiceBusTest(runtime); tester.StartAndStop(() => { Service.Use <IServiceBusManagementService>(managementService => { ListenerEndpoint endpoint = new ListenerEndpoint(Guid.NewGuid(), "name of endpoint", "NamedPipeListener", "net.pipe://test/someservice/", typeof(IContract), new WcfServiceHostListener()); managementService.AddListener(endpoint); ListenerEndpoint added = managementService.ListListeners().First(); tester.AssertEqual(endpoint, added); managementService.RemoveListener(endpoint.Id); Assert.IsEmpty(managementService.ListListeners()); }); }); } }
public IEnumerable <ListenerEndpoint> LoadListenerEndpoints() { List <ListenerEndpoint> listenerEndpoints = new List <ListenerEndpoint>(); using (SqlConnection connection = getConnection()) { using (SqlCommand command = new SqlCommand("sp_listener_list", connection)) { command.CommandType = CommandType.StoredProcedure; using (SqlDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { ListenerEndpoint listener = getListener(dataReader); listenerEndpoints.Add(listener); } } } } return(listenerEndpoints); }
protected override void OnStart() { foreach (Endpoint e in LoadEndpoints()) { ListenerEndpoint le = e as ListenerEndpoint; SubscriptionEndpoint se = e as SubscriptionEndpoint; if (le != null) { _managedEndpoints.Add(le); } else if (se != null) { _managedEndpoints.Add(se); } else { throw new InvalidOperationException("Invalid endpoint type encountered"); } } }
protected override void OnStop() { // Clear out all the stuff we loaded foreach (Endpoint e in _managedEndpoints) { ListenerEndpoint le = e as ListenerEndpoint; SubscriptionEndpoint se = e as SubscriptionEndpoint; if (le != null) { Runtime.RemoveListener(le); } else if (se != null) { Runtime.RemoveSubscription(se); } else { throw new InvalidOperationException("Unexpected endpoint type encountered"); } } }
public void Can_Create_Remove_Update_And_Delete_Endpoints() { SqlSubscriptionDB db = new SqlSubscriptionDB(_connectionString, new Type[] { typeof(WcfProxyDispatcher) }, new Type[] { typeof(WcfServiceHostListener) }, new Type[] { typeof(PassThroughMessageFilter) }); Assert.AreEqual(0, db.LoadListenerEndpoints().Count()); Assert.AreEqual(0, db.LoadSubscriptionEndpoints().Count()); ListenerEndpoint listener = new ListenerEndpoint(Guid.NewGuid(), "listener", "ListenerConfig", "http://localhost/test", typeof(IContract), new WcfServiceHostListener()); db.CreateListener(listener); IEnumerable<ListenerEndpoint> listeners = db.LoadListenerEndpoints(); Assert.AreEqual(1, listeners.Count()); ListenerEndpoint savedListener = listeners.First(); Assert.AreEqual(listener.Name, savedListener.Name); Assert.AreEqual(listener.Id, savedListener.Id); Assert.AreEqual(listener.ContractType, savedListener.ContractType); Assert.AreEqual(listener.ConfigurationName, savedListener.ConfigurationName); Assert.AreEqual(listener.Address, savedListener.Address); SubscriptionEndpoint subscription = new SubscriptionEndpoint(Guid.NewGuid(), "subscription", "SubscriptionConfig", "http://localhost/test/subscription", typeof(IContract), new WcfProxyDispatcher(), new PassThroughMessageFilter()); db.CreateSubscription(subscription); IEnumerable<SubscriptionEndpoint> subscriptions = db.LoadSubscriptionEndpoints(); Assert.AreEqual(1, subscriptions.Count()); SubscriptionEndpoint savedSubscription = subscriptions.First(); Assert.AreEqual(subscription.Name, savedSubscription.Name); Assert.AreEqual(subscription.Address, savedSubscription.Address); Assert.AreEqual(subscription.ConfigurationName, savedSubscription.ConfigurationName); Assert.AreEqual(subscription.ContractType, savedSubscription.ContractType); // TODO: Compare dispatchers Assert.AreEqual(subscription.Id, savedSubscription.Id); Assert.AreEqual(subscription.Filter.GetType(), savedSubscription.Filter.GetType()); db.DeleteListener(listener.Id); }
public void AddListener([MessageParameter(Name = "Endpoint")] ListenerEndpoint endpoint) { Runtime.AddListener(endpoint); }
protected internal override void OnListenerRemoved(ListenerEndpoint endpoint) { base.OnListenerRemoved(endpoint); DeleteListener(endpoint); }
protected internal override void OnListenerAdded(ListenerEndpoint endpoint) { base.OnListenerAdded(endpoint); CreateListener(endpoint); }
/// <summary> /// Delete a listener from the persistence store /// </summary> /// <param name="endpoint"></param> protected abstract void DeleteListener(ListenerEndpoint endpoint);
/// <summary> /// Create a listener in the persistence store /// </summary> /// <param name="endpoint"></param> protected abstract void CreateListener(ListenerEndpoint endpoint);