Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import protofile.bus_arch.message.python.message_pb2 as bm
  2.  
  3. from rediscluster import StrictRedisCluster
  4. import redis
  5. import zlib
  6. import uuid
  7. import struct
  8.  
  9. def connectStandalone(host, port):
  10.     return redis.Redis(host=host, port=port)
  11.  
  12. def connectCluster(host, port):
  13.     # Requires at least one node for cluster discovery. Multiple nodes is recommended.
  14.     startup_nodes = [{"host": host, "port": port}]
  15.  
  16.     # Note: See note on Python 3 for decode_responses behaviour
  17.     return StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
  18.  
  19. def craftData(function, msg):
  20.     data = bm.BusMessage()
  21.     data.version = "0.3.0"
  22.     data.replyChannel = "qa-k1"
  23.     data.function = function
  24.     data.data = str.encode(msg)
  25.     data.crc = struct.pack("<I", zlib.crc32(msg.encode('utf-8'))%(1<<32))
  26.  
  27.     return data.SerializeToString()
  28.  
  29. # rc = connectStandalone('localhost', 6379)
  30. rc = connectCluster('10.10.20.191', 30039)
  31.  
  32. rc.lpush("{bus:bms-channel}", craftData('create-building', '{"name": "orgNmae"}'))
  33.  
  34. reply = rc.brpop("qa-k1")
  35. message = bm.BusMessage()
  36. message.ParseFromString(reply[1])
  37. print (message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement