4. What is server push
1.Notifications
Unread
messages
2. Message and Chat
3. Message wall ,history messages
5. 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.
7. 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
9. Push server compare
Payment &
Support OS Scalability Complexity NOTE
Open Source
WIN 、 MA
Limit For Ajax Push
Stream Hub C 、 Linux No Low
Free Server
、 Solaris
、 Unix
Windows
websocket
Node.js Mac OS Yes Medium Free
Web service
Linux
Ajax Push Linux, BSD Ajax push
No Low Free
(APE) & Mac OS Server
Windows websocket
Rabbit MQ Linux , Mac Yes Low Free Web
OS Service
10. 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
11. 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.
12. 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
15. The AMQP
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.
15
15
17. AMQP Server
broker
Channel
Consumer
• 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
17
17
18. 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” 的消息要到綁定的名稱隊列中
29. 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
30. 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
31. Send Message example
1 String message “This is a message”;
2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
Java example
31
32. For among consumers
1 String message “This is a message”;
2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)
32
33. Message publish
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)
33
37. Routing Rule
Routing rule= Domain. ID
• # one section matched
• * any section
Example :
Name Cosa.user.id156486 Cosa.group
Routing
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.#’)
38
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)
40
41.
42. Web Service Post
• Provide web push function thought web service.
Var Description Type
Domain *Domain Name String
ExName *Exchange Name String
ID ID String
(null for broadcast)
Msg *Message String
Durable Durable Bool
(Default False)
Ack No Ack require Bool
(Default True)
Auth *Authentication String
(Get form SSO) * Required
42
42
43. Web Service Response Code
• 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
43
43
45. 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