What is server push
3. Message wall ,history messages
1.Notifications
2. Message and Chat
Unread
messages
Ajax V.S Comet
•Ajax
–When user trigged (mouseover or click…) or using
“Periodic Refresh” to check data update.
•Comet
–Let browser and server connect on a long-request.
–Server can send data to client, client doesn't have
to send request first.
Ajax V.S Comet
Websocket
•WebSocket is a web technology providing full-
duplex communications channels over a
single TCP connection.
•The WebSocket protocol makes possible
more interaction between a browser and a
web site.
7
Technical survey
8
Push server compare
Support OS Scalability Complexity
Payment &
Open Source
NOTE
Stream Hub
WIN、MA
C、Linux
、Solaris
、Unix
No Low
Limit For
Free
Ajax Push
Server
Node.js
Windows
Mac OS
Linux
Yes Medium Free
websocket
Web service
Ajax Push
(APE)
Linux, BSD
& Mac OS
No Low Free
Ajax push
Server
Rabbit MQ
Windows
Linux , Mac
OS
Yes Low Free
websocket
Web
Service
Push server
•Stream Hub
–Light and quick Comet Server
•Node.js
–Base on Google Chrome V8 JavaScript engine.
–The fastest JavaScript engine
–Design for “Comet(long pulling) Request Server” and
capable to handle massive message exchange.
•Ajax Push (Ajax Push Engine)
–Apply for Comet(long pulling) Request Server and
easy to setup.
– Base on Node.js
Node.js
•Pro
–Build for Web Push .
–Java Script Engine (Event Driven) quick and light.
–Hottest technology now.
–Could provide multi-service in future.
–Modules support.
•Cons
–NodeJS is just a base engine, Still need to develop a whole
service.
–Stable need to test for porting on the machine.
Rabbit MQ
•Robust messaging for applications.
•Easy to use Runs on all major operating
systems.
•Supports a huge number of developer
platforms.
•Open source and commercially supported.
•Base on Advanced Message Queuing
Protocol (AMQP)
12
The Advanced Message Queuing Protocol (AMQP) is an open standard
application layer protocol for message-oriented middleware.
The defining features of AMQP are message orientation, queuing, routing
(including point-to-point and publish-and-subscribe), reliability and security.
The AMQP
15
15
•Message broker: a server to which AMQ clients connect using the AMQ protocol.
Message brokers can run in a cluster but these details are implementation specific
and are not covered by the specification.
•Consumer: a user is an entity that, by providing credentials in form of a password,
may or may not be authorized to connect to a broker.
•Connection: a physical connection (e.g., using TCP/IP or SCTP). A connection is
bound to a user.
•Channel: a logical connection that is tied to a connection
broker
Consumer
Channel
AMQP Server
17
17
AMQP protocol
•Advanced Message Queuing Protocol (AMQP)
–virtual host
•A host containes Exchange、Queue、Binding
–Exchange
•A message with with routing key
–Message Queue
•Keep message, and send it to message consumer
–Binding
•Message binding with routes rule,例如,指明具有路由
鍵“X” 的消息要到 定的名稱隊列中
綁
Push work flow
1.Server create a message queue. (without
binding user)
2.Client connect to server and bind the queue.
(connection established)
3.Server send messages to queue.
4.Client received messages from server.
29
Three step for create connection
1.Create connection factory.
2.Create connection.
3.Create channel.
1. ConnectionFactory factory = new ConnectionFactory();
2. factory.setHost("140.92.25.159");
3. Connection connection = factory.newConnection();
4. Channel channel = connection.createChannel();
Java example
30
Send Message example
1 String message “This is a message”;
2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
Java example
31
For among consumers
32
1 String message “This is a message”;
2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)
Message publish
33
1 String message “This is a message”;
2 channel.exchange_declare(exchange='logs', type='fanout')
2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)
Routing message
34
35
1 String message “This is a message”;
2 channel.queue_bind(exchange=exchange_name,
queue=queue_name, routing_key='black')
3 channel.exchange_declare(exchange='direct_logs', type='direct')
4 channel.basic_publish(exchange=‘direct_logs’,
routing_key=severity, body=message)
Pattern message
36
Routing Rule
Routing rule= Domain. ID
•# one section matched
•* any section
Example :
Name
Routing
Cosa.user.id156486 Cosa.group
Cosa.* O O
Cosa.# X O
37
37
38
1 String message “This is a message”;
2 channel.queue_bind(exchange=exchange_name,
queue=queue_name, routing_key=‘*.black.#’)
PRC
39
40
1 String message “This is a message”;
2 ch.basic_publish(exchange='', routing_key=props.reply_to,
properties=pika.BasicProperties(correlation_id = \
props.correlation_id), body=str(response))
3 ch.basic_ack(delivery_tag)
Web Service Post
•Provide web push function thought web service.
Var Description Type
Domain *Domain Name String
ExName *Exchange Name String
ID
(null for broadcast)
ID String
Msg *Message String
Durable
(Default False)
Durable Bool
Ack
(Default True)
No Ack require Bool
Auth *Authentication
(Get form SSO)
String
* Required
42
42
Web Service Response Code
Var Description
200 Message sant
401 Not authorize.
404 Domain or exchange
not exist
406 Not Acceptable
500 Service is busy or
maintain.
* Required
•Response code
43
43
‹#›
Summary
•Push server is …
–A style of Internet-based communication where
the request for a given transaction is initiated by
the publisher or central server.
•Rabbit MQ is
– Aopen source message broker software (i.e.,
message-oriented middleware) that implements
the Advanced Message Queuing Protocol
(AMQP) standard.
45