def __init__(self, init_func_override=None, rcv_func_override=None): self.keep_going = True self.rcv_func = None self.last_ran = time.time() self.instance_send_queue = queue.Queue( ) # thread safe queue https://docs.python.org/3/library/queue.html # intialize rmr context if init_func_override: self.mrc = init_func_override() else: mdc_logger.debug("Waiting for rmr to initialize..") # rmr.RMRFL_MTCALL puts RMR into a multithreaded mode, where a receiving thread populates an # internal ring of messages, and receive calls read from that # currently the size is 2048 messages, so this is fine for the foreseeable future self.mrc = rmr.rmr_init(b"4562", rmr.RMR_MAX_RCV_BYTES, rmr.RMRFL_MTCALL) while rmr.rmr_ready(self.mrc) == 0: time.sleep(0.5) # set the receive function self.rcv_func = (rcv_func_override if rcv_func_override else lambda: helpers.rmr_rcvall_msgs_raw( self.mrc, [A1_POLICY_RESPONSE, A1_POLICY_QUERY])) # start the work loop self.thread = Thread(target=self.loop) self.thread.start()
def setup_module(): """ test_rmr module setup """ global MRC_SEND MRC_SEND = rmr.rmr_init(b"4562", rmr.RMR_MAX_RCV_BYTES, 0x00) while rmr.rmr_ready(MRC_SEND) == 0: time.sleep(1) global MRC_RCV MRC_RCV = rmr.rmr_init(b"4563", rmr.RMR_MAX_RCV_BYTES, 0x00) while rmr.rmr_ready(MRC_RCV) == 0: time.sleep(1) global MRC_BUF_RCV MRC_BUF_RCV = rmr.rmr_init(b"4564", rmr.RMR_MAX_RCV_BYTES, 0x02) while rmr.rmr_ready(MRC_BUF_RCV) == 0: time.sleep(1)
# limitations under the License. # ================================================================================== """ Test receiver """ import time import json from rmr import rmr PORT = "4564" mrc = rmr.rmr_init(PORT.encode("utf-8"), rmr.RMR_MAX_RCV_BYTES, rmr.RMRFL_MTCALL) test_type = 1006001 while rmr.rmr_ready(mrc) == 0: time.sleep(1) print("not yet ready") print("listening ON {}".format(PORT)) # loop while True: # do query pay = {"policy_type_id": test_type} sbuf_send = rmr.rmr_alloc_msg(mrc, 4096, payload=json.dumps(pay).encode("utf-8"), gen_transaction_id=True, mtype=20012) sbuf_send = rmr.rmr_send_msg(mrc, sbuf_send) post_send_summary = rmr.message_summary(sbuf_send) if not (post_send_summary["message state"] == 0 and post_send_summary["message status"] == "RMR_OK"):