# IPubSubManagerService

`IPubSubManagerService` in assembly SanteDB.Core.Api version 3.0.1980.0

## Summary

Represents a pub/sub manager service

## Events

| Event         | Type                                                                  | Description                                                    |
| ------------- | --------------------------------------------------------------------- | -------------------------------------------------------------- |
| Subscribing   | EventHandler\<DataPersistingEventArgs\<PubSubSubscriptionDefinition>> | Fired when a subscription is requested, but not yet registered |
| Subscribed    | EventHandler\<DataPersistedEventArgs\<PubSubSubscriptionDefinition>>  | Fired after a subscription has been registered                 |
| UnSubscribing | EventHandler\<DataPersistingEventArgs\<PubSubSubscriptionDefinition>> | Fired when an unsubscription is requested                      |
| UnSubscribed  | EventHandler\<DataPersistedEventArgs\<PubSubSubscriptionDefinition>>  | Fired when a subscription has been terminated                  |
| Activating    | EventHandler\<DataPersistingEventArgs\<PubSubSubscriptionDefinition>> | Fired after a subscription and channel are activating          |
| DeActivating  | EventHandler\<DataPersistingEventArgs\<PubSubSubscriptionDefinition>> | Fired after a subscription and channel are deactivating        |
| Activated     | EventHandler\<DataPersistedEventArgs\<PubSubSubscriptionDefinition>>  | Fired after a subscription and channel are activated           |
| DeActivated   | EventHandler\<DataPersistedEventArgs\<PubSubSubscriptionDefinition>>  | Fired after a subscription and channel are deactivated         |

## Operations

| Operation             | Response/Return                                | Input/Parameter                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Description                                                            |
| --------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| FindChannel           | IQueryResultSet\<PubSubChannelDefinition>      | *Expression\<Func\<PubSubChannelDefinition,Boolean>>* **filter**                                                                                                                                                                                                                                                                                                                                                                                                            | Find an existing channel                                               |
| FindSubscription      | IQueryResultSet\<PubSubSubscriptionDefinition> | *Expression\<Func\<PubSubSubscriptionDefinition,Boolean>>* **filter**                                                                                                                                                                                                                                                                                                                                                                                                       | Find an existing subscription                                          |
| FindChannel           | IEnumerable\<PubSubChannelDefinition>          | <p><em>Expression\<Func\<PubSubChannelDefinition,Boolean>></em> <strong>filter</strong><br><em>Int32</em> <strong>offset</strong><br><em>Int32</em> <strong>count</strong><br><em>Int32&</em> <strong>totalResults</strong></p>                                                                                                                                                                                                                                             | Find an existing channel                                               |
| FindSubscription      | IEnumerable\<PubSubSubscriptionDefinition>     | <p><em>Expression\<Func\<PubSubSubscriptionDefinition,Boolean>></em> <strong>filter</strong><br><em>Int32</em> <strong>offset</strong><br><em>Int32</em> <strong>count</strong><br><em>Int32&</em> <strong>totalResults</strong></p>                                                                                                                                                                                                                                        | Find an existing subscription                                          |
| RegisterChannel       | PubSubChannelDefinition                        | <p><em>String</em> <strong>name</strong><br><em>Type</em> <strong>dispatcherFactoryType</strong><br><em>Uri</em> <strong>endpoint</strong><br><em>IDictionary\<String,String></em> <strong>settings</strong></p>                                                                                                                                                                                                                                                            | Registers the specified pub-sub channel using the specified dispatcher |
| RegisterChannel       | PubSubChannelDefinition                        | <p><em>String</em> <strong>name</strong><br><em>String</em> <strong>dispatchFactoryId</strong><br><em>Uri</em> <strong>endpoint</strong><br><em>IDictionary\<String,String></em> <strong>settings</strong></p>                                                                                                                                                                                                                                                              | Registers the specified pub-sub channel using the specified dispatcher |
| UpdateChannel         | PubSubChannelDefinition                        | <p><em>Guid</em> <strong>key</strong><br><em>String</em> <strong>name</strong><br><em>Uri</em> <strong>endpoint</strong><br><em>IDictionary\<String,String></em> <strong>settings</strong></p>                                                                                                                                                                                                                                                                              | Updates the specified pub-sub channel                                  |
| RegisterSubscription  | PubSubSubscriptionDefinition                   | <p><em>String</em> <strong>name</strong><br><em>String</em> <strong>description</strong><br><em>PubSubEventType</em> <strong>events</strong><br><em>Expression\<Func\<TModel,Boolean>></em> <strong>filter</strong><br><em>Guid</em> <strong>channelId</strong><br><em>String</em> <strong>supportAddress</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notBefore</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notAfter</strong></p>                     | Register a new subscription for the specified type                     |
| RegisterSubscription  | PubSubSubscriptionDefinition                   | <p><em>Type</em> <strong>modelType</strong><br><em>String</em> <strong>name</strong><br><em>String</em> <strong>description</strong><br><em>PubSubEventType</em> <strong>events</strong><br><em>String</em> <strong>hdsiFilter</strong><br><em>Guid</em> <strong>channelId</strong><br><em>String</em> <strong>supportAddress</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notBefore</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notAfter</strong></p> | Register a new subscription for the specified type                     |
| UpdateSubscription    | PubSubSubscriptionDefinition                   | <p><em>Guid</em> <strong>key</strong><br><em>String</em> <strong>name</strong><br><em>String</em> <strong>description</strong><br><em>PubSubEventType</em> <strong>events</strong><br><em>String</em> <strong>hdsiFilter</strong><br><em>String</em> <strong>supportAddress</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notBefore</strong><br><em>Nullable\<DateTimeOffset></em> <strong>notAfter</strong></p>                                                   | Update subscription data                                               |
| ActivateSubscription  | PubSubSubscriptionDefinition                   | <p><em>Guid</em> <strong>key</strong><br><em>Boolean</em> <strong>isActive</strong></p>                                                                                                                                                                                                                                                                                                                                                                                     | Activate a subscription                                                |
| GetSubscription       | PubSubSubscriptionDefinition                   | *Guid* **id**                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Gets the subscription information                                      |
| GetChannel            | PubSubChannelDefinition                        | *Guid* **id**                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Gets the channel information                                           |
| RemoveChannel         | PubSubChannelDefinition                        | *Guid* **id**                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Removes the specified channel and all related subscriptions            |
| RemoveSubscription    | PubSubSubscriptionDefinition                   | *Guid* **id**                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Removes the subscription                                               |
| GetSubscriptionByName | PubSubSubscriptionDefinition                   | *String* **name**                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Get subscription by its name                                           |

## Implementations

### UpstreamPubSubManager - (SanteDB.Client)

Upstream publish and subscribe

#### Service Registration

```markup
...
<section xsi:type="ApplicationServiceContextConfigurationSection" threadPoolSize="4">
	<serviceProviders>
		...
		<add type="SanteDB.Client.Upstream.Management.UpstreamPubSubManager, SanteDB.Client, Version=3.0.1980.0, Culture=neutral, PublicKeyToken=null" />
		...
	</serviceProviders>
```

### ADO.NET Pub/Sub Subscription Manager - (SanteDB.Persistence.PubSub.ADO)

Represents a pub/sub manager which stores definitions in a database

#### Service Registration

```markup
...
<section xsi:type="ApplicationServiceContextConfigurationSection" threadPoolSize="4">
	<serviceProviders>
		...
		<add type="SanteDB.Persistence.PubSub.ADO.AdoPubSubManager, SanteDB.Persistence.PubSub.ADO, Version=3.0.1980.0, Culture=neutral, PublicKeyToken=null" />
		...
	</serviceProviders>
```

## Example Implementation

```csharp
/// Example Implementation
using SanteDB.Core.PubSub;
/// Other usings here
public class MyPubSubManagerService : SanteDB.Core.PubSub.IPubSubManagerService { 
	public String ServiceName => "My own IPubSubManagerService service";
	/// <summary>
	/// Fired when a subscription is requested, but not yet registered
	/// </summary>
	public event EventHandler<DataPersistingEventArgs<PubSubSubscriptionDefinition>> Subscribing;
	/// <summary>
	/// Fired after a subscription has been registered
	/// </summary>
	public event EventHandler<DataPersistedEventArgs<PubSubSubscriptionDefinition>> Subscribed;
	/// <summary>
	/// Fired when an unsubscription is requested
	/// </summary>
	public event EventHandler<DataPersistingEventArgs<PubSubSubscriptionDefinition>> UnSubscribing;
	/// <summary>
	/// Fired when a subscription has been terminated
	/// </summary>
	public event EventHandler<DataPersistedEventArgs<PubSubSubscriptionDefinition>> UnSubscribed;
	/// <summary>
	/// Fired after a subscription and channel are activating
	/// </summary>
	public event EventHandler<DataPersistingEventArgs<PubSubSubscriptionDefinition>> Activating;
	/// <summary>
	/// Fired after a subscription and channel are deactivating
	/// </summary>
	public event EventHandler<DataPersistingEventArgs<PubSubSubscriptionDefinition>> DeActivating;
	/// <summary>
	/// Fired after a subscription and channel are activated
	/// </summary>
	public event EventHandler<DataPersistedEventArgs<PubSubSubscriptionDefinition>> Activated;
	/// <summary>
	/// Fired after a subscription and channel are deactivated
	/// </summary>
	public event EventHandler<DataPersistedEventArgs<PubSubSubscriptionDefinition>> DeActivated;
	/// <summary>
	/// Find an existing channel
	/// </summary>
	public IQueryResultSet<PubSubChannelDefinition> FindChannel(Expression<Func<PubSubChannelDefinition,Boolean>> filter){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Find an existing subscription
	/// </summary>
	public IQueryResultSet<PubSubSubscriptionDefinition> FindSubscription(Expression<Func<PubSubSubscriptionDefinition,Boolean>> filter){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Find an existing channel
	/// </summary>
	public IEnumerable<PubSubChannelDefinition> FindChannel(Expression<Func<PubSubChannelDefinition,Boolean>> filter,Int32 offset,Int32 count,Int32& totalResults){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Find an existing subscription
	/// </summary>
	public IEnumerable<PubSubSubscriptionDefinition> FindSubscription(Expression<Func<PubSubSubscriptionDefinition,Boolean>> filter,Int32 offset,Int32 count,Int32& totalResults){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Registers the specified pub-sub channel using the specified dispatcher
	/// </summary>
	public PubSubChannelDefinition RegisterChannel(String name,Type dispatcherFactoryType,Uri endpoint,IDictionary<String,String> settings){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Registers the specified pub-sub channel using the specified dispatcher
	/// </summary>
	public PubSubChannelDefinition RegisterChannel(String name,String dispatchFactoryId,Uri endpoint,IDictionary<String,String> settings){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Updates the specified pub-sub channel
	/// </summary>
	public PubSubChannelDefinition UpdateChannel(Guid key,String name,Uri endpoint,IDictionary<String,String> settings){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Register a new subscription for the specified type
	/// </summary>
	public PubSubSubscriptionDefinition RegisterSubscription<TModel>(String name,String description,PubSubEventType events,Expression<Func<TModel,Boolean>> filter,Guid channelId,String supportAddress,Nullable<DateTimeOffset> notBefore,Nullable<DateTimeOffset> notAfter){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Register a new subscription for the specified type
	/// </summary>
	public PubSubSubscriptionDefinition RegisterSubscription(Type modelType,String name,String description,PubSubEventType events,String hdsiFilter,Guid channelId,String supportAddress,Nullable<DateTimeOffset> notBefore,Nullable<DateTimeOffset> notAfter){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Update subscription data
	/// </summary>
	public PubSubSubscriptionDefinition UpdateSubscription(Guid key,String name,String description,PubSubEventType events,String hdsiFilter,String supportAddress,Nullable<DateTimeOffset> notBefore,Nullable<DateTimeOffset> notAfter){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Activate a subscription
	/// </summary>
	public PubSubSubscriptionDefinition ActivateSubscription(Guid key,Boolean isActive){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Gets the subscription information
	/// </summary>
	public PubSubSubscriptionDefinition GetSubscription(Guid id){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Gets the channel information
	/// </summary>
	public PubSubChannelDefinition GetChannel(Guid id){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Removes the specified channel and all related subscriptions
	/// </summary>
	public PubSubChannelDefinition RemoveChannel(Guid id){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Removes the subscription
	/// </summary>
	public PubSubSubscriptionDefinition RemoveSubscription(Guid id){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Get subscription by its name
	/// </summary>
	public PubSubSubscriptionDefinition GetSubscriptionByName(String name){
		throw new System.NotImplementedException();
	}
}
```

## References

* [IPubSubManagerService C# Documentation](http://santesuite.org/assets/doc/net/html/T_SanteDB_Core_PubSub_IPubSubManagerService.htm)
* [UpstreamPubSubManager C# Documentation](http://santesuite.org/assets/doc/net/html/T_SanteDB_Client_Upstream_Management_UpstreamPubSubManager.htm)
* [AdoPubSubManager C# Documentation](http://santesuite.org/assets/doc/net/html/T_SanteDB_Persistence_PubSub_ADO_AdoPubSubManager.htm)
