PayPal _redis Advanced Apps-Publish and subscribe

Source: Internet
Author: User

Redis Advanced Apps-Publishing and subscriptions

One, publish and subscribe (pub/sub) function

Second, publish and subscribe (PUB/SUB) mechanism

Iii. implementation of Redis Publishing and subscription (PUB/SUB)

one, publish and subscribe (pub/sub) function

The Pub/sub function (Meanspublish, Subscribe) is the publish and subscribe function. In event-based systems, Pub/sub is a widely used communication model that uses events as a basic communication mechanism to provide loosely coupled interaction patterns required by large-scale systems: subscribers (such as clients) express an event or class of events that they are interested in receiving as an event subscription; a publisher (such as a server ) to notify the relevant subscribers of events of interest to subscribers at any time

The simple model for publish/subscribe is as follows:


ii. Publication and Subscription (PUB/SUB) Categories

1. Time is non-coupled: Publishers and Subscribers do not have to be online simultaneously, they do not have to participate in the interaction simultaneously


2, Space non-coupling: Publishers and Subscribers do not need to know each other's location. Publishers publish events through the Event Service, and subscribers get events indirectly through the event service. Publishers and Subscribers do not need to have a reference directly to each other, nor do they have to know how many subscribers or publishers are involved in the interaction


3, synchronous non-coupling: publisher/Subscriber is the asynchronous mode. Publishers can continually produce events, and subscribers (via a callback) can asynchronously get notification of events that generate them

Summarize:

Pub/sub is a distributed interaction model that can be applied to scalable, loosely coupled systems.

In the abstraction layer, its time non-coupling, spatial non-coupling and synchronous non-coupling can allow the participants to operate independently without relying on another, which has some extensibility, however, in the implementation layer, extensibility is still constrained by other reasons.

For example: 1, flexible subscription requires complex filtering and routing algorithms;

2, high availability overhead (event listening, log retransmission);

3. The network traffic consumption caused by the message recognition;

4, the huge subscriber data brings the system overhead;

The development and utilization of event-based PUB/SUB middleware can improve the efficiency of the system to some extent

Iii. Implementation of Redis Publishing and Subscription (Pub/sub)

Redis implements the subscription and release model through commands such as publish, subscribe, unsubscribe, which provide two information mechanisms, namely subscription/publish to channel and subscribe/publish to mode. In this implementation, the sender (the client sending the message) does not send the information directly to a particular recipient (the client receiving the information), but instead sends the information to the channel or pattern, and then the channel/mode forwards the information to all subscribers interested in the channel

1, publish, subscribe, unsubscribe, psubscribe, punsubscribe command description

A, subscribe: subscription Channel

B, unsubscribe: Unsubscribe Channel

C, publish: Go to a channel, post a message

D, Psubscribe: Subscription mode Channel

E, Punsubscribe: Unsubscribe mode Channel

2, channel subscription and information release Simple example

(Note: Subscriber subscribes to Channel One, and then publishes the message ' Hello World ', at which point the Subscriber displays the published message.)

3, pattern-based subscription and information release Simple example

4. Message Format

4.1, if the subscription channel, then return message type (message), channel name, specific message content

4.2, if is based on the mode, then return the message type (pmessage), the pattern name, the specific channel name, the specific message content

5. Understanding subscription channel and subscription mode

To subscribe to the channel, the client needs to indicate the name of the channel for the specific subscription. Instead, the subscription mode, the client can subscribe to a pattern with the * number, if the name of a/certain channel and this pattern match, then when there is information sent to this/these channels, the client will also receive this/these channels of information

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PayPal _redis Advanced Apps-Publish and subscribe

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.