Asterisk stasis message bus: Difference between revisions
(Created page with "== Overview == Asterisk stasis message bus 내용 정리 == Message Bus == The overall stasis-core API can be best described as a publish/subscribe message bus. Data that ne...") |
|||
Line 18: | Line 18: | ||
For subscriptions that deal with many different types of messages, the stasis_message_router can be used to route messages based on type. This gets rid of a lot of ugly looking if/else chains and replaces them with callback dispatch. | For subscriptions that deal with many different types of messages, the stasis_message_router can be used to route messages based on type. This gets rid of a lot of ugly looking if/else chains and replaces them with callback dispatch. | ||
Another common use case within Asterisk is to have a subscription that monitors state changes for snapshots that are published to a topic. To aid in this, we have stasis_cachig_topic. This is a topic filter, which presents its own topic with filtered and modified messages from an original topic. In the case of the caching topic, it watches for snapshot messages, comapres them with their prior values. For these messages, it publishes a stasis_cache_update_message with both the old and new values of the snapshot. | |||
== See also == | == See also == |
Revision as of 20:59, 9 April 2019
Overview
Asterisk stasis message bus 내용 정리
Message Bus
The overall stasis-core API can be best described as a publish/subscribe message bus.
Data that needs to be published on the message bus is encapsulated in a stasis_message, which associates the message data(which is simply an AO2 managed void *) along with a stasis_message_type. (The message also has the timeval when it was created, which is generally useful, since messages are received asynchronously).
Messages are published to a stasis_topic. To receive the messages published to a topic, use stasis_subscribe() to create a subscription.
When topics are subscribed to/unsubscribed to, stasis_subscription_change are sent to all of the topic's subscribers. On unsubscribe, the stasis_subscription_change will be the laste message received by the unsubscriber, which can be used to kick off any cleanup that might be necessary. The convenience function stasis_subscription_final_message() can be used to check if a message is the final unsubscribe message.
To forward all of the messages from one topic to another, use stasis_forward_all(). This is useful for creating aggregation topics, like ast_channel_topic_all(), which collect all of the messages published to a set of other topics.
Routing and caching
In addition to these fundamental concepts, there are a few extra objects in the Stasis Bus arsenal.
For subscriptions that deal with many different types of messages, the stasis_message_router can be used to route messages based on type. This gets rid of a lot of ugly looking if/else chains and replaces them with callback dispatch.
Another common use case within Asterisk is to have a subscription that monitors state changes for snapshots that are published to a topic. To aid in this, we have stasis_cachig_topic. This is a topic filter, which presents its own topic with filtered and modified messages from an original topic. In the case of the caching topic, it watches for snapshot messages, comapres them with their prior values. For these messages, it publishes a stasis_cache_update_message with both the old and new values of the snapshot.