Stage 5 3. Micro Services [online] _day05 RabbitMQ_6.RabbitMQ studies and research messaging middleware - entry procedures - Consumers

We write code in a consumer this function


first is this new level package

created entry procedures consumer

consumers also need to establish and mq channel. Create a channel to establish a connection


at the top of the queue are declared

below to write the core code listen queue. basicConsume method which is the core method

Ctrl + T-- select the last PublisherCallbackChannelImpl

have a lot of overloaded methods, we take one of them


Consumer realization method

Here with the original method of consumption
that there needs to be rewritten method

handleDelivery

When a message is received it will call hanleDelivery


drop a parameter consumerTag method in which implementation class is set to have a place where this consumerTag is consumed tags. This parameter is provided may not be provided

by the envelope is the envelope means. By envelope can get a lot of things to get, for example, the switch

can also get the message Id

parameter list each parameter means

the content of the output message

to try catch channel defined outside of the


Start the test 





If the execution method once again sent.


Then the receiver will automatically receive a message here

Process




 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11620723.html