(Adobe® Flex™ Data Services 2 only)
Packagemx.messaging
Classpublic class Consumer
InheritanceConsumer Inheritance MessageAgent Inheritance EventDispatcher Inheritance Object

A Consumer subscribes to a destination to receive messages. Consumers send subscribe and unsubscribe messages which generate a MessageAckEvent or MessageFaultEvent depending upon whether the operation was successful or not. Once subscribed, a Consumer dispatches a MessageEvent for each message it receives. Consumers provide the ability to filter messages using a selector. These selectors must be understood by the destination.

MXML Syntaxexpanded Hide MXML Syntax

The <mx:Consumer> tag inherits all the tag attributes of its superclass, and adds the following tag attributes:

   <mx:Consumer
    Properties
    messageType="No default."  
    resubscribeAttempts="5"
    resubscribeInterval="5000"
    selector="No default."
    timestamp="No default."
  />
  


Public Properties
 PropertyDefined by
 InheritedchannelSet : ChannelSet
Provides access to the ChannelSet used by the MessageAgent.
MessageAgent
 InheritedclientId : String
Provides access to the client id for the MessageAgent.
MessageAgent
 Inheritedconnected : Boolean
Indicates whether this MessageAgent is currently connected to its destination via its ChannelSet.
MessageAgent
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheriteddestination : String
Provides access to the destination for the MessageAgent.
MessageAgent
  messageType : String
[read-only] The server alias for the type of message the Consumer can process.
Consumer
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
 InheritedrequestTimeout : int
Provides access to the request timeout in seconds for sent messages.
MessageAgent
  resubscribeAttempts : int
The number of resubscribe attempts that the Consumer makes in the event that the connection to its destination fails.
Consumer
  resubscribeInterval : int
The number of milliseconds between resubscribe attempts.
Consumer
  selector : String
The selector for the Consumer.
Consumer
  subscribed : Boolean
[read-only] Indicates whether the Consumer is currently subscribed.
Consumer
  subtopic : String
[write-only] Setting the subtopic when the Consumer is connected and subscribed has the side effect of unsubscribing and resubscribing the Consumer.
Consumer
  timestamp : Number
Contains the timestamp of the most recent message this Consumer has received.
Consumer
Public Methods
 MethodDefined by
  
Consumer(messageType:String = "flex.messaging.messages.AsyncMessage")
Constructs a Consumer.
Consumer
 Inherited
Invoked by a MessageResponder upon receiving a result for a sent message.
MessageAgent
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
 Inherited
Handles a CONNECT ChannelEvent.
MessageAgent
 Inherited
Handles a DISCONNECT ChannelEvent.
MessageAgent
 Inherited
Handles a ChannelFaultEvent.
MessageAgent
  
Disconnects the Consumer from its remote destination.
Consumer
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Invoked by a MessageResponder upon receiving a fault for a sent message.
MessageAgent
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
initialized(document:Object, id:String):void
Called after the implementing object has been created and all properties specified on the tag have been assigned.
MessageAgent
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Logs the MessageAgent out from its remote destination.
MessageAgent
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
receive(timestamp:Number = 0):void
Requests any messages that are pending from the server from the specified timestamp to the present.
Consumer
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
setCredentials(username:String, password:String):void
Sets the credentials that the MessageAgent uses to authenticate to destinations.
MessageAgent
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
setRemoteCredentials(username:String, password:String):void
Sets the remote credentials that will be passed through to the remote destination for authenticating to secondary systems.
MessageAgent
  
subscribe(clientId:String = null):void
Subscribes to the remote destination.
Consumer
 Inherited
Returns the string representation of the specified object.
Object
  
Unsubscribes from the remote destination.
Consumer
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Protected Methods
 MethodDefined by
  
Returns a subscribe message.
Consumer
  
Returns an unsubscribe message.
Consumer
  
Consumer overrides this method and initializes its ChannelSet based upon the value of messageType.
Consumer
 Inherited
Sends a Message from the MessageAgent to its destination using the agent's ChannelSet.
MessageAgent
Events
 EventSummaryDefined by
 Inherited Dispatched when an acknowledge message is received for a sent message.MessageAgent
 Inherited Dispatched when the underlying Channel the MessageAgent is using connects.MessageAgent
 Inherited Dispatched when the underlying Channel the MessageAgent is using disconnects.MessageAgent
 Inherited Dispatched when the underlying Channel the MessageAgent is using faults.MessageAgent
 Inherited Dispatched when a message fault occurs.MessageAgent
   Dispatched when a message is received by the Consumer.Consumer
 Inherited Dispatched when the connected property of the MessageAgent changes.MessageAgent
Property detail
messageTypeproperty
messageType:String  [read-only]

The server alias for the type of message the Consumer can process.

Implementation
    public function get messageType():String
resubscribeAttemptsproperty 
resubscribeAttempts:int  [read-write]

The number of resubscribe attempts that the Consumer makes in the event that the connection to its destination fails. A value of -1 enables infinite attempts.

Implementation
    public function get resubscribeAttempts():int
    public function set resubscribeAttempts(value:int):void
resubscribeIntervalproperty 
resubscribeInterval:int  [read-write]

The number of milliseconds between resubscribe attempts. If a Consumer doesn't receive an acknowledgement for a subscription request, it will wait the specified number of milliseconds before attempting to resubscribe. Setting the value to zero disables resubscriptions.

Implementation
    public function get resubscribeInterval():int
    public function set resubscribeInterval(value:int):void

Throws
ArgumentError — If the assigned value is negative.
selectorproperty 
selector:String  [read-write]

The selector for the Consumer. This is an expression that is passed to the destination which uses it to filter the messages delivered to the Consumer.

Before a call to the subscribe() method, this property can be set with no side effects. After the Consumer has subscribed to its destination, changing this value has the side effect of updating the Consumer's subscription to use the new selector expression immediately.

The remote destination must understand the value of the selector expression.

Implementation
    public function get selector():String
    public function set selector(value:String):void
subscribedproperty 
subscribed:Boolean  [read-only]

Indicates whether the Consumer is currently subscribed. The propertyChange event is dispatched when this property changes.

This property can be used as the source for data binding.

Implementation
    public function get subscribed():Boolean
subtopicproperty 
subtopic:String  [write-only]

Setting the subtopic when the Consumer is connected and subscribed has the side effect of unsubscribing and resubscribing the Consumer.

Implementation
    public function set subtopic(value:String):void
timestampproperty 
timestamp:Number  [read-write]

Contains the timestamp of the most recent message this Consumer has received. This value is passed to the destination in a receive() call to request that it deliver messages for the Consumer from the timestamp forward. All messages with a timestamp value greater than the timestamp value will be returned during a poll operation. Setting this value to -1 will retrieve all cached messages from the destination.

Implementation
    public function get timestamp():Number
    public function set timestamp(value:Number):void
Constructor detail
Consumer()constructor
public function Consumer(messageType:String = "flex.messaging.messages.AsyncMessage")

Constructs a Consumer.

Parameters
messageType:String (default = "flex.messaging.messages.AsyncMessage") — The alias for the message type processed by the service hosting the remote destination the Consumer will subscribe to.

Example
       function initConsumer():void
       {
           var consumer:Consumer = new Consumer();
           consumer.destination = "NASDAQ";
           consumer.selector = "operation IN ('Bid','Ask')";
           consumer.addEventListener(MessageEvent.MESSAGE, messageHandler);
           consumer.subscribe();
       }
            function messageHandler(event:MessageEvent):void
       {
           var msg:IMessage = event.message;
           var info:Object = msg.body;
           trace("-App recieved message: " + msg.toString());
       }
       

Method detail
disconnect()method
public override function disconnect():void

Disconnects the Consumer from its remote destination. This method should be invoked on a Consumer that is no longer needed by an application after unsubscribing. This method does not wait for outstanding network operations to complete and does not send an unsubscribe message to the server. After invoking disconnect(), the Consumer will report that it is in an disconnected, unsubscribed state because it will not receive any more messages until it has reconnected and resubscribed.

getSubscribeMessage()method 
protected function getSubscribeMessage():CommandMessage

Returns a subscribe message. This method should be overridden by subclasses if they need custom subscribe messages.

Returns
CommandMessage — The subscribe CommandMessage.
getUnsubscribeMessage()method 
protected function getUnsubscribeMessage():CommandMessage

Returns an unsubscribe message. This method should be overridden by subclasses if they need custom unsubscribe messages.

Returns
CommandMessage — The unsubscribe CommandMessage.
initChannelSet()method 
protected override function initChannelSet(message:IMessage):void

Consumer overrides this method and initializes its ChannelSet based upon the value of messageType.

Parameters
message:IMessage — The message that needs to be sent.
receive()method 
public function receive(timestamp:Number = 0):void

Requests any messages that are pending from the server from the specified timestamp to the present.

Parameters
timestamp:Number (default = 0) — The timestamp to request messages from.
subscribe()method 
public function subscribe(clientId:String = null):void

Subscribes to the remote destination.

Parameters
clientId:String (default = null) — The client id to subscribe with. Use null for non-durable Consumers. If the subscription is durable, a consistent value must be supplied every time the Consumer subscribes in order to reconnect to the correct durable subscription in the remote destination.

Throws
InvalidDestinationError — If no destination is set.
unsubscribe()method 
public function unsubscribe():void

Unsubscribes from the remote destination. In the case of durable JMS subscriptions, this will destroy the durable subscription on the JMS server.

Event detail
messageevent 
Event object type: mx.messaging.events.MessageEvent
MessageEvent.type property = mx.messaging.events.MessageEvent.MESSAGE

Dispatched when a message is received by the Consumer.

The MESSAGE event type; dispatched upon receipt of a message.

The value of this constant is "message".

The properties of the event object have the following values:

PropertyValue
bubblesfalse
cancelablefalse
currentTargetThe Object that defines the event listener that handles the event. For example, if you use myButton.addEventListener() to register an event listener, myButton is the value of the currentTarget.
messageThe message associated with this event.
targetThe Object that dispatched the event; it is not always the Object listening for the event. Use the currentTarget property to always access the Object listening for the event.




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/2/langref/mx/messaging/Consumer.html