admin 管理员组文章数量: 1184232
2024年1月16日发(作者:plight)
2 #-*- coding:utf-8 -*-34 importpika5 importsys67 connection = ngConnection(tionParameters(host='localhost'))8 channel =l()910 ge_declare(exchange='direct_logs',type='direct')1112 result = _declare(exclusive=True)13 queue_name =1415 severities = [1:]16 if notseverities:17 ("Usage: %s [info] [warning] [error]n" %[0])(1)1920 for severity inseverities:21 _bind(exchange='direct_logs',22 queue=queue_name,23routing_key=severity)2425 print('[*] Waiting for logs. To exit press CTRL+C')262728 defcallback(ch, method, properties, body):29 print("[x] %r:%r" %(g_key, body))303132 _consume(callback,33 queue=queue_name,34 no_ack=True)3536 _consuming()1.9 更细致的消息过滤importpikaimportsysconnection=ngConnection(tionParameters(host='localhost'))channel=l()ge_declare(exchange='topic_logs',type='topic')routing_key= [1] if len() > 1 else ''message= ' '.join([2:]) or 'HelloWorld!'_publish(exchange='topic_logs',routing_key=routing_key,body=message)print("[x] Sent %r:%r" %(routing_key, message))()import pikaimportsysconnection=ngConnection(tionParameters(host='localhost'))
channel=l()ge_declare(exchange='topic_logs',type='topic')result= _declare(exclusive=True)queue_name=inding_keys= [1:]if notbinding_keys:("Usage: %s [binding_key]...n" %[0])(1)for binding_key inbinding_keys:_bind(exchange='topic_logs',queue=queue_name,routing_key=binding_key)print('[*] Waiting for logs. To exit press CTRL+C')defcallback(ch, method, properties, body):print("[x] %r:%r" %(g_key, body))_consume(callback,queue=queue_name,no_ack=True)_consuming()1.10 rpcRPC server1 importpika2 importtime3 connection =ngConnection(tionParameters(4 host='localhost'))56 channel =l()78 _declare(queue='rpc_queue')910 deffib(n):11 if n ==0:12 return013 elif n == 1:14 return 115 else:16 return fib(n-1) + fib(n-2)1718 defon_request(ch, method, props, body):19 n =int(body)2021 print("[.] fib(%s)" %n)22 response =fib(n)2324 _publish(exchange='',25 routing_key=_to,26 properties=roperties(correlation_id =ation_id),28 body=str(response))29 _ack(delivery_tag =ry_tag)3031 _qos(prefetch_count=1)32 _consume(on_request, queue='rpc_queue')3334 print("[x] Awaiting RPC requests")35 _consuming()RPC client
set(name, value, ex=None, px=None, nx=False, xx=False)在Redis中设置值,默认,不存在则创建,存在则修改
版权声明:本文标题:rabbitmq存入mysql_消息队列RabbitMQ、缓存数据库Redis 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1705414733a483808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论