知识准备
RabbitMQ
RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统。
MQ
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。
消息队列使用发布订-阅模式工作。消息发送者是消息源,在对消息进行处理后将消息发送至分布式消息队列,消息接受者从分布式消息队列获取该消息后继续进行处理。可以看到,消息发送者和消息接受者之间没有直接耦合,消息发送者将消息发送至分布式消息队列即结束对消息的处理,而消息接受者只需要从分布式消息队列获取消息后进行处理,不需要知道该消息从何而来。
通过消息队列通信,让A,B两个服务指间保持低耦合,实现业务的灵活拓展。
pika
pika是RabbitMQ团队编写的官方Python AMQP库。
安装启动
$ brew install rabbitmq$ usr/local/sbin/rabbitmq-server
安装pika
pip install pika
操作实例
Hello World
sender
# coding: utf-8import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello') channel.basic_publish(exchange='', routing_key='hello', body='Hello, World!')print 'send msg: Hello World!'connection.close()
receiver
# coding: utf-8import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello')def callback(ch, method, properties, body): print 'receive msg: %s' % body channel.basic_consume(callback, queue='hello', no_ack=False)print 'waiting for msg...'channel.start_consuming()
运行结果:
# sender.py 运行2次send msg: Hello World!# receiverwaiting for msg... receive msg: Hello, World! receive msg: Hello, World!
消费者处理消息后,并没有退出,仍然可以处理后续的消息。
Atas ialah kandungan terperinci Python中RabbitMQ的操作图文代码详解. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Pythonlistscanstoreanydatatype, arraymoduleArraysstoreonetype, andnumpyarraysarefornumumericalcomputations.1) listsareversatileButlessMememory-efficient.2) arraymoduleArduleArrayRaysarememory-efficientforhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogen

KetikayyoUttemptToStoreAveFheWrongatatypeinapythonArray, anda akan menjadicounteratypeerror

Pythonlistsarepartofthestandardlibrary, sementara

Thescriptisrunningwiththewrongpythonversionduetoincorrectdefault interpretsettings

PythonArraysSupportVariousoperations: 1) SlicingExtractsSubsets, 2) Menambah/ExtendingAddSelements, 3) InsertingPlaceSelementSatSatSatSpecifics, 4) RemovingDeleteselements, 5) Sorting/ReversingChangesOrder,

NumpyarraysareessentialforapplicationRequiringeficientnumericalcomputationsanddatamanipulation.theyarecrucialindaSascience, machinelearning, fizik, kejuruteraan, danfinanceduetotheirabilitytOHandlelarge-Scaledataefisien.Forexample, infinancialanal

UseanArray.arrayoveralistinpythonwhendealingwithhomogeneousdata, criticalcode prestasi, orinterfacingwithccode.1) homogeneousdata: arrayssavemememorywithtypedelements.2)

Tidak, notalllistoperationsaresuportedByArrays, andviceversa.1) arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing, whyimpactsperformance.2) listsdonotguaranteeconstantTimeComplexityFordirectacesscesscesscesscesscesscesscesscesscesessd.


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

Video Face Swap
Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Alat panas

Pelayar Peperiksaan Selamat
Pelayar Peperiksaan Selamat ialah persekitaran pelayar selamat untuk mengambil peperiksaan dalam talian dengan selamat. Perisian ini menukar mana-mana komputer menjadi stesen kerja yang selamat. Ia mengawal akses kepada mana-mana utiliti dan menghalang pelajar daripada menggunakan sumber yang tidak dibenarkan.

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

Penyesuai Pelayan SAP NetWeaver untuk Eclipse
Integrasikan Eclipse dengan pelayan aplikasi SAP NetWeaver.

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

EditPlus versi Cina retak
Saiz kecil, penyerlahan sintaks, tidak menyokong fungsi gesaan kod
