keys know how是什么意思一集有多少时间

英语的一张完形填空A foolish man went to a butcher’s shop(肉店) to buy a piece of meat.16__he didn’t know how to 17__it,he asked the butcher to tell him the way of cooking meat.The butcher told him about that.“But I can not 18__what y_百度作业帮
英语的一张完形填空A foolish man went to a butcher’s shop(肉店) to buy a piece of meat.16__he didn’t know how to 17__it,he asked the butcher to tell him the way of cooking meat.The butcher told him about that.“But I can not 18__what y
英语的一张完形填空A foolish man went to a butcher’s shop(肉店) to buy a piece of meat.16__he didn’t know how to 17__it,he asked the butcher to tell him the way of cooking meat.The butcher told him about that.“But I can not 18__what you say.19__ you please write them down for me?” The butcher was kind enough to do so.The man went home 20 with the piece of meat in his hand and the note in his pocket.A dog walked after him 21__ the way.It suddenly jumped at him and took away the _22 from the man and ran off.He stood there and didn’t know what to do.After a while,he began to 23 and said to himself,“Don’t 24__.He doesn’t know how to cook it because the note is 25__in my pocket.” (butcher 屠夫)( ) 16.A Because B When C So C If( ) 17.A take B buy C cook D bring( ) 18.A forget B leave C understand D remember( ) 19.A.Do B Are C Would D Could( ) 20.A sadly B happily C luckily D badly( ) 21.A.on B by C in D to( ) 22.A.note B meat C money D food( ) 23.A laugh B call C cry D shout( ) 24.A go B hurry C worry D mind( ) 25.A still B not C yet D missing
Keys:16 A17 C18 D19 C20 B21 A22 B23 A24 D25 AKnow something about this track?Help build Last.fm by .
Listening Trend
79,523listeners all time
357,794scrobbles all time
Recent listeners trend:
Explore more
Listen to, buy or share
Add to library
<b data-count="7,794
<b id="listenerCount" data-count="7
is listening to
Have you ever felt so strongThat it made you feel weakLong days, long nightsAnd you just can't sleep
Download the new Last.fm Scrobbler
The Scrobbler automatically adds the tracks you play to your Last.fm profile.
Leave a comment.
one of my favourite songs ever
the lyrics!
Such a beautiful song ?
muito bom :)
I'd risk the fall just to know how it feels to fly ?
The greatest song she's recorded. Ever.
Alicia Vocally Slays This! Omggg. just fantastic
the emotions she gives off in this song carries me & high as the notes she's hitting.
Have you ever felt so strong...that it made you feel weak?...long days, long nights & you just can't sleep, &3
Such a beautiful, wonderful song!
WHAT A VOICE SHE HAS !!
1 I ATTENDED HER CONCERT ALSO!!
AMAZING SONG!!
is a very good song i like :)
Love her voice!
so beautiful
Top Listener
Top Listener
Top Listener
Top ListenerPosted by Jason
Posted in ,
Posted on 01-13-2009
If you like Rabbit and Warrens checkout RabbitMQ in Action in the sidebar.
The goal was simple enough: decouple a particular type of analysis out-of-band from mainstream e-mail processing. We started down the MySQL road…put the things to be digested into a table…consume them in another daemon…bada bing bada boom. But pretty soon, complex ugliness crept into the design phase… You want to have multiple daemons servicing the queue?…no problem we&#8217;ll just hard code node numbers…what? you want dynamic load re-assignment when daemons join and die?
You get the idea…what was supposed to be simple (decouple something) was spinning its own . It seemed like a good time to see if every problem was looking like a nail (table), because all we had were hammers (MySQL).
A short search later, and we entered the world of message queueing. No, no…we know obviously what a message queue is. Heck, we do e-mail for a living. We&#8217;ve implemented all sorts of specialized, high-speed, in-memory queues for e-mail processing. What we weren&#8217;t aware of was the family of off-the-shelf, generalized, message queueing (MQ) servers…a language-agnostic, no-assembly required way to wire routing between applications over a network. A message queue we didn&#8217;t have to write ourselves? Hold your tongue.
Open up your queue…
Cutting to the chase, over the last 4 years there have been no shortage of open-source message queueing servers written. Most of them are one-offs by folks like LiveJournal to scratch a particular itch. Yeah, they don&#8217;t really care what kind of messages they carry, but their design parameters are usually creator-specific (and message persistence after a crash usually isn&#8217;t one of them). However, there are three in-particular, that are designed to be highly flexible message queues for their own sake:
Apache ActiveMQ gets the most press, but it appears to have some issues not losing messages. Next.
ZeroMQ and RabbitMQ both support an open messaging protocol called AMQP. The advantage to AMQP is that it&#8217;s designed to be a highly-robust and open alternative to the two commercial message queues out there (IBM and Tibco). Muy bueno. However, ZeroMQ doesn&#8217;t support message persistence across crashes reboots. No muy bueno. That leaves us with RabbitMQ. (That being said if you don&#8217;t need persistence ZeroMQ is pretty darn interesting…incredibly low latency and flexible topologies).
That leaves us with the carrot muncher…
RabbitMQ pretty much sold me the minute I read “written in Erlang”.
is a highly parallel programming language developed over at Ericsson for running telco switches…yeah the kind with six bazillion 9s of uptime. In Erlang, its supposedly trivial to spin off processes and then communicate between them using message passing. Seems like the ideal underpinning for a message queue no?
Also, RabbitMQ supports persistence. Yes Virginia, if your RabbitMQ dies, your messages don&#8217;t have to die an unwitting death…they can be reborn in your queues on reboot. Oh…and as is always desired @ DigiTar, it . All that being said, RabbitMQs documentation is well…horrible. Lemme rephrase, if you already understand AMQP, the docs are fine. But how many folks know AMQP? It&#8217;d be like MySQL docs assuming you knew some form of SQL…er…nevermind.
So, without further ado…here is a reduction of a weeks&#8217; worth of reading up on AMQP and how it works in RabbitMQ…and how to play with it in Python:
Playing telephone
There are four building blocks you really care about in AMQP: virtual hosts, exchanges, queues and bindings. A virtual host holds a bundle of exchanges, queues and bindings. Why would you want multiple virtual hosts? Easy. A username in RabbitMQ grants you access to a virtual host…in its entirety. So the only way to keep group A from accessing group B&#8217;s exchanges/queues/bindings/etc. is to create a virtual host for A and one for B. Every RabbitMQ server has a default virtual host named “/”. If that&#8217;s all you need, you&#8217;re ready to roll.
Exchanges, Queues and bindings…oh my!
Here&#8217;s where my railcar went off the tracks initially. How do all the parts thread together?
Queues are where your “messages” end up. They&#8217;re message buckets…and your messages sit there until a client (a.k.a. consumer) connects to the queue and siphons it off. However, you can configure a queue so that if there isn&#8217;t a consumer ready to accept the message when it hits the queue, the message goes poof. But we digress…
The important thing to remember is that queues are created programmatically by your consumers (not via a configuration file or command line program). That&#8217;s OK, because if a consumer app tries to “create” a queue that already exists, RabbitMQ pats it on the head, smiles gently and NOOPs the request. So you can keep your MQ configuration in-line with your app code…what a concept.
OK, so you&#8217;ve created and attached to your queue, and your consumer app is drumming its fingers waiting for a message…and drumming…and drumming…but alas no message. What happened? Well you gotta pump a message in first! But to do that you&#8217;ve got to have an exchange…
Exchanges are routers with routing tables. That&#8217;s it. End stop. Every message has what&#8217;s known as a “routing key”, which is simply a string. The exchange has a list of bindings (routes) that say, for example, messages with routing key “X” go to queue “timbuktu”. But we get slightly ahead of ourselves.
Your consumer application should create your exchanges (plural). Wait? You mean you can have more than one exchange? Yes, you can, but why? Easy. Each exchange operates in its own userland process, so adding exchanges, adds processes allowing you to scale message routing capacity with the number of cores in your server. As an example, on an 8-core server you could create 5 exchanges to maximize your utilization, leaving 3 cores open for handling the queues, etc.. Similarly, in a RabbitMQ cluster, you can use the same principle to spread exchanges across the cluster members to add even more throughput.
OK, so you&#8217;ve created an exchange…but it doesn&#8217;t know what queues the messages go in. You need “routing rules” (bindings). A binding essentially says things like this: put messages that show up in exchange “desert” and have routing key “ali-baba” into the queue “hideout”. In other words, a binding is a routing rule that links an exchange to a queue based on a routing key. It is possible for two binding rules to use the same routing key. For example, maybe messages with the routing key “audit” need to go both to the “log-forever” queue and the “alert-the-big-dude” queue. To accomplish this, just create two binding rules (each one linking the exchange to one of the queues) that both trigger on routing key “audit”. In this case, the exchange duplicates the message and sends it to both queues. Exchanges are just routing tables containing bindings.
Now for the curveball: there are multiple types of exchanges. They all do routing, but they accept different styles of binding “rules”. Why not just create one type of exchange for all style of rules? Because each rule style has a different CPU cost for analyzing if a message matches the rule. For example, a “topic” exchange tries to match a message&#8217;s routing key against a pattern like “dogs.*”. Matching that wildcard on the end takes more CPU than simply seeing if the routing key is “dogs” or not (e.g. a “direct” exchange). If you don&#8217;t need the extra flexibility of a “topic” exchange, you can get more messages/sec routed if you choose the “direct” exchange type. So what are the types and how do they route?
Fanout Exchange &#8211; No routing keys involved. You simply bind a queue to the exchange. Any message that is sent to the exchange is sent to all queues bound to that exchange. Think of it like a subnet broadcast. Any host on the subnet gets a copy of the packet. Fanout exchanges route messages the fastest.
Direct Exchange &#8211; Routing keys are involved. A queue binds to the exchange to request messages that match a particular routing key exactly. This is a straight match. If a queue binds to the exchange requesting messages with routing key “dog”, only messages labelled “dog” get sent to that queue (not “dog.puppy”, not “dog.guard“…only “dog”).
Topic Exchange &#8211; Matches routing keys against a pattern. Instead of binding with a particular routing key, the queue binds with a pattern string. The symbol # matches one or more words, and the symbol * matches any single word (no more, no less). So “audit.#” would match “audit.irs.corporate”, but “audit.*” would only match “audit.irs”. Our friends at RedHat have put together a great image to express how topic exchanges work:
(by me and a very cool Uruguayan dude&#8230;Mr. Alvaro)
Persistent little bugger…
You spend all that time creating your queues, exchanges and bindings, and then BANG!…the server fries faster than the griddle at McDonald&#8217;s. All your queues, exchanges and bindings are there right? Oh geez…what about the messages in the queues you hadn&#8217;t serviced yet?
Relax, providing you created everything with the default arguments, it&#8217;s all gone…poof…whoosh…nada…nil. That&#8217;s right, RabbitMQ rebooted as empty as a baby&#8217;s noggin. You gotta redo everything kemosabe. How do you keep this from happening in the future?
On your queues and your exchanges there&#8217;s a creation-time flag called “durable”. There&#8217;s only one thing durable means in AMQP-land…the queue or exchange marked durable will be re-created automatically on reboot. It does not mean the messages in the queues will survive the reboot. They won&#8217;t. So how do we make not only our config but messages persist through a reboot?
Well the first question is, do you really want your messages to persist? For a message to last through a reboot, it has to be written to disk, and even a simple checkpoint to disk takes time. If you value message routing speed more than the contents of the message, don&#8217;t make your messages persistent. That being said, for our particular needs @ DigiTar, persistence is important.
When you publish your message to an exchange, there&#8217;s a flag called “Delivery Mode”. Depending on the AMQP library you&#8217;re using there will be different ways of setting it (we&#8217;ll cover the Python library later). But the long and the short of it is you want the “Delivery Mode” set to the value 2, which means “persistent”. “Delivery Mode” usually (depending on your AMQP library) defaults to a value of 1, which means “non-persistent”. So the steps for persistent messaging are:
Mark the exchange “durable”.
Mark the queue “durable”.
Set the message&#8217;s “delivery mode” to a value of 2
That&#8217;s it. Not really rocket science, but enough moving parts to make a mistake and send little Sally&#8217;s dental records into cyber-Nirvana.
There may be one thing nagging you though…what about the binding? We didn&#8217;t mark the binding “durable” when we created it. It&#8217;s alright. If you bind a durable queue to a durable exchange, RabbitMQ will automatically preserve the binding. Similarly, if you delete any exchange/queue (durable or not) any bindings that depend on it get deleted automatically.
Two things to be aware of:
RabbitMQ will not allow you to bind a non-durable exchange to a durable queue, or vice-versa. Both the exchange and the queue must be durable for the binding operation to succeed.
You cannot change the creation flags on a queue or exchange after you&#8217;ve created it. For example, if you create a queue as “non-durable”, and want to change it to “durable”, the only way to do this is to destroy the queue and re-create it. It&#8217;s a good reason to double check your declarations.
Food for snakes
A real empty area for AMQP usage is using it in Python programs. For other languages there are plenty of references:
Java &#8211;
.NET &#8211;
Ruby &#8211;
But for little old Python, you need to dig it out yourself. So other folks don&#8217;t have to wander in the wilderness like I did, here&#8217;s a little primer on using Python to do the AMQP-tasks we&#8217;ve talked about:
First, you&#8217;ll need a Python AMQP library…and there are two:
&#8211; General AMQP library
&#8211; An AMQP library that uses the
framework, thereby allowing asynchronous I/O.
Depending on your needs, py-amqplib or txAMQP may be more to your liking. Being Twisted-based, txAMQP holds the promise of building super performing AMQP consumers that use async I/O. But Twisted programming is a topic all its own…so we&#8217;re going to use py-amqplib for clarity&#8217;s sake. UPDATE: Please check the comments for example code showing use of txAMQP from Esteve Fernandez.
AMQP supports pipelining multiple MQ communication channels over one TCP connection, where each channel is a communication stream used by your program. Every AMQP program has at least one connection and one channel:
&&&from amqplib import client_0_8 as amqp
conn = amqp.Connection&#40;host=&localhost:5672 &, userid=&guest&,
password=&guest&, virtual_host=&/&, insist=False&#41;
chan = conn.channel&#40;&#41;
Each channel is assigned an integer channel number automatically by the .channel() method of the Connection() class. Alternately, you can specify the channel number yourself by calling .channel(x) , where x is the channel number you want. More often than not, its a good idea to just let the .channel() method auto-assign the channel number to avoid collisions.
Now we&#8217;ve got a connection and channel to talk over. At this point, our code is going to diverge into two applications that use that same bit we&#8217;ve created so far: a consumer and the publisher. Let&#8217;s create the consumer app by creating a queue named “po_box” and an exchange named “sorting_room”:
&&&chan.queue_declare&#40;queue=&po_box&, durable=True,
exclusive=False, auto_delete=False&#41;
chan.exchange_declare&#40;exchange=&sorting_room&, type=&direct&, durable=True,
auto_delete=False,&#41;
What did that do? First, it created a queue called “po_box” that is durable (will be re-created on reboot) and will not be automatically deleted when the last consumer detaches from it (auto_delete=False). It&#8217;s important to set auto_delete to false when making a queue (or exchange) durable, otherwise the queue itself will disappear when the last consumer detaches (regardless of the durable flag). Setting both durable and auto_delete to true, would make a queue that would be recreated only if RabbitMQ died unexpectedly with consumers still attached.
(You may have noticed there&#8217;s another flag specified called “exclusive”. If set to true, only the consumer that creates the queue will be allowed to attach to it. It&#8217;s a queue that is private to the creating consumer.)
There&#8217;s also the exchange declaration for the “sorting_room” exchange. auto_delete and durable mean the same things as they do in a queue declaration. However, .exchange_declare() introduces an argument called type that defines what type of exchange you&#8217;re making (as described earlier): fanout, direct or topic.
At this point, you&#8217;ve got a queue to receive messages and an exchange to publish them to initially…but we need a binding to link the two together:
&&&chan.queue_bind&#40;queue=&po_box&, exchange=&sorting_room&,
routing_key=&jason&&#41;
The binding is pretty straight forward. Any messages arriving at the “sorting_room” exchange with the routing key “jason” gets routed to the “po_box” queue.
Now, there&#8217;s two methods of getting messages out of the queue. The first is to call chan.basic_get() to pull the next message off the queue (if there are no messages waiting on the queue, chan.basic_get() will return a None object&#8230;thereby blowing up the print msg.body code below if not trapped) :
&&&msg = chan.basic_get&#40;&po_box&&#41;
print msg.body
chan.basic_ack&#40;msg.delivery_tag&#41;
But what if you want your application to be notified as soon as a message is available for it? To do that, instead of chan.basic_get(), you need to register a callback for new messages using chan.basic_consume():
&&&def recv_callback&#40;msg&#41;:
print 'Received: ' + msg.body
chan.basic_consume&#40;queue='po_box', no_ack=True,
callback=recv_callback, consumer_tag=&testtag&&#41;
while True:
chan.wait&#40;&#41;
chan.basic_cancel&#40;&testtag&&#41;
chan.wait() is looped infinitely, which is what causes the channel to wait for the next message notification from the queue. chan.basic_cancel() is how you unregister your message notification callback. The argument specifies the consumer_tag you specified in the original chan.basic_consume() registration (that&#8217;s how it figures out which callback to unregister). In this case chan.basic_cancel() never gets called due to the infinite loop that precedes it…but you need to know about it, so it&#8217;s in the snippet.
The one additional thing you should pay attention to in the consumer is the no_ack argument. It&#8217;s accepted on both chan.basic_get() and chan.basic_consume() and defaults to false. When you grab a message off a queue, RabbitMQ needs you to explicitly acknowledge that you have it. If you don&#8217;t, RabbitMQ will re-assign the message to another consumer on the queue after a timeout interval (or on disconnect by the consumer that initially received it
without ack&#8217;ing it). If you set the no_ack argument to true, then py-amqplib will add a &#8220;no_ack&#8221; property to your AMQP request for the next message. That will instruct the AMQP server to not expect an acknowledgement for that get/consume. However, in most cases, you probably want to send the acknowledgement yourself (e.g. you need to put the message contents in a database before you acknowledge). Acknowledgements are done by caling the chan.basic_ack() method, using the delivery_tag property of the message you&#8217;re acknowledging as the argument (see the chan.basic_get() code snippet above for an example).
That&#8217;s all she wrote for the consumer. (Download: )
But what good is a consumer, if nobody is sending it messages? So you need a publisher. The code below will publish a simple message to the “sorting_room” exchange and mark it with the routing key “jason”:
&&&msg = amqp.Message&#40;&Test message!&&#41;
msg.properties&#91;&delivery_mode&&#93; = 2
chan.basic_publish&#40;msg,exchange=&sorting_room&,routing_key=&jason&&#41;
You may notice that we set the delivery_mode element of the message&#8217;s properties to “2”. Since the queue and exchange were marked durable, this will ensure the message is sent as persistent (i.e. will survive a reboot of RabbitMQ while it is in transit to the consumer).
The only other thing we need to do (and this needs to be done on both consumer and publisher apps), is close the channel and connection:
&&&chan.close&#40;&#41;
conn.close&#40;&#41;
Pretty simple, no? (Download: )
Giving it a shot…
Now we&#8217;ve written our consumer and publisher, so let&#8217;s give it a go. (This assumes you have RabbitMQ
and running on localhost.)
Open up the first terminal, and run python ./amqp_consumer.py to get the consumer running and to create your queues, exchanges and bindings.
Then run python ./amqp_publisher.py &#8220;AMQP rocks.&#8221; in a second terminal. If everything went well, you should see your message printed by the consumer on the first terminal.
Taking it all in
I realize this has been a really fast run through AMQP/RabbitMQ and using it from Python. Hopefully, it will fill in some of the holes of how all the concepts fit together and how they get used in a real Python program. If you find any errors in my write-up, I&#8217;d very much appreciate it if you&#8217;d please let me know (). Similarly, I&#8217;d be happy to answer any questions that I can. Next up&#8230;.clustering! But I&#8217;ve got to figure it out first.
NB: Special thanks to Barry Pederson and Gordon Sims for correcting my understanding of no_ack&#8217;s operation and for catching syntactically incorrect Python code I missed.
NB: My knowledge on the subject was distilled from these sources, which are excellent further reading:
Write a comment

我要回帖

更多关于 how do you know 的文章

 

随机推荐