RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Exchange - exchanger lossis exchange point. Cov lus raug xa mus rau nws. Exchange faib cov lus nyob rau hauv ib los yog ntau dua kab. Nws xa cov lus mus rau ib kab raws li cov links tsim (bindings) nruab nrab ntawm nws thiab lub queue.

Exchange tsis yog Cov txheej txheem. Yog vim li cas ntawm scalability exchange yog ib txoj hlua (ib qho txuas mus rau lub module nrog cov cai qhov twg lub logic routing yog) nyob rau hauv lub embedded database mnesia. 1 txhiab exchangers yuav siv 1MB ntawm lub cim xeeb xwb.

Cov txheej txheem

  • RabbitMQ. Ntu 1. Kev Taw Qhia. Erlang, AMQP thiab RPC
  • RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv
  • RabbitMQ. Ntu 3. Nkag siab cov lus nug thiab kev khi
  • RabbitMQ. Ntu 4. Hais txog dab tsi yog cov lus thiab thav ntawv
  • RabbitMQ. Ntu 5: Kev Tshaj Tawm thiab Siv Cov Lus Qhia Ua Haujlwm
  • RabbitMQ. Ntu 6. Txheej txheem cej luam ntawm Federation thiab Shovel Modules
  • RabbitMQ. Part 7. Paub meej txog kev sib txuas thiab Chanel
  • RabbitMQ. Part 8. RabbitMQ hauv .NET
  • RabbitMQ. Ntu 9. Kev soj ntsuam

Direct Txauv

Direct exchange - siv thaum xav tau xa cov lus rau cov kab tshwj xeeb. Cov lus yog luam tawm rau tus exchanger nrog ib qho tshwj xeeb tus yuam sij routing thiab nkag mus rau hauv tag nrho cov kab uas cuam tshuam nrog qhov sib pauv no nrog tus yuam sij routing zoo sib xws. Tus yuam sij routing yog ib txoj hlua. Kev sib piv yog ua tiav siv tshuaj xyuas cov hlua rau kev sib npaug.

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

В rabbitmq muaj tswvyim default exchanger. Qhov no direct exchange tsis muaj npe. Yog hais tias lub neej ntawd exchanger yog siv, ces cov lus yuav raug xa mus rau ib tug queue nrog ib lub npe sib npaug rau lus routing key.

Lub ntsiab lus pauv

Topic exchange - zoo sib xws direct exchange enables xaiv routing los ntawm kev sib piv tus yuam sij routing. Tab sis, nyob rau hauv cov ntaub ntawv no, tus yuam sij yog muab los ntawm template. Thaum tsim ib lub template, siv 0 los yog ntau lo lus (cov ntawv AZ и az thiab cov lej 0-9), sib cais los ntawm ib qho chaw, nrog rau cov cim * и #.

  • * - tuaj yeem hloov tau raws nraim 1 lo lus
  • # - tuaj yeem hloov tau 0 los yog lus ntau

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Pib los ntawm version RabbitMQ 2.4.0 routing algorithm rau topic exchange pib ua hauj lwm kom txog thaum 145 sij hawm sai dua. Lawv ua tiav qhov no los ntawm kev siv txoj hauv kev sim siv, uas implies tus sawv cev ntawm templates raws li ib tug ntoo qauv. Piv txwv li templates a.b.c, a.*.b.c, a.#.c и b.b.c yuav sawv cev los ntawm cov qauv hauv qab no:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Cov qauv sib txuam yog tshawb xyuas pib ntawm lub hauv paus thiab mus los ntawm sab saum toj mus rau hauv qab.

Nta:

  • kev siv ntawm no exchanger yuav ua tau ib qho kev xaiv zoo rau kev txhim kho app yav tom ntej, vim templates tuaj yeem hloov kho txhua zaus kom cov lus tshaj tawm zoo ib yam direct exchange los yog fanout exchange
  • templates uas siv * sai duatshaj cov qauv uas siv #.
  • topic exchange qeeb qeeb direct exchange

Fanout Txauv

Fanout exchange - tag nrho cov lus raug xa mus rau txhua kab txawm hais tias tus yuam sij routing tau teev nyob rau hauv cov lus.

Nta:

  • RabbitMQ tsis ua hauj lwm nrog routing keys thiab templates uas muaj txiaj ntsig zoo rau kev ua haujlwm. Qhov no yog qhov ceev tshaj plaws exchange;
  • txhua tus neeg siv khoom yuav tsum muaj peev xwm ua txhua yam lus;

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Headers Exchange

Headers exchange - directs cov lus rau cov kab sib txuas raws li kev sib piv ntawm cov khub (qhov tseem ceeb, tus nqi) cov khoom headers khi thiab cov khoom zoo sib xws. headers yog ib tug Dictionary<ключ, значение>.

Yog tias koj ntxiv tus yuam sij tshwj xeeb rau phau ntawv txhais lus x-match nrog lub ntsiab lus any, ces cov lus yog routed yog cov khub (qhov tseem ceeb, tus nqi) ib feem match. Tus cwj pwm no zoo ib yam li tus neeg teb xov tooj or.

var bindingArguments = new Dictinary<String, Object>();
bindingArguments.add("x-match", "any");

Default key x-match muaj tus nqi all. Qhov no txhais tau hais tias cov lus raug xa mus thaum cov khub (qhov tseem ceeb, tus nqi) tag nrho phim. Tus cwj pwm no zoo ib yam li tus neeg teb xov tooj and.

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Nta:

  • ntxiv yooj
  • ntxiv kev suav nyiaj siv ua haujlwm. Txhua tus khub (qhov tseem ceeb, tus nqi) ntawm tus cwj pwm headers yuav tsum tau txheeb los ntawm lub npe tseem ceeb ua ntej xam cov lus routing qhov tseem ceeb. qeeb dua lwm hom kev sib pauv.

Ib txwm Hashing Exchange

Qhov no exchanger yog plugin и tsis ua hauv в RabbitMQ.

Consistent-hashing exchange (hloov nrog hashing zoo ib yam) - siv thaum muaj ntau cov kab uas muaj peev xwm tau txais cov lus thiab thaum koj xav kom sib npaug ntawm cov load ntawm lawv. Cov lus yog txuam nrog cov queue los ntawm qhov hnyav (ib txoj hlua tus nqi los ntawm 0 - n).

Qhov hnyav sib npaug ntawm cov kab - qhia tias txhua kab yuav tau txais txog tus nqi qub lus (txhua cov lus yuav muab tso rau hauv ib kab xwb). Tsis muaj kev lees paub tag nrho ntawm kev faib tawm ntawm cov lus.

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Hash xam raws li routing key los yog khoom headers lus. Yog tias tag nrho cov lus tshaj tawm muaj cov yuam sij sib txawv, lossis headers, ces qhov kev faib tawm yuav tshwm sim los ntawm qhov hnyav. Txwv tsis pub, tus yuam sij routing yuav raug siv, lossis headers.

Yuav tsum pab thaum cov neeg siv khoom siv yuav tsum tau nce siab dua li kev daws teeb meem nrog ntau tus neeg siv khoom siv tib kab.

Kev sib xyaw ntawm cov khoom sib txuas (E2E)

Tus cwj pwm ntawm txhua tus neeg sib pauv tuaj yeem ua ke nrog kev sib txuas lus Exchange-rau-Exchange (kev sib txuas ntawm exchangers tsis suav nrog hauv cov specification AMQP. Qhov no yog ib txoj kev txuas ntxiv los ntawm sab RabbitMQ).

Graphical sawv cev ntawm cov lus ntws:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Ntawm kev siv nyiaj E2E peb tuaj yeem nrhiav txoj cai scalable configuration uas ua tau raws li qhov xav tau tam sim no thiab loj hlob.

Tsim ib qho Exchange

Lub exchanger yog tsim los ntawm synchronous RPC thov rau lub server. Kev thov yog ua los ntawm txoj kev Exchange.Declare, hu nrog parameters:

  • exchanger npe
  • yam exchanger
  • lwm txoj kev xaiv

Tsim qauv exchange nrog kev pab RabbitMQ.Client:

//...
channel.ExchangeDeclare(
    exchange: "my_exchange",
    type: "direct",
    durable: "false",
    autoDelete: "false",
    arguments: null
);
//...

  • exchange - lub npe ntawm tus exchanger uas peb xav tsim. Lub npe yuav tsum yog qhov tshwj xeeb
  • type - hom exchanger
  • durable - yog ntsia true, ces exchange yuav nyob ruaj khov. Nws yuav khaws cia rau hauv disk thiab yuav muaj peev xwm ciaj sia lub server / broker rov pib dua. Yog tus nqi false, ces exchange yog ib ntus thiab yuav raug tshem tawm thaum lub server / broker rov pib dua
  • autoDelete - rho tawm tsis siv neeg. Exchange yuav raug rho tawm thaum tag nrho cov kab sib txuas raug tshem tawm
  • arguments yog cov lus tsis txaus siab. Feem ntau, los ntawm kev sib cav teeb tsa alternative exchange (lwm exchanger). Yog tias cov lus tsis tuaj yeem mus dhau ntawm txoj kev qub, nws tuaj yeem xa mus rau lwm qhov kev sib pauv hloov mus rau txoj kev sib txawv.

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Yog creation exchange yog ua tau, ces tus neeg rau zaub mov yuav xa tus neeg siv khoom synchronous RPC teb Exchange.DeclareOk. Yog creation yog tsis yooj yim sua (muaj qhov tsis kam lees ntawm qhov kev thov Exchange.Declare) ces channel yuav kaw server siv cov lus txib asynchronous Channel.Close thiab tus neeg siv yuav tau txais kev zam OperationInterruptedException, uas yuav muaj qhov yuam kev code thiab nws cov lus piav qhia.

Ib tug exchanger yuav tsum tau tsim ua ntej tshaj tawm. Yog tias koj tshaj tawm cov lus rau qee tus neeg sib pauv uas tsis muaj nyob - RabbitMQ ntsiag to tshem nws.

Tsim ib qho Exchange GUI

Mus rau admin vaj huam sib luag RabbitMQ hauv qab neeg siv guest (username: guest thiab tus password: guest). Thov nco ntsoov tias tus neeg siv guest tuaj yeem txuas los ntawm localhost xwb. Tam sim no cia peb mus rau lub tab Exchanges thiab nias rau Add a new exchange. Sau cov khoom:

RabbitMQ. Ntu 2. Nkag siab txog kev sib pauv

Feem ntau ntawm cov khoom tau piav qhia saum toj no. Ntawm no peb nco ntsoov tias yog peb teem Internal, ces qhov pauv tsuas yog siv rau E2E. Producer yuav tsis muaj peev xwm xa lus mus rau xws li kev sib pauv.

xaus

Thaum tsim ib qho system, nws yooj yim los piav txog cov topology txoj kev siv ib daim duab. Tab sis ua ntej koj pib tsim ib daim duab, nws tsim nyog hais txog txoj hauv kev nrog cov tsheb loj, vim tias. lawv xav tau siab dua (kev ua tau zoo). Tom ntej no, koj tuaj yeem faib cov tsheb khiav. Thiab ces pib tsim.

Yog hais tias nyob rau hauv daim duab tsim muaj finite set routing yuam sij, ces, nws yog tsim nyog saib rau ob peb fanout exchange, uas yog 1: 1 ntsig txog tus yuam sij routing. Nco ntsoov tias fanout exchange ceev tshaj plaws.

Yog tus naj npawb ntawm txoj kev nyiam mus infinity, nws yog tsim nyog them sai sai rau topic exchange los yog, yog tias tus qauv tsis xav tau, ces koj tuaj yeem xaiv direct exchnge, vim nws sai dua topic exchange.

Kev sib xyaw ntawm ntau yam exchange yuav tsum pab koj nrhiav qhov yog. scalable configuration, uas ua tau raws li ob qho tib si tam sim no thiab kev loj hlob ntawm qhov yuav tsum tau ua.

Cov naj npawb ntawm exchange thiab cov kab yuav tsum tsawg kawg yog piv rau cov lej ntawm txoj kev.

Hauv tsab xov xwm tom ntej no, peb yuav pib nkag siab ntau ntxiv txog Queues thiab Bindings.

ua tim khawv

Tau qhov twg los: www.hab.com

Ntxiv ib saib