Message push technology

Source: Internet
Author: User

Address: http://88250.b3log.org/web-message-push

Message push technology message push

Message push is a technology for Web application development. It means that the server actively delivers information to the client. It is mainly used to improve user experience and Prevent Users From refreshing pages and pulling data from the server. For example, an email item is automatically displayed in a web mail, and a new message is automatically prompted in instant messaging.

The message push mechanism involves two aspects:

  • Web-layer message push
  • Service layer Message Service
Web layer message push socket

You can use the socket interface for full-duplex communication. It can be implemented through Flash xmlsocket and Java Applet technologies.
However, because the implementation scheme is too tightly bound to the vendor's technology, it is not in the scope of Web standardization and there are some restrictions (Communication Port enabling security and client plug-ins), which are not described here.

HTTP request polling

Currently, web applications are based on the HTTP protocol, which specifies the request-Response Processing Model. The ticket communication mode at the application layer makes it difficult to implement server-side push in a pure sense.

To implement "push" based on the HTTP protocol, the client can initiate HTTP request polling, and the server returns a response after the request.

There are three types of push Based on the polling time and request processing method.

Simple round robin

Generally, the client initiates a request in a scheduled manner, and the server returns a response after processing.

  • Principle, simple client/server implementation
  • The polling interval can be adjusted based on the Application scenario.
  • The server needs to process a large number of requests
Long polling

After the client initiates a request, the server suspends the request (no response is returned) until it times out, encounters an exception, or needs to process the response (push content. After receiving the response, the client requests the server again (that is, polling) and processes the response.

  • High real-time performance
  • The server needs to manage pending requests
HTTP stream

After the client initiates a request, the server processes the request and writes data to the client through the HTTP stream until a timeout or exception occurs. The client requests the server again after the connection is disconnected, which is a type of long polling.

HTML 5 websocket

This is a standardized full-duplex Client Communication specification, but the server specification has not yet been formed, and considering the limited support of the existing client for HTML 5, it is not described here.

Multi-Client Support

The preceding introduction is intended for browser clients. in actual application scenarios, you also need to consider support from other clients, such as IOS and Android.

In terms of mobile clients, you need to consider the following points.

Diverse APIs

Local APIs Interfaces of different clients are different, but basic HTTP protocols are supported. Development Based on the HTTP protocol can minimize the differences.

Unstable network connection

Communication channels cannot be maintained for a long time after they are opened. The status management between the client and the server is complex.

Minimize traffic

Minimize network traffic to improve mobile client availability.

Service layer Message Service

Message is a low-coupling mode for communication between systems or components, and is the basis of the system-level asynchronous architecture.

In web message push, the server manages the application status. When the status changes, the client needs to be notified to complete message push.

Java Message Service

Pay attention to the following technical points:

Message domain
  • Point-to-point only one client can receive messages.


  • Publish/Subscribe
    Broadcast to the subscription client. Persistent subscription can be configured.
Message confirmation
  • When the session local transaction is committed, the received message is confirmed, and all messages are retransmitted during rollback.
  • Non-local transaction validation: Session. auto_acknowledge, session. client_acknowledge, session. dups_ OK _acknowledge
Technical Design Objectives
  • Support for browser client push
  • High performance, high reliability
  • Modular, not coupled with Applications
  • Support for multiple mobile clients in the future
Web Layer Design

The web layer is implemented using the open-source component pushlets.

Pushlets component

Based on the HTTP publishing/subscription model, pushlets provides poll and pull push methods. Here, pull is the long polling method, which is returned when there is a message.

  • Release: Get/post or call ethod call (dispatcher Interface)
  • Subscription: Get stream, pull/round robin Mode
  • Tree topic: hierarchical subscription
  • Protocol format: JS and XML (JSON is not supported yet)
  • Available for clients using HTTP protocol
  • Easy to scale: such as event source implementation
  • Easy integration: Web applications can be independent or web application components.
  • Multiple implementations: J2EE/servlets and JavaScript (Ajax)
JS Client
  • Js-pushlet-client.js
    • Use the "Hide IFRAME technique"
    • Format: JavaScript function events
  • Ajax-pushlet-client.js
    • Use XMLHttpRequest
    • Format: XML
    • HTTP stream not supported

The Ajax client is flexible and easy to encapsulate.

Service Layer Design

The service layer Message Service uses the application server JMS middleware. Status synchronization is achieved through the publishing/subscription model.

Procedure
  1. Configure topic subscription
  2. Publish a JMS message when the application status changes
  3. The JMS message listener publishes the received messages to pushlets.
  4. Write the message to the Web-layer message table.
Message table

Stores multiple message records pushed for the client to search for messages when the client refreshes.

Userid

Createdtime

Lastgettime

Clients

MSG

Type

Timeout

Targetsys

Srcsys

....

 

Xxx

Xxx

Xxx

["PC", "iOS"]

{}

Announcement

3 days

OA

OA

   

The message body is stored in the MSG field using a JSON string. Other fields can be extracted based on universality, such as the user name.

When the message listener receives the message, pushlets is pushed and the record is written (the record lastgettime is the write time, indicating that the message has been pushed ).

Set a scheduled task to delete the timeout record.

Logical architecture

The JMS message system is a separate communication bus service independent of the application system, and pushlets is a component in the application system.

The message table management component allows you to add and query and delete pushed message records.

Key points of time series pushing
  • Service layer message listening
  • Message table management
  • Pushlets configuration, license problem: pushlets is lgpl open source, must be encapsulated for commercial projects
  • Front-end fault tolerance Switch
Reference
  • Comet: server push technology based on HTTP persistent connections
  • Websocket in HTML 5
  • Official pushlets website
  • The javaee 6 tutorial-Java Message Service
  • JMS specification tutorial
Original article: Message push technology via Google Docs

Message push technology

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.