【飛凌嵌入式 OK3399-C 開(kāi)發(fā)板試用體驗(yàn)】(安裝RabbitMQ消息隊(duì)列服務(wù)】
作者:fcb5511
提供兩種消息隊(duì)列服務(wù)安裝方式:
2、erl # 查看relang語(yǔ)言版本,成功執(zhí)行則說(shuō)明relang安裝成功
在rk3399瀏覽器中輸入localhost:15672,登陸用戶名和密碼分別為”guest”、”guest”。
局域網(wǎng)內(nèi)計(jì)算機(jī)瀏覽器輸入192.168.1.109:15672,用戶名和密碼分別為”admin”、”admin”
import pika import threading import time import signal import os class Producer(object): def __init__(self, host='127.0.0.1', port=5672, user='admin', passwd='admin', exchange='test_exchange', routing_key='test_key', exchange_type= 'fanout', exhcange_durable=False, exchange_autodelete=True ): self.host=host self.port=port self.user=user self.passwd=passwd self.exchange=exchange self.routing_key=routing_key self.exchange_type=exchange_type self.exhcange_durable=exhcange_durable self.exchange_autodelete=exchange_autodelete self.connection=None self.channel=None def CreateConnection(self): try: self.credentials=pika.PlainCredentials(self.user, self.passwd) self.connection = pika.BlockingConnection(pika.ConnectionParameters(host = self.host, port = self.port, virtual_host = '/', credentials=self.credentials)) self.channel = self.connection.channel() self.channel.exchange_declare(exchange_type=self.exchange_type, exchange = self.exchange, durable = self.exhcange_durable, auto_delete=self.exchange_autodelete) except Exception as e: print("occurring an exception when the producer executing the function 'CreateConnection()':", e) def PublisMessage(self, Message): try: self.channel.basic_publish(exchange=self.exchange, routing_key=self.routing_key, properties=pika.BasicProperties(delivery_mode = 2), body=Message) except Exception as e: print("An exception occurred when publishing message:", e)
amqconsumer.py程序:
import pika import time class Consumer(object): def __init__(self, host='127.0.0.1', port=5672, user='admin', passwd='admin', queue='test_queue', exchange='test_exchange', routing_key='test_key', queue_exclusive=False, queue_durable=False, queue_autodelete=True, exchange_type= 'fanout', exhcange_durable=False, exchange_autodelete=True ): self.host=host self.port=port self.user=user self.passwd=passwd self.queue=queue self.exchange=exchange self.routing_key=routing_key self.queue_exclusive=queue_exclusive self.queue_durable=queue_durable self.queue_autodelete=queue_autodelete self.exchange_type=exchange_type self.exhcange_durable=exhcange_durable self.exchange_autodelete=exchange_autodelete self.connection=None self.channel=None def CreateConnection(self): try: self.credentials=pika.PlainCredentials(self.user, self.passwd) self.connection = pika.BlockingConnection(pika.ConnectionParameters(host = self.host, port = self.port, virtual_host = '/', credentials=self.credentials)) self.channel = self.connection.channel() self.channel.queue_declare(queue=self.queue, durable=self.queue_durable, exclusive=self.queue_exclusive, auto_delete=self.queue_autodelete) self.channel.exchange_declare(exchange_type=self.exchange_type, exchange = self.exchange, durable = self.exhcange_durable, auto_delete=self.exchange_autodelete) self.channel.queue_bind(queue = self.queue, exchange = self.exchange, routing_key = self.routing_key) self.channel.basic_consume(on_message_callback = self.on_response, auto_ack=True, queue=self.queue) except Exception as e: print("occurring an exception when the consumer RecvData:", e) def on_response(self, ch, method, props, body): #print(" [%s] Received %r" % (time.time(), body)) print(time.strftime('%H:%M:%S',time.localtime(time.time()))+': Get Message from '+self.host + ':'+body.decode()) def ProcessConsumeEventBlock(self): try: self.channel.start_consuming() except Exception as e: print('An exception occurred when executing consuming, the exception is:',e) def ProcessConsumeEventNoneBlock(self): try: self.connection.process_data_events() except Exception as e: print('An exception occurred when executing consuming, the exception is:',e)
main.py程序:
import pika import time import threading from amqconsumer import Consumer from amqproducer import Producer class ManageMent: def __init__(self): self.producer = Producer(host='localhost',user='guest',passwd='guest') self.consumer = Consumer(host='localhost',user='guest',passwd='guest') def CreateSever(self): self.consumer.CreateConnection() self.producer.CreateConnection() def ProducerRun(self): while True: self.producer.PublisMessage('this message is used for testing RabbitMQ') time.sleep(0.3) def ConsumerRun(self): self.consumer.ProcessConsumeEventBlock() def Run1(self): while True: self.producer.PublisMessage('this message is used for test RabbitMQ') self.consumer.ProcessConsumeEventNoneBlock() time.sleep(1) def Run(self): self.Consumer_thread=threading.Thread(target=self.ConsumerRun) self.Producer_thread=threading.Thread(target=self.ProducerRun) self.Consumer_thread.start() self.Producer_thread.start() if __name__ == '__main__': manage=ManageMent() manage.CreateSever() manage.Run()
最終運(yùn)行效果如圖
此貼為基礎(chǔ)功能,下次將mq數(shù)據(jù)與qt界面結(jié)合,實(shí)現(xiàn)動(dòng)態(tài)的界面。
相關(guān)產(chǎn)品 >
-
FET3399-C核心板
飛凌RK3399安卓高性能核心板采用 采用六核Rockchip RK3399芯片,雙Cortex-A72大核+四Cortex-A53小核結(jié)構(gòu),對(duì)整數(shù)、浮點(diǎn)、內(nèi)存等作了大幅優(yōu)化,在整體性能、功耗及核心面積三個(gè)方面提升。以下將對(duì)瑞芯微芯片RK3399參數(shù),RK3399核心板方案及其性能做具體介紹。如您對(duì)飛凌RK3399系列核心板有興趣,歡迎咨詢了解。
了解詳情 -
OK3399-C開(kāi)發(fā)板
飛凌嵌入式RK3399安卓開(kāi)發(fā)板主芯片采用高性能六核CPU Rockchip RK3399,GPU采用Mail-T860四核 GPU,RK3399作為目RK產(chǎn)品線中低功耗、高性能的代表,可滿足人臉識(shí)別設(shè)備、機(jī)器人、無(wú)人機(jī)、IoT物聯(lián)網(wǎng)領(lǐng)域應(yīng)用。飛凌RK3399開(kāi)發(fā)板在整體性能、功耗及核心面積做了大幅度優(yōu)化,更加滿足工業(yè)設(shè)計(jì)需求。飛凌RK3399開(kāi)發(fā)板為進(jìn)一步減少用戶二次開(kāi)發(fā)難度,開(kāi)放了底板原理圖,并提供了RK3399用戶手冊(cè)、芯片手冊(cè),加上優(yōu)質(zhì)的技術(shù)服務(wù),讓您的方案從構(gòu)思到上市時(shí)間縮短。