1 # ==================================================================================
2 # Copyright (c) 2019 Nokia
3 # Copyright (c) 2018-2019 AT&T Intellectual Property.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
18 # Mnemonic: rcv_all.py
19 # Abstract: This example shows how to receive all queued messages into
20 # a bunch (an array of summaries). RMR is initialised in multi-
21 # threaded call mode so that it will queue messages on a 2K ring
22 # and prevent the remote application(s) from blocking if we don't
23 # do timely receives. Then we read 'bursts' of messages sleeping
24 # between reads to allow some message to pile up.
26 # Because this programme does not send messages, there is no reason
27 # to wait for RMR to initialise a route table (no call to rmr_ready
31 from rmr import helpers
37 # Ensure things terminate nicely
39 def signal_handler(sig, frame):
40 print('SIGINT received! Cleaning up rmr')
45 listen_port = "4560".encode('utf-8') # port RMR will listen on (RMR needs string, not value)
46 mrc = rmr.rmr_init( listen_port, rmr.RMR_MAX_RCV_BYTES, rmr.RMRFL_MTCALL ) # put into multi-threaded call mode
48 signal.signal(signal.SIGINT, signal_handler) # cleanup on ctl-c
52 # three calling options:
53 #mbunch = helpers.rmr_rcvall_msgs( mrc, [2, 4, 6] ) # get types 2, 4 and 6 only
54 #mbunch = helpers.rmr_rcvall_msgs( mrc, [2] ) # get types 2 only
55 mbunch = helpers.rmr_rcvall_msgs( mrc ) # get all message types
57 if mbunch == None or len( mbunch ) < 1:
58 print( "no messages" )
60 print( "got %d messages" % len( mbunch ) )
62 print( "type=%d payload=%s" % (mb[rmr.RMR_MS_MSG_TYPE], mb[rmr.RMR_MS_PAYLOAD] ) )
64 time.sleep( 1 ) # sleep to allow some to accumulate