Was this page helpful?

PubSub

    Assembly: mindtouch.dream
    Class:MindTouch.Dream.PubSubService
    SID: sid://mindtouch.com/dream/2008/10/pubsub

    Overview

    The PubSubService accepts subscription sets from subscribers and filters and propagates messages it receives accordingly. In general, the location of an PubSubService will be provided by the environment to each service via the <uri.subservice> configuration value. The URI provided in the configuration value is rooted at {service}/subscribe, so that subscription calls are done against the provided URI, without the postfix.

    An EventPublisher service receives messages. It either is an EventSubscriber or is associated with at least one via another transport (such as Xmpp). In general, the location of an EventPublisher will be provided by the environment to each service via the <uri.pubservice> configuration value. The URI provided in the configuration value is rooted at {service}/publish, so that publication of messages are done against the provided URI.

    Verb:Suffix Description
    POST:publish Publish a message onto a channel
    POST:subscribers Initialize subscriptions from a subscription set
    GET:subscribers Retrieve the combined subscription set
    GET:subscribers/{subscription-location} Retrieve present subscription set
    PUT|POST:subscribers/{subscription-location} Replaces an existing subscription set
    DELETE:subscribers/{subscription-location} Delete an existing subscription set at the location

    Data Types

    Subscription Set 

    <subscription-set max-failures="...">
        <!-- the uri of the service registering the subscription set -->
        <uri.owner>...</uri.owner>
    
        <!-- the set can have 1 or more subscription blocks. @id will be assigned by
            the server if none was provided -->
        <subscription id="...">
    
            <!-- each subscription can include 1 or more channels. Channels are OR-ed
                for matching events. Channels can use a wildcard '*' for host
                and end of path -->
            <channel>channel:///some/channel</channel>
            ...
    
            <!-- each subscription can include 0 or more resources to subscribe to. Resources
                are OR-ed for matching events.  Resource Uri's can use a wildcard '*' for host
                and end of path -->
            <uri.resource>http://canonical/path/to/resource</uri.resource>
            ...
    
            <!-- There can be zero or one proxy. If it exists it is used as the
                destination for matched events -->
            <uri.proxy>...</uri.proxy>
    
            <!-- There can be 1 or more recipients. If there is more than one recipient
                a proxy must be defined. If the event has recipients, the intersection
                between event and subscription recipients is used to filter matches. Recipient
                comparison is done solely on the recipient uri, although end points can employ
                their own contracts based on additional data included in the recipient document -->
            <recipient>
                <uri>...</uri>
                ...
            </recipient>
            ... 
    
        </subscription>
        ...
    </subscription-set>

     

    Channels

    Channels are URIs. There generalized format is:

    {system}://{instance}/{action-path}

    In subscription sets, channels accept wild cards at the instance or end of action. The following are all valid channel patterns:

    channel://*/some/exact/path
    foo://some-instance/wildcard/path/*
    channel://*/*
    
    The PubSubService is also a publisher itself of change events on its subscription set, which it POSTs against subscribers that subscribe to the channel pattern
    pubsub:///*
    

    PubSub service chaining

    Downstream Pubsub chaining

    Scenario: PubSubService p1 intends to publish events that PubSubService p2 has subscriptions for into p2. For this to happen, p1 must subscribe to p2 in such a way that subscription set changes are published into a named subscribers endpoint.

    1. p1 discovers the subscribe uri in some fashion (it was injected into p1)
    2. p1 retrieves p2s current subscription set via GET on p2's subscribe feature
    3. p1 creates subscription set location l1 using p2's subscribtion set
    4. p1 creates a subscription set subscribing to pubsub:///* at location l1 and POSTs this set to p2's subscribe feature
    5. p1 receives updates to p2's subscriptions at l1 as they occur
    6. As p1 receives events that match p2's subscription set, it POSTs them against p2's publish feature

    Upstream PubSub chaining

    Scenario: PubSubService p1 intends to proxy events received by PubSubService p2 for its own subscribers. For this to happen, p1 must subscribe to events on p2 matching its combined subscription set and also push updates to this subscription set to p2.

    1. p1 discovers the subscribe uri of p2 in some fashion (it was injected or part of the config file)
    2. p1 creates its combined subscription set and POSTs this set to p2's subscribe feature
    3. According to the subscribe feature's behavior p1 is informed of the location l2 on p2 where its subscription set lives
    4. As subscription changes happen on p1, it PUTs its updated combined subscription set on l2, so that p2 can properly publish matching events into p1's publish feature

    Features

    POST:publish

    Publish an event. At service start-up, every service will be provided the uri to a publish feature via uri.publish. This is also exposed as a Plug at the Publish property of the service. The uri is rooted at the publish feature, i.e. no additional "publish" is needed for the post.

    Accces: Internal

    This feature is internal, but the services provided the URI for this service are generally also provided the appropriate cookie along for the automatically provided publish.

    Request body

    The request body can be anything, accompanied by a proper mime-type. However, there are some header requirements.

    Headers Occurence Description
    X-Dream-Event-Id 1
    The id of the event. If one was not provided, one will assigned and returned in the response body
    X-Dream-Event-Origin-Uri 1+ one or more resource uri's for resources related to the event. Generally additional uri's denote previous locations of that resource
    X-Dream-Event-Channel 1 the channel this event is published to
    X-Dream-Event-Via-Uri 0+ zero or more publishers the event has passed through (to determine circular routes)
    X-Dream-Event-Recipient-Uri 0+ a list of recipients authorized to receive the event. Generally should be set by a EventSubscriber based on the set of recipient subscribers so that known downstream subscribers are in this list
    Response
    Response Response Body Description
    Ok (200) see below
    operation completed successfully and a new event was created
    Bad Request (400) text/html request could not be completed, because of invalid data in the request
    Response body

    The response body is always an empty envelope with an id, either the one provided in the header by the caller or assigned by service, if none existed.

    <event id="ad232fdd0ed" />
    

    POST:subscribers

    Register a subscription set with the EventSubscriber which is used to filter and dispatch incoming events. Matching events are dispatched to the the uri.recipient or uri.proxy in the event format specified for EventPublisher. If the EventSubscriber is one in a chain of pub/sub services, it builds a combined subscription set from all subscriptions for all recipients it handles and posts it to the upstream publisher as its subscription set.

    Access: Internal
    Request body

    Xml document following the subscription set specified above.

    Response
    Status Response Body Description
    Created (201) text/xml operation completed successfully. Response contains Location header
    Conflict (409) -- A set for that owner already exists. Response contains a Content-Location header for the location of the conflicting subscription set
    Response body
    <subscription-set>
      <uri.location>...</uri.location>
      <access-key>...</access-key>
    </subscription-set>

    The response also includes a Location header that has the access-key appended as a query-argument. Access is granted to the location either by using the location uri from the header directly (which may expose the access key), or by constructing an access-key cookie for the location.


    GET:subscribers

    Retrieve the combined subscription set that the EventSubscriber pushes to an upstream subscriber

    Access: Internal
    Response
    Status Response Body Description
    OK (200) text/xml operation completed successfully

     


    GET:subscribers/{location}

    Retrieve a subscription set, along with each subscriptions statistics

    Access: Private

    A private key is issued upon creation of the location

    Response

    Status Response Body Description
    OK (200) text/xml operation completed successfully

     


    PUT|POST:subscribers/{location}

    Replace an existing subscription set. This feature supports both PUT and POST, primarily since it is used as a publish endpoint for chaining and publishing only allows post. It is preferable to use PUT if not done as part of chaining

    Access: Private

    A private key is issued upon creation of the location

    Response
    Status Response Body Description
    OK (200) -- operation completed successfully

     


    DELETE:subscribers/{location}

    Remove an existing subscription set

    Access: Private

    A private key is issued upon creation of the location

    Response
    Status Response Body Description
    OK (200) -- operation completed successfully

     

    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by