Skip to content
jci-shotola edited this page Sep 24, 2014 · 6 revisions

The ChannelDefinition constructor function creates an instance of a channel definition, providing a simple wrapper around subscribing to and publishing messages on a given channel. The built-in ChannelDefinition is stored under postal.ChannelDefinition. You create a new instance of a ChannelDefinition by calling the postal.channel method.

Be sure to read What are Channels? for more background information.

ChannelDefinition members:

Member Description
channel The channel name (string)
subscribe

subscribe( topic, callback ) - The topic is a string value of the actual topic, or wildcard binding, to which you want to subscribe, and the callback argument is a function that should be invoked when a message with that topic is published on this channel. The callback function takes two arguments: callback( data, envelope ), where data is the message data and envelope is the full message envelope (includes channel, topic, timestamp and data, at a minimum).

This method returns a SubscriptionDefinition instance.
publish
  • publish( topic, data )
    topic should be a string value specifying the topic to which you want to publish (the actual topic, not a wildcard binding). The data argument can be any value (and you may omit it as well).
  • publish( envelope ) - You can also pass an object literal to the ChannelDefinition.publish call. The object should contain - at least - a topic member and may also contain a data member along with any other properties you would like to add to the envelope. This does not allow you to override the channel value of the envelope.
This method returns the actual envelope object published to the bus.
Clone this wiki locally