Functions | |
| TOPIC_HANDLER_T | subscribe (SESSION_T *session, const SUBSCRIPTION_PARAMS_T params) |
| Request subscription to topic. | |
| TOPIC_HANDLER_T | diffusion_subscribe_with_scope (SESSION_T *session, const char *selection_scope, const SUBSCRIPTION_PARAMS_T params, DIFFUSION_API_ERROR *api_error) |
| Request subscription to topics using a scope selection. | |
| void | unsubscribe (SESSION_T *session, const UNSUBSCRIPTION_PARAMS_T params) |
| Unsubscribe from one or more topics. | |
| bool | diffusion_unsubscribe_with_scope (SESSION_T *session, const char *selection_scope, const UNSUBSCRIPTION_PARAMS_T params, DIFFUSION_API_ERROR *api_error) |
| Unsubscribe from topics using a selection scope. | |
| bool | diffusion_unsubscribe_all_scopes (SESSION_T *session, const UNSUBSCRIPTION_ALL_SCOPES_PARAMS_T params, DIFFUSION_API_ERROR *api_error) |
| Unsubscribe topics from all topic selection scopes. | |
| void | notify_subscription_register (SESSION_T *session, const NOTIFY_SUBSCRIPTION_PARAMS_T params) |
| Register to receive subscription notifications. | |
| void | notify_unsubscription_register (SESSION_T *session, const NOTIFY_UNSUBSCRIPTION_PARAMS_T params) |
| Register to receive unsubscription notifications. | |
Subscription to topics and fetching topic data.
This feature allows a client session to subscribe to topics to receive streamed topic updates, fetch the state of topics and/or update topics with new values.
Specifically, the feature provides the ability to:
A session can issue requests to subscribe to topics at any time, even if the topics do not exist at the server. Each subscription request provides a topic selector that is evaluated by the server to select matching topics. The session will be subscribed to any topics that match the selector unless they are already subscribed, or the session has insufficient permission. The subscription request is also retained at the server and the session will be automatically subscribed to newly created topics that match the selector (unless a subsequent unsubscription cancels the request).
Sessions receive notifications from topics that they are subscribed to via subscription streams (see below). When a session is subscribed to a topic, all matching streams will first receive a subscription notification that provides details about the topic. If the server has a value for the topic, the value will be delivered to the streams before any other notifications.
A session can unsubscribe from topics at any time. This is also specified using a topic selector. On unsubscription, matching streams are notified via the on_unsubscription notification. This notification will give the reason for unsubscription (for example, by request of the session, request of the server, or topic removal).
Subscriptions and unsubscriptions can occur for reasons other than requests from the session. A session can be subscribed to or unsubscribed from a topic by another session using the Subscription Control feature. The removal of a topic also automatically causes unsubscription for subscribed sessions.
Subscription requests are subject to authorisation checks. The session must have SELECT_TOPIC SELECT_TOPIC permission for the topic selector used to subscribe. Matching topics will be further filtered to those for which the session has READ_TOPIC READ_TOPIC permission.
Topic selection scopes allow an application with multiple components to use a single Diffusion session. An application component can use a topic selection scope to manage a set of selectors that is unaffected by unsubscriptions performed by other application components. The session will be subscribed to all topics with paths matching a selector in any scope. The unsubscribe operation removes a selector from specific scopes.
A scope may be specified to a subscribe or unsubscribe method, indicating that the selection only applies to that scope. The server manages scopes to ensure that unsubscriptions applied to one scope do not affect another.
Scope names are case sensitive. A scope name may not begin with the character $ as this is reserved for internal use.
Unsubscription using a wildcard selector that indicates all topics effectively removes the scope. An application can request unsubscription from all scopes using unsubscribe_all_scopes. The DEFAULT_SELECTION_SCOPE is used for all methods that do not explicitly specify a scope.
A session can listen to subscription events and updates for a selection of topics by adding one or more streams. A stream is registered using a topic selector which specifies the topics that the stream applies to. When an update is received for a topic then it will be routed to every stream that matches both the topic selector and the stream's value type. If more than one stream matches, all will receive the update; the order in which they are notified is not defined.
A stream can be added several times for different selectors. If the same stream is registered for several selectors that match an event, the stream will only be notified of the event once. The mapping of topic selectors to streams is maintained locally in the client process.
It is also possible to add one or more fallback streams which will receive updates that do not match any stream registered with a selector. This is useful for default processing or simply to catch unprocessed updates. A fallback stream can be added using add_fallback_stream. Zero, one, or more fallback streams may be assigned. If no fallback stream is specified, any updates that are not routed to any other stream will simply be discarded.
If the session is already subscribed to a topic when a matching stream is added, the stream will immediately receive a subscription notification. For most topic types, the latest value is locally cached and will be provided to the stream following the subscription notification.
A stream will receive an on_close callback when unregistered and an on_error callback if the session is closed.
A value stream receives values for matching topics as and when updates are received from the server. Delta updates received from the server are automatically applied to locally cached values so that the stream always receives full values for each update.
Value streams are typed to a specified value class and only updates for compatible topics will be routed to the stream. The following table shows how the value class maps to compatible topic types that will be routed to the stream:
| Value Class | Compatible Topic Types |
|---|---|
| JSON | JSON STRING INT64 DOUBLE |
| String | STRING |
| Long | INT64 |
| Double | DOUBLE |
| Binary | BINARY |
| Bytes | JSON STRING INT64 DOUBLE BINARY RECORD_V2 |
| RecordV2 | RECORD_V2 |
Value stream implementations can be added using add_stream.
A value stream can be added to received updates from time series topics using add_time_series_stream. The following table shows how the value class specified when adding the stream maps to the event value class of time series topics that will be routed to the stream:
| Event Value Class | Time Series Event Value Class |
|---|---|
| JSON | JSON STRING INT64 DOUBLE |
| String | STRING |
| Long | INT64 |
| Double | DOUBLE |
| Binary | BINARY |
| Bytes | JSON STRING INT64 DOUBLE BINARY RECORD_V2 |
| RecordV2 | RECORD_V2 |
A session can issue a request to fetch details of a topic or topics (subject to authorization) at any time. The topics required are specified using a topic selector.
The results of a fetch will return the topic path and type of each selected topic. The results may also optionally return the topic values and/or properties.
A new request can be created using diffusion_fetch_request_init and modified to specify additional requirements of the fetch operation. The request is issued to the server using the diffusion_fetch_request_fetch method on the request.
A session must have SELECT_TOPIC SELECT_TOPIC permission for the topic selector used to subscribe or diffusion_fetch_request_fetch. The topics that result from a subscription or fetch request are further filtered using the READ_TOPIC READ_TOPIC permission.
No access control restrictions are applied to unsubscription.
| TOPIC_HANDLER_T diffusion_subscribe_with_scope | ( | SESSION_T * | session, |
| const char * | selection_scope, | ||
| const SUBSCRIPTION_PARAMS_T | params, | ||
| DIFFUSION_API_ERROR * | api_error ) |
Request subscription to topics using a scope selection.
The session will become subscribed to each existing topic matching the selector unless the session is already subscribed to the topic, or the session does not have READ_TOPIC permission for the topic path. For each topic to which the session becomes subscribed, a subscription notification and initial value (if any) will be delivered to registered value streams.
The subscription request is also retained at the server and the session will be automatically subscribed to newly created topics that match the selector (unless a subsequent unsubscription cancels the request).
| session | The session handle. If NULL, this function returns immediately. |
| selection_scope | Specifies the scope of the selection. |
| params | Parameters describing the subscription request and callbacks handlers which may be invoked in response. |
| api_error | Populated on API error. Can be NULL. |
| bool diffusion_unsubscribe_all_scopes | ( | SESSION_T * | session, |
| const UNSUBSCRIPTION_ALL_SCOPES_PARAMS_T | params, | ||
| DIFFUSION_API_ERROR * | api_error ) |
Unsubscribe topics from all topic selection scopes.
This can be used at any time whilst connected to reduce the set of topics to which the session is subscribed or negate earlier subscription requests and will apply to all scopes in use.
| session | The session handle. If NULL, this function returns immediately. |
| params | Parameters describing the unsubscription request and callback handlers which may be invoked in response. |
| api_error | Populated on API error. Can be NULL. |
| bool diffusion_unsubscribe_with_scope | ( | SESSION_T * | session, |
| const char * | selection_scope, | ||
| const UNSUBSCRIPTION_PARAMS_T | params, | ||
| DIFFUSION_API_ERROR * | api_error ) |
Unsubscribe from topics using a selection scope.
This can be used at any time whilst connected to reduce the set of topics to which the session is subscribed or negate earlier subscription requests.
| session | The session handle. If NULL, this function returns immediately. |
| selection_scope | Specifies the scope of the selection. |
| params | Parameters describing the unsubscription request and callback handlers which may be invoked in response. |
| api_error | Populated on API error. Can be NULL. |
| void notify_subscription_register | ( | SESSION_T * | session, |
| const NOTIFY_SUBSCRIPTION_PARAMS_T | params ) |
Register to receive subscription notifications.
This function should be called by the application to register to receive notifications that it has been subscribed to a topic.
| session | The current session. If NULL, this function returns immediately. |
| params | Callbacks and other parameters. on_notify_subscription should be set to receive notifications. |
| void notify_unsubscription_register | ( | SESSION_T * | session, |
| const NOTIFY_UNSUBSCRIPTION_PARAMS_T | params ) |
Register to receive unsubscription notifications.
This function should be called by the application to receive notifications that it has been unsubscribed to a topic.
| session | The current session. If NULL, this function returns immediately. |
| params | Callbacks and other parameters. on_notify_unsubscription should be set to receive notifications. |
| TOPIC_HANDLER_T subscribe | ( | SESSION_T * | session, |
| const SUBSCRIPTION_PARAMS_T | params ) |
Request subscription to topic.
This is equivalent to calling diffusion_subscribe_with_scope specifying DEFAULT_SELECTION_SCOPE.
| session | The session handle. If NULL, the function returns immediately. |
| params | Parameters describing the subscription request and callbacks handlers which may be invoked in response. |
| void unsubscribe | ( | SESSION_T * | session, |
| const UNSUBSCRIPTION_PARAMS_T | params ) |
Unsubscribe from one or more topics.
This is equivalent to calling diffusion_unsubscribe_with_scope specifying DEFAULT_SELECTION_SCOPE.
| session | The session handle. If NULL, this function returns immediately. |
| params | Parameters describing the unsubscription request and callback handlers which may be invoked in response. |