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