In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use TTL+DLX to achieve delayed messages, the article is very detailed, has a certain reference value, interested friends must read it!
Text:
There are two ways to achieve it on the Internet. I won't talk about the second one. If you want to upgrade rabbitmq, others will say what you can't do.
TTL + DLX way to achieve delay messages (java python related code is not shooting huang film! )
Masturbate code:
1. First, you have to create a new queue, a new switch to store delayed messages and set up the switch and routeing key to forward after the expiration of the new queue message ttl (my old switch is e_test key is K1)
The main code is:
Function mqInitYanChi ($eBay _ name _
{
/ / create a connection and channel
$channel = new AMQPChannel ($conn)
/ / create switch object
$ex = new AMQPExchange ($channel)
$ex- > setName ($e_name)
$ex- > setType (AMQP_EX_TYPE_DIRECT); / / must be set
$ex- > setFlags (AMQP_DURABLE); / / persistence may not be selected
Echo "exchange status:". $ex- > declareExchange ().\ n'
/ / bind the switch and queue and specify the routing key
/ / create a queue
$Q = new AMQPQueue ($channel)
$Q-> setName ($q_name)
# $Q-> setFlags (AMQP_DURABLE); / / persistence
$Q-> setArgument ('xmurf words, exchangeholders, etc.); / / set the ttl timeout to forward to e_test
$Q-> setArgument ('xmurf words, words, routinghouses, keyboards, etc. K1'); / / set the key of ttl timeout forwarding to K1
Echo "Message Total:". $Q-> declare (). "\ n"
Echo 'Queue Bind:. $Q-> bind ($e_name, $k_route). "\ n"
Return $ex
}
two。 That is, setting ttl when sending messages is actually very simple.
Main code:
$message = "Test delay!"
$ex1=mqInitYanChi ('ethereal yanchifang pr é cor qlocyanchi pr é cor K1l pr orchrary conn)
$attributes = array ('expiration' = > 5000); / / set to 5 seconds
$ex1- > publish ($message,'k1','1',$attributes)
In this way, the message sent to the q_yanchi queue can be overdue and forwarded to the routing-key K1 queue of the e_test-bound switch after five seconds.
The above is all the contents of the article "how to use TTL+DLX to achieve delayed messages". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.