Flex-producer consumer

Source: Internet
Author: User

From: http://www.riastep.com /? P = 101

Http://www.riastep.com /? Cat = 6

 

In Flex, there are two transmission modes (Request/response) and (publish/subscribe ).

Producer (producer)/consumer (consumer), producer and consumer use messaging to communicate, obviously using the publishing/subscription mechanism. The producer is used to publish messages, and the consumer is used to subscribe to consumers. For example, a client subscribes to a message from the server. When the message changes, the client that subscribes to the message will receive the updated message and update it instantly. Therefore, we can make a lot of applications with real-time interaction requirements, such as chat rooms, Im, meeting rooms, online stocks, etc...

 

Message Publishing component-producer

Common attributes:

  1. ID-producer Instance name.
  2. Destination-the target of the message service. This value should match the target entry in the messaging-config.xml file.
  3. Channelset-provides access to the Message channel class configured for the producer.
  4. Autoconnect-if it istrue, Then the producer will be called for the first timesend()Method is automatically connected to its target. Iffalse, Must be explicitly calledconnect()Method to establish a connection with the target. By default, this attribute istrueBut applications that need to operate in offline mode may set this attributefalseTo preventsend()Method.
  5. Connected-read-only attribute. Indicates whether the producer is connected to its target through its channelset.
  6. Reconnectattempts-Number of reconnection attempts when a connection to the target is lost or the target to which the connection is closed.
  7. Reconnectinterval-Number of milliseconds between retries.
  8. Requesttimeout-sets the request timeout (in seconds) for sent messages. If no confirmation, response, or error is received from the remote target before the timeout is reached, an error is reported on the client.
  9. Subtopic-access to the subtopic of the remote target.

Common Methods:

  1. connect():void--Connect the producer to its target. When establishing a connection,connectedThe property is changedtrue。
  2. Disconnect (): void -- disconnect the producer from its remote target. This method does not wait until the unfinished network operation is completed. Calldisconnect()Method, the producer reports that it is not connected and will not receive any uncompleted message confirmation or error. If you are trying to reconnect, disconnecting will stop the attempt to automatically reconnect.
  3. Send (message: iMessage): void -- send a specified message to the target. If you use producer to publish/subscribe to message transmission, unless you use a custom message type and the message target on the server is configured to process custom messages, otherwise, only asyncmessage messages can be sent.

Common events:

  1. Fault-schedule a fault event when a message error occurs.
  2. Acknowledge-messageresponder schedules the confirmation result of the sent message.
  3. Channelconnect-scheduling when establishing a connection with the channel.
  4. Channeldisconnect-scheduling when disconnected from the channel.
  5. Channelfault-scheduling when an error occurs in the channel used.

After a connection is established between the producer and disconnect, the connected attribute is set to true.Public Function send (message: iMessage): The connected attribute is automatically checked before the void method sends a message. After the producer sends a message using the send () method, the acknowledge event is automatically scheduled when the message is sent successfully. If the message fails to be sent, the fault event is automatically scheduled. We can process the event in the event listening method. If the client and severs lose connection for some reason, the producer automatically tries to connect to the server according to the reconnectattempts and reconnectinterval settings. If reconnectattempts is set to-1, the producer will try to reconnect to the server without limit. If reconnectattempts is set to 0, no operation will be attempted to reconnect to the server.

 

Message subscription and receiving component-consumer

Common attributes:

  1. ID-consumer Instance name.
  2. Destination-the target of the message service. This value should match the target entry in the messaging-config.xml file.
  3. Channelset-provides access to the Message channel class configured for consumer.
  4. Connected-read-only attribute. Indicates whether the consumer has connected to the target through its channelset.
  5. Subscribed-read-only attribute. Indicates whether the consumer is currently in the subscription status.
  6. Reconnectattempts-Number of reconnection attempts when a connection to the target is lost or the target to which the connection is closed.
  7. Reconnectinterval-Number of milliseconds between retries.
  8. Requesttimeout-sets the request timeout (in seconds) for sent messages. If no confirmation, response, or error is received from the remote target before the timeout is reached, an error is reported on the client.
  9. Subtopic-access to the subtopic of the remote target.
  10. Selector-string type. The consumer selector.

Common Methods:

  1. subscribe(clientId:String = null):void-Subscribe to a remote target.
  2. Unsubscribe (preservedurable: Boolean = false): void-Unsubscribe from a remote destination. For persistent JMS subscriptions, this will destroy the persistent subscription on the JMS server.
  3. Receive ()-Requests all messages queued for this consumer on the server. This method should be used only for consumers subscribed through non-real-time and non-polling channels. If you have not subscribed to consumer, this method is not available.
  4. Disconnect ()-disconnect a consumer from its remote target. This method should be called on the consumer that is no longer needed by the application after the subscription is canceled. This method does not wait for unfinished network operations to complete or send a message to the server to cancel the subscription. After disconnect () is called, consumer will report that it is in the disconnected unsubscribe status because it will not receive any other messages before re-establishing the connection and re-subscription. If you are attempting to subscribe again, disconnecting will stop the attempt to automatically subscribe again.

Common events:

  1. Message-consumer is scheduled to receive messages.
  2. Fault-schedule a fault event when a message error occurs.
  3. Channelconnect-scheduling when establishing a connection with the channel.
  4. Channeldisconnect-scheduling when disconnected from the channel.
  5. Channelfault-scheduling when an error occurs in the channel used.

After a connection is established between the consumer and the target referred to by disconnect, the connected attribute is set to true, and the subscribed attribute is set to true after messages are successfully subscribed using the subscribe () method. When a message is sent to the client,Consumer automatically schedules the message event. We can handle it in the message event listening method.If the client and severs lose connection for some reason, the producer automatically tries to connect to the server according to the reconnectattempts and reconnectinterval settings. If reconnectattempts is set to-1, the producer will try to reconnect to the server without limit. If reconnectattempts is set to 0, no operation will be attempted to reconnect to the server.Consumer uses itsUnsubscribe () method.

 

Other materials: http://www.javaeye.com/topic/549037

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.