summaryrefslogtreecommitdiff
path: root/python-pyrsmq.spec
blob: 0b5dcb6e0500b44ac692897994c7257d6b01ae0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
%global _empty_manifest_terminate_build 0
Name:		python-PyRSMQ
Version:	0.4.5
Release:	1
Summary:	Python Implementation of Redis SMQ
License:	Apache 2.0
URL:		https://mlasevich.github.io/PyRSMQ/
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/fe/24/136817132d5178d4c81fc6b9dfdacb1d1e71efdc902de9bdc1177036fa1c/PyRSMQ-0.4.5.tar.gz
BuildArch:	noarch

Requires:	python3-redis

%description
![RSMQ: Redis Simple Message Queue for Node.js](https://img.webmart.de/rsmq_wide.png)

[![Build Status](https://travis-ci.org/mlasevich/PyRSMQ.svg?branch=master)](https://travis-ci.org/mlasevich/PyRSMQ)
[![Coverage Status](https://coveralls.io/repos/github/mlasevich/PyRSMQ/badge.svg?branch=master)](https://coveralls.io/github/mlasevich/PyRSMQ?branch=master)
[![PyPI version](https://badge.fury.io/py/PyRSMQ.svg)](https://badge.fury.io/py/PyRSMQ)

# Redis Simple Message Queue

A lightweight message queue for Python that requires no dedicated queue server. Just a Redis server.

This is a Python implementation of [https://github.com/smrchy/rsmq](https://github.com/smrchy/rsmq))


## PyRSMQ Release Notes
* 0.4.5
  * Re-release to push to PyPi

* 0.4.4
  * Allow extending the transaction for deleteMessage to perform other actions in same transaction ([#9](https://github.com/mlasevich/PyRSMQ/issues/9)) (@yehonatanz)
  * Use redis timestamp in milliseconds instead of local in seconds ([#11](https://github.com/mlasevich/PyRSMQ/pull/11)) (@yehonatanz)
  * Convert queue attributes to numbers when elligible ([#12](https://github.com/mlasevich/PyRSMQ/pull/12)) (@yehonatanz)


* 0.4.3 
  * Don't encode sent message if it is of type bytes ([#6](https://github.com/mlasevich/PyRSMQ/issues/6))  (@yehonatanz)
  * Allow delay and vt to be float (round only after converting to millis) ([#7](https://github.com/mlasevich/PyRSMQ/issues/7)) (@yehonatanz)
  * Convert ts from str/bytes to int in receive/pop message ([#8](https://github.com/mlasevich/PyRSMQ/issues/8)) (@yehonatanz)

* 0.4.2
  * Fix typo in `setClient` method [#3](https://github.com/mlasevich/PyRSMQ/issues/3)
      * Note this is a breaking change if you use this method, (which seems like nobody does)

* 0.4.1
  * Add auto-decode option for messages from JSON (when possible) in Consumer (on by default)

* 0.4.0
  * Ability to import `RedisSMQ` from package rather than from the module (i.e. you can now use `from rsmq import RedisSMQ` instead of `from rsmq.rsmq import RedisSMQ`)
  * Add quiet option to most commands to allow to hide errors if exceptions are disabled
  * Additional unit tests
  * Auto-encoding of non-string messages to JSON for sendMessage
  * Add `RedisSMQConsumer` and `RedisSMQConsumerThread` for easier creation of queue consumers
  * Add examples for simple producers/consumers

* 0.3.1
  * Fix message id generation match RSMQ algorithm

* 0.3.0
  * Make message id generation match RSMQ algorithm
  * Allow any character in queue name other than `:`

* 0.2.1
  * Allow uppercase characters in queue names

* 0.2.0 - Adding Python 2 support
  * Some Python 2 support
  * Some Unit tests
  * Change `.exec()` to `.execute()` for P2 compatibility

* 0.1.0 - initial version
    * Initial port
    * Missing "Realtime" mode
    * Missing unit tests

## Quick Intro to RSMQ

RSMQ is trying to emulate Amazon's SQS-like functionality, where there is a named queue (name
consists of "namespace" and "qname") that is backed by Redis. Queue must be created before used.
Once created, _Producers_ will place messages in queue and _Consumers_ will retrieve them.
Messages have a property of "visibility" - where any "visible" message may be consumed, but
"invisbile" messages stay in the queue until they become visible or deleted.

Once queue exists, a _Producer_ can push messages into it. When pushing to queue, message gets a
unique ID that is used to track the message. The ID can be used to delete message by _Producer_ or
_Consumer_ or to control its "visibility"

During insertion, a message may have a `delay` associated with it. "Delay" will mark message
"invisible" for specified delay duration, and thus prevent it from being consumed. Delay may be
specified at time of message creation or, if not specified, default value set in queue attributes
is used.

_Consumer_ will retrieve next message in queue via either `receiveMessage()` or `popMessage()`
command. If we do not care about reliability of the message beyond delivery, a good and simple way
to retrieve it is via `popMessage()`.  When using `popMessage()` the message is automatically
deleted at the same time it is received.

However in many cases we want to ensure that the message is not only received, but is also
processed before being deleted. For this, `receiveMessage()` is best. When using `receiveMessage()`,
the message is kept in the queue, but is marked "invisible" for some amount of time. The amount of
time is specified by queue attribute `vt`(visibility timeout), which may also be overridden by
specifying a custom `vt` value in `receiveMessage()` call. When using  `receiveMessage()`,
_Consumer_' is responsible for deleting the message before `vt` timeout occurs, otherwise the
message may be picked up by another _Consumer_. _Consumer_ can also extend the timeout if it needs
more time, or clear the timeout if processing failed.

A "Realtime" mode can be specified when using the RSMQ queue. "Realtime" mode adds a Redis PUBSUB
based notification that would allow _Consumers_ to be notified whenever a new message is added to
the queue. This can remove the need for _Consumer_ to constantly poll the queue when it is empty
(*NOTE:* as of this writing, "Realtime" is not yet implemented in python version)

## Python Implementation Notes

*NOTE* This project is written for Python 3.x. While some attempts to get Python2 support were made
I am not sure how stable it would be under Python 2

This version is heavily based on Java version (https://github.com/igr/jrsmq), which in turn is
based on the original Node.JS version.

### API
To start with, best effort is made to maintain same method/parameter/usablity named of both version
(which, admittedly, resulted in a not very pythonic API)

Although much of the original API is still present, some alternatives are added to make life a bit
easier.

For example, while you can set any available parameter to command using the "setter" method, you can
also simply specify the parameters when creating the command. So these two commands do same thing:

    rqsm.createQueue().qname("my-queue").vt(20).execute()

    rqsm.createQueue(qname="my-queue", vt=20).execute()

In addition, when creating a main controller, any non-controller parameters specified will become
defaults for all commands created via this controller - so, for example, you if you plan to work
with only one queue using this controller, you can specify the qname parameter during creation of
the controller and not need to specify it in every command.

### A "Consumer" Service Utility

In addition to all the APIs in the original RSMQ project, a simple to use consumer implementation
is included in this project as `RedisSMQConsumer` and `RedisSMQConsumerThread` classes.

#### RedisSMQConsumer
The `RedisSMQConsumer` instance wraps an RSMQ Controller and is configured with a processor method
which is called every time a new message is received. The processor method returns true or false 
to indicate if message was successfully received and the message is deleted or returned to the
queue based on that. The consumer auto-extends the visibility timeout as long as the processor is
running, reducing the concern that item will become visible again if processing takes too long and
visibility timeout elapses.

NOTE: Since currently the `realtime` functionality is not implemented, Consumer implementation is
currently using polling to check for queue items. 

Example usage:

```
from rsmq.consumer import RedisSMQConsumer

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumer('my-queue', processor, host='127.0.0.1')

# run consumer
consumer.run()
```

For a more complete example, see examples directory.


#### RedisSMQConsumerThread

`RedisSMQConsumerThread` is simply a version of `RedisSMQConsumer` that extends Thread class.

Once created you can start it like any other thread, or stop it using `stop(wait)` method, where
wait specifies maximum time to wait for the thread to stop before returning (the thread would still
be trying to stop if the `wait` time expires)

Note that the thread is by default set to be a `daemon` thread, so on exit of your main thread it
will be stopped. If you wish to disable daemon flag, just disable it before starting the thread as
with any other thread

Example usage:

```
from rsmq.consumer import RedisSMQConsumerThread

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumerThread('my-queue', processor, host='127.0.0.1')

# start consumer
consumer.start()

# do what else you need to, then stop the consumer
# (waiting for 10 seconds for it to stop):
consumer.stop(10)

```

For a more complete example, see examples directory.

### General Usage Approach

As copied from other versions, the general approach is to create a controller object and use that
object to create, configure and then execute commands

### Error Handling

Commands follow the pattern of other versions and throw exceptions on error.

Exceptions are all extending `RedisSMQException()` and include:

* `InvalidParameterValue()` - Invalid Parameter specified
* `QueueAlreadyExists()` - attempt to create queue which already exists
* `QueueDoesNotExist()` - attempt to use/delete queue that does not exist
* `NoMessageInQueue()` - attempt to retrieve message from queue that has no visible messaged

However, if you do not wish to use exceptions, you can turn them off on per-command or
per-controller basis by using `.exceptions(False)` on the relevant object. For example, the
following will create Queue only if it does not exist without throwing an exception:

    rsmq.createQueue().exceptions(False).execute()


## Usage

### Example Usage

In this example we will create a new queue named "my-queue", deleting previous version, if one
exists, and then send a message with a 2 second delay. We will then demonstrate both the lack of
message before delay expires and getting the message after timeout


    from pprint import pprint
    import time

    from rsmq import RedisSMQ


    # Create controller.
    # In this case we are specifying the host and default queue name
    queue = RedisSMQ(host="127.0.0.1", qname="myqueue")


    # Delete Queue if it already exists, ignoring exceptions
    queue.deleteQueue().exceptions(False).execute()

    # Create Queue with default visibility timeout of 20 and delay of 0
    # demonstrating here both ways of setting parameters
    queue.createQueue(delay=0).vt(20).execute()

    # Send a message with a 2 second delay
    message_id = queue.sendMessage(delay=2).message("Hello World").execute()

    pprint({'queue_status': queue.getQueueAttributes().execute()})

    # Try to get a message - this will not succeed, as our message has a delay and no other
    # messages are in the queue
    msg = queue.receiveMessage().exceptions(False).execute()

    # Message should be False as we got no message
    pprint({"Message": msg})

    print("Waiting for our message to become visible")
    # Wait for our message to become visible
    time.sleep(2)

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # Get our message
    msg = queue.receiveMessage().execute()

    # Message should now be there
    pprint({"Message": msg})

    # Delete Message
    queue.deleteMessage(id=msg['id'])

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # delete our queue
    queue.deleteQueue().execute()

    # No action
    queue.quit()



### RedisSMQ Controller API Usage

Usage: `rsmq.rqsm.RedisSMQ([options])`

* Options (all options are provided as keyword options):
    * Redis Connection arguments:
        * `client` - provide an existing, configured redis client
        or
        * `host` - redis hostname (Default: `127.0.0.1`)
        * `port` - redis port (Default: `6379`)
        * `options` - additional redis client options. Defaults:
            * `encoding`: `utf-8`
            * `decode_responses`: `True`
    * Controller Options
        * `ns` - namespace - all redis keys are prepended with `<ns>:`. Default: `rsmq`
        * `realtime` - if set to True, enables realtime option. Default: `False`
        * `exceptions` - if set to True, throw exceptions for all commands. Default: `True`
    * Default Command Options. Anything else is passed to each command as defaults. Examples:
        * `qname` - default Queue Name

#### Controller Methods

* `exceptions(True/False)` - enable/disable exceptions
* `setClient(client)` - specify new redis client object
* `ns(namespace)` - set new namespace
* `quit()` - disconnect from redis. This is mainly for compatibility with other versions. Does not do much

#### Controller Commands

* `createQueue()` - Create new queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was created

* `deleteQueue()` - Delete Existing queue
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was deleted

* `setQueueAttributes()` - Update queue attributes. If value is not specified, it is not updated.
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * output of `getQueueAttributes()` call

* `getQueueAttributes()` - Get Queue Attributes and statistics
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** a dictionary with following fields:
        * `vt` -  default visibility timeout
        * `delay` - default insertion delay
        * `maxsize` -  max size of the message
        * `totalrecv` - number of messages consumed. Note, this is incremented each time message is retrieved, so if it was not deleted and made visible again, it will show up here multiple times.
        * `totalsent` - number of messages sent to queue.
        * `created` -  unix timestamp (seconds since epoch) of when the queue was created
        * `modified` -  unix timestamp (seconds since epoch) of when the queue was last updated
        * `msgs` -  Total number of messages currently in the queue
        * `hiddenmsgs` - Number of messages in queue that are not visible

* `listQueues()` - List all queues in this namespace
    * **Parameters:**
    * **Returns**:
        * All queue names in this namespace as a `set()`

* `changeMessageVisibility()` - Change Message Visibility
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * ???
    * **Returns**:
        * ???

* `sendMessage()` - Send message into queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `message` - (Required) message id
        * `delay` - Optional override of the `delay` for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * `encode` if set to `True`, force encode message as JSON string. If False, try to auto-detect if message needs to be encoded
    * **Returns**:
        * message id of the sent message

* `receiveMessage()` - Receive Message from queue and mark it invisible
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - Optional override for visibility timeout for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `popMessage()` -  Receive Message from queue and delete it from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `deleteMessage()` -  Delete Message from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if message was deleted




%package -n python3-PyRSMQ
Summary:	Python Implementation of Redis SMQ
Provides:	python-PyRSMQ
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-PyRSMQ
![RSMQ: Redis Simple Message Queue for Node.js](https://img.webmart.de/rsmq_wide.png)

[![Build Status](https://travis-ci.org/mlasevich/PyRSMQ.svg?branch=master)](https://travis-ci.org/mlasevich/PyRSMQ)
[![Coverage Status](https://coveralls.io/repos/github/mlasevich/PyRSMQ/badge.svg?branch=master)](https://coveralls.io/github/mlasevich/PyRSMQ?branch=master)
[![PyPI version](https://badge.fury.io/py/PyRSMQ.svg)](https://badge.fury.io/py/PyRSMQ)

# Redis Simple Message Queue

A lightweight message queue for Python that requires no dedicated queue server. Just a Redis server.

This is a Python implementation of [https://github.com/smrchy/rsmq](https://github.com/smrchy/rsmq))


## PyRSMQ Release Notes
* 0.4.5
  * Re-release to push to PyPi

* 0.4.4
  * Allow extending the transaction for deleteMessage to perform other actions in same transaction ([#9](https://github.com/mlasevich/PyRSMQ/issues/9)) (@yehonatanz)
  * Use redis timestamp in milliseconds instead of local in seconds ([#11](https://github.com/mlasevich/PyRSMQ/pull/11)) (@yehonatanz)
  * Convert queue attributes to numbers when elligible ([#12](https://github.com/mlasevich/PyRSMQ/pull/12)) (@yehonatanz)


* 0.4.3 
  * Don't encode sent message if it is of type bytes ([#6](https://github.com/mlasevich/PyRSMQ/issues/6))  (@yehonatanz)
  * Allow delay and vt to be float (round only after converting to millis) ([#7](https://github.com/mlasevich/PyRSMQ/issues/7)) (@yehonatanz)
  * Convert ts from str/bytes to int in receive/pop message ([#8](https://github.com/mlasevich/PyRSMQ/issues/8)) (@yehonatanz)

* 0.4.2
  * Fix typo in `setClient` method [#3](https://github.com/mlasevich/PyRSMQ/issues/3)
      * Note this is a breaking change if you use this method, (which seems like nobody does)

* 0.4.1
  * Add auto-decode option for messages from JSON (when possible) in Consumer (on by default)

* 0.4.0
  * Ability to import `RedisSMQ` from package rather than from the module (i.e. you can now use `from rsmq import RedisSMQ` instead of `from rsmq.rsmq import RedisSMQ`)
  * Add quiet option to most commands to allow to hide errors if exceptions are disabled
  * Additional unit tests
  * Auto-encoding of non-string messages to JSON for sendMessage
  * Add `RedisSMQConsumer` and `RedisSMQConsumerThread` for easier creation of queue consumers
  * Add examples for simple producers/consumers

* 0.3.1
  * Fix message id generation match RSMQ algorithm

* 0.3.0
  * Make message id generation match RSMQ algorithm
  * Allow any character in queue name other than `:`

* 0.2.1
  * Allow uppercase characters in queue names

* 0.2.0 - Adding Python 2 support
  * Some Python 2 support
  * Some Unit tests
  * Change `.exec()` to `.execute()` for P2 compatibility

* 0.1.0 - initial version
    * Initial port
    * Missing "Realtime" mode
    * Missing unit tests

## Quick Intro to RSMQ

RSMQ is trying to emulate Amazon's SQS-like functionality, where there is a named queue (name
consists of "namespace" and "qname") that is backed by Redis. Queue must be created before used.
Once created, _Producers_ will place messages in queue and _Consumers_ will retrieve them.
Messages have a property of "visibility" - where any "visible" message may be consumed, but
"invisbile" messages stay in the queue until they become visible or deleted.

Once queue exists, a _Producer_ can push messages into it. When pushing to queue, message gets a
unique ID that is used to track the message. The ID can be used to delete message by _Producer_ or
_Consumer_ or to control its "visibility"

During insertion, a message may have a `delay` associated with it. "Delay" will mark message
"invisible" for specified delay duration, and thus prevent it from being consumed. Delay may be
specified at time of message creation or, if not specified, default value set in queue attributes
is used.

_Consumer_ will retrieve next message in queue via either `receiveMessage()` or `popMessage()`
command. If we do not care about reliability of the message beyond delivery, a good and simple way
to retrieve it is via `popMessage()`.  When using `popMessage()` the message is automatically
deleted at the same time it is received.

However in many cases we want to ensure that the message is not only received, but is also
processed before being deleted. For this, `receiveMessage()` is best. When using `receiveMessage()`,
the message is kept in the queue, but is marked "invisible" for some amount of time. The amount of
time is specified by queue attribute `vt`(visibility timeout), which may also be overridden by
specifying a custom `vt` value in `receiveMessage()` call. When using  `receiveMessage()`,
_Consumer_' is responsible for deleting the message before `vt` timeout occurs, otherwise the
message may be picked up by another _Consumer_. _Consumer_ can also extend the timeout if it needs
more time, or clear the timeout if processing failed.

A "Realtime" mode can be specified when using the RSMQ queue. "Realtime" mode adds a Redis PUBSUB
based notification that would allow _Consumers_ to be notified whenever a new message is added to
the queue. This can remove the need for _Consumer_ to constantly poll the queue when it is empty
(*NOTE:* as of this writing, "Realtime" is not yet implemented in python version)

## Python Implementation Notes

*NOTE* This project is written for Python 3.x. While some attempts to get Python2 support were made
I am not sure how stable it would be under Python 2

This version is heavily based on Java version (https://github.com/igr/jrsmq), which in turn is
based on the original Node.JS version.

### API
To start with, best effort is made to maintain same method/parameter/usablity named of both version
(which, admittedly, resulted in a not very pythonic API)

Although much of the original API is still present, some alternatives are added to make life a bit
easier.

For example, while you can set any available parameter to command using the "setter" method, you can
also simply specify the parameters when creating the command. So these two commands do same thing:

    rqsm.createQueue().qname("my-queue").vt(20).execute()

    rqsm.createQueue(qname="my-queue", vt=20).execute()

In addition, when creating a main controller, any non-controller parameters specified will become
defaults for all commands created via this controller - so, for example, you if you plan to work
with only one queue using this controller, you can specify the qname parameter during creation of
the controller and not need to specify it in every command.

### A "Consumer" Service Utility

In addition to all the APIs in the original RSMQ project, a simple to use consumer implementation
is included in this project as `RedisSMQConsumer` and `RedisSMQConsumerThread` classes.

#### RedisSMQConsumer
The `RedisSMQConsumer` instance wraps an RSMQ Controller and is configured with a processor method
which is called every time a new message is received. The processor method returns true or false 
to indicate if message was successfully received and the message is deleted or returned to the
queue based on that. The consumer auto-extends the visibility timeout as long as the processor is
running, reducing the concern that item will become visible again if processing takes too long and
visibility timeout elapses.

NOTE: Since currently the `realtime` functionality is not implemented, Consumer implementation is
currently using polling to check for queue items. 

Example usage:

```
from rsmq.consumer import RedisSMQConsumer

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumer('my-queue', processor, host='127.0.0.1')

# run consumer
consumer.run()
```

For a more complete example, see examples directory.


#### RedisSMQConsumerThread

`RedisSMQConsumerThread` is simply a version of `RedisSMQConsumer` that extends Thread class.

Once created you can start it like any other thread, or stop it using `stop(wait)` method, where
wait specifies maximum time to wait for the thread to stop before returning (the thread would still
be trying to stop if the `wait` time expires)

Note that the thread is by default set to be a `daemon` thread, so on exit of your main thread it
will be stopped. If you wish to disable daemon flag, just disable it before starting the thread as
with any other thread

Example usage:

```
from rsmq.consumer import RedisSMQConsumerThread

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumerThread('my-queue', processor, host='127.0.0.1')

# start consumer
consumer.start()

# do what else you need to, then stop the consumer
# (waiting for 10 seconds for it to stop):
consumer.stop(10)

```

For a more complete example, see examples directory.

### General Usage Approach

As copied from other versions, the general approach is to create a controller object and use that
object to create, configure and then execute commands

### Error Handling

Commands follow the pattern of other versions and throw exceptions on error.

Exceptions are all extending `RedisSMQException()` and include:

* `InvalidParameterValue()` - Invalid Parameter specified
* `QueueAlreadyExists()` - attempt to create queue which already exists
* `QueueDoesNotExist()` - attempt to use/delete queue that does not exist
* `NoMessageInQueue()` - attempt to retrieve message from queue that has no visible messaged

However, if you do not wish to use exceptions, you can turn them off on per-command or
per-controller basis by using `.exceptions(False)` on the relevant object. For example, the
following will create Queue only if it does not exist without throwing an exception:

    rsmq.createQueue().exceptions(False).execute()


## Usage

### Example Usage

In this example we will create a new queue named "my-queue", deleting previous version, if one
exists, and then send a message with a 2 second delay. We will then demonstrate both the lack of
message before delay expires and getting the message after timeout


    from pprint import pprint
    import time

    from rsmq import RedisSMQ


    # Create controller.
    # In this case we are specifying the host and default queue name
    queue = RedisSMQ(host="127.0.0.1", qname="myqueue")


    # Delete Queue if it already exists, ignoring exceptions
    queue.deleteQueue().exceptions(False).execute()

    # Create Queue with default visibility timeout of 20 and delay of 0
    # demonstrating here both ways of setting parameters
    queue.createQueue(delay=0).vt(20).execute()

    # Send a message with a 2 second delay
    message_id = queue.sendMessage(delay=2).message("Hello World").execute()

    pprint({'queue_status': queue.getQueueAttributes().execute()})

    # Try to get a message - this will not succeed, as our message has a delay and no other
    # messages are in the queue
    msg = queue.receiveMessage().exceptions(False).execute()

    # Message should be False as we got no message
    pprint({"Message": msg})

    print("Waiting for our message to become visible")
    # Wait for our message to become visible
    time.sleep(2)

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # Get our message
    msg = queue.receiveMessage().execute()

    # Message should now be there
    pprint({"Message": msg})

    # Delete Message
    queue.deleteMessage(id=msg['id'])

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # delete our queue
    queue.deleteQueue().execute()

    # No action
    queue.quit()



### RedisSMQ Controller API Usage

Usage: `rsmq.rqsm.RedisSMQ([options])`

* Options (all options are provided as keyword options):
    * Redis Connection arguments:
        * `client` - provide an existing, configured redis client
        or
        * `host` - redis hostname (Default: `127.0.0.1`)
        * `port` - redis port (Default: `6379`)
        * `options` - additional redis client options. Defaults:
            * `encoding`: `utf-8`
            * `decode_responses`: `True`
    * Controller Options
        * `ns` - namespace - all redis keys are prepended with `<ns>:`. Default: `rsmq`
        * `realtime` - if set to True, enables realtime option. Default: `False`
        * `exceptions` - if set to True, throw exceptions for all commands. Default: `True`
    * Default Command Options. Anything else is passed to each command as defaults. Examples:
        * `qname` - default Queue Name

#### Controller Methods

* `exceptions(True/False)` - enable/disable exceptions
* `setClient(client)` - specify new redis client object
* `ns(namespace)` - set new namespace
* `quit()` - disconnect from redis. This is mainly for compatibility with other versions. Does not do much

#### Controller Commands

* `createQueue()` - Create new queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was created

* `deleteQueue()` - Delete Existing queue
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was deleted

* `setQueueAttributes()` - Update queue attributes. If value is not specified, it is not updated.
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * output of `getQueueAttributes()` call

* `getQueueAttributes()` - Get Queue Attributes and statistics
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** a dictionary with following fields:
        * `vt` -  default visibility timeout
        * `delay` - default insertion delay
        * `maxsize` -  max size of the message
        * `totalrecv` - number of messages consumed. Note, this is incremented each time message is retrieved, so if it was not deleted and made visible again, it will show up here multiple times.
        * `totalsent` - number of messages sent to queue.
        * `created` -  unix timestamp (seconds since epoch) of when the queue was created
        * `modified` -  unix timestamp (seconds since epoch) of when the queue was last updated
        * `msgs` -  Total number of messages currently in the queue
        * `hiddenmsgs` - Number of messages in queue that are not visible

* `listQueues()` - List all queues in this namespace
    * **Parameters:**
    * **Returns**:
        * All queue names in this namespace as a `set()`

* `changeMessageVisibility()` - Change Message Visibility
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * ???
    * **Returns**:
        * ???

* `sendMessage()` - Send message into queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `message` - (Required) message id
        * `delay` - Optional override of the `delay` for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * `encode` if set to `True`, force encode message as JSON string. If False, try to auto-detect if message needs to be encoded
    * **Returns**:
        * message id of the sent message

* `receiveMessage()` - Receive Message from queue and mark it invisible
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - Optional override for visibility timeout for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `popMessage()` -  Receive Message from queue and delete it from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `deleteMessage()` -  Delete Message from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if message was deleted




%package help
Summary:	Development documents and examples for PyRSMQ
Provides:	python3-PyRSMQ-doc
%description help
![RSMQ: Redis Simple Message Queue for Node.js](https://img.webmart.de/rsmq_wide.png)

[![Build Status](https://travis-ci.org/mlasevich/PyRSMQ.svg?branch=master)](https://travis-ci.org/mlasevich/PyRSMQ)
[![Coverage Status](https://coveralls.io/repos/github/mlasevich/PyRSMQ/badge.svg?branch=master)](https://coveralls.io/github/mlasevich/PyRSMQ?branch=master)
[![PyPI version](https://badge.fury.io/py/PyRSMQ.svg)](https://badge.fury.io/py/PyRSMQ)

# Redis Simple Message Queue

A lightweight message queue for Python that requires no dedicated queue server. Just a Redis server.

This is a Python implementation of [https://github.com/smrchy/rsmq](https://github.com/smrchy/rsmq))


## PyRSMQ Release Notes
* 0.4.5
  * Re-release to push to PyPi

* 0.4.4
  * Allow extending the transaction for deleteMessage to perform other actions in same transaction ([#9](https://github.com/mlasevich/PyRSMQ/issues/9)) (@yehonatanz)
  * Use redis timestamp in milliseconds instead of local in seconds ([#11](https://github.com/mlasevich/PyRSMQ/pull/11)) (@yehonatanz)
  * Convert queue attributes to numbers when elligible ([#12](https://github.com/mlasevich/PyRSMQ/pull/12)) (@yehonatanz)


* 0.4.3 
  * Don't encode sent message if it is of type bytes ([#6](https://github.com/mlasevich/PyRSMQ/issues/6))  (@yehonatanz)
  * Allow delay and vt to be float (round only after converting to millis) ([#7](https://github.com/mlasevich/PyRSMQ/issues/7)) (@yehonatanz)
  * Convert ts from str/bytes to int in receive/pop message ([#8](https://github.com/mlasevich/PyRSMQ/issues/8)) (@yehonatanz)

* 0.4.2
  * Fix typo in `setClient` method [#3](https://github.com/mlasevich/PyRSMQ/issues/3)
      * Note this is a breaking change if you use this method, (which seems like nobody does)

* 0.4.1
  * Add auto-decode option for messages from JSON (when possible) in Consumer (on by default)

* 0.4.0
  * Ability to import `RedisSMQ` from package rather than from the module (i.e. you can now use `from rsmq import RedisSMQ` instead of `from rsmq.rsmq import RedisSMQ`)
  * Add quiet option to most commands to allow to hide errors if exceptions are disabled
  * Additional unit tests
  * Auto-encoding of non-string messages to JSON for sendMessage
  * Add `RedisSMQConsumer` and `RedisSMQConsumerThread` for easier creation of queue consumers
  * Add examples for simple producers/consumers

* 0.3.1
  * Fix message id generation match RSMQ algorithm

* 0.3.0
  * Make message id generation match RSMQ algorithm
  * Allow any character in queue name other than `:`

* 0.2.1
  * Allow uppercase characters in queue names

* 0.2.0 - Adding Python 2 support
  * Some Python 2 support
  * Some Unit tests
  * Change `.exec()` to `.execute()` for P2 compatibility

* 0.1.0 - initial version
    * Initial port
    * Missing "Realtime" mode
    * Missing unit tests

## Quick Intro to RSMQ

RSMQ is trying to emulate Amazon's SQS-like functionality, where there is a named queue (name
consists of "namespace" and "qname") that is backed by Redis. Queue must be created before used.
Once created, _Producers_ will place messages in queue and _Consumers_ will retrieve them.
Messages have a property of "visibility" - where any "visible" message may be consumed, but
"invisbile" messages stay in the queue until they become visible or deleted.

Once queue exists, a _Producer_ can push messages into it. When pushing to queue, message gets a
unique ID that is used to track the message. The ID can be used to delete message by _Producer_ or
_Consumer_ or to control its "visibility"

During insertion, a message may have a `delay` associated with it. "Delay" will mark message
"invisible" for specified delay duration, and thus prevent it from being consumed. Delay may be
specified at time of message creation or, if not specified, default value set in queue attributes
is used.

_Consumer_ will retrieve next message in queue via either `receiveMessage()` or `popMessage()`
command. If we do not care about reliability of the message beyond delivery, a good and simple way
to retrieve it is via `popMessage()`.  When using `popMessage()` the message is automatically
deleted at the same time it is received.

However in many cases we want to ensure that the message is not only received, but is also
processed before being deleted. For this, `receiveMessage()` is best. When using `receiveMessage()`,
the message is kept in the queue, but is marked "invisible" for some amount of time. The amount of
time is specified by queue attribute `vt`(visibility timeout), which may also be overridden by
specifying a custom `vt` value in `receiveMessage()` call. When using  `receiveMessage()`,
_Consumer_' is responsible for deleting the message before `vt` timeout occurs, otherwise the
message may be picked up by another _Consumer_. _Consumer_ can also extend the timeout if it needs
more time, or clear the timeout if processing failed.

A "Realtime" mode can be specified when using the RSMQ queue. "Realtime" mode adds a Redis PUBSUB
based notification that would allow _Consumers_ to be notified whenever a new message is added to
the queue. This can remove the need for _Consumer_ to constantly poll the queue when it is empty
(*NOTE:* as of this writing, "Realtime" is not yet implemented in python version)

## Python Implementation Notes

*NOTE* This project is written for Python 3.x. While some attempts to get Python2 support were made
I am not sure how stable it would be under Python 2

This version is heavily based on Java version (https://github.com/igr/jrsmq), which in turn is
based on the original Node.JS version.

### API
To start with, best effort is made to maintain same method/parameter/usablity named of both version
(which, admittedly, resulted in a not very pythonic API)

Although much of the original API is still present, some alternatives are added to make life a bit
easier.

For example, while you can set any available parameter to command using the "setter" method, you can
also simply specify the parameters when creating the command. So these two commands do same thing:

    rqsm.createQueue().qname("my-queue").vt(20).execute()

    rqsm.createQueue(qname="my-queue", vt=20).execute()

In addition, when creating a main controller, any non-controller parameters specified will become
defaults for all commands created via this controller - so, for example, you if you plan to work
with only one queue using this controller, you can specify the qname parameter during creation of
the controller and not need to specify it in every command.

### A "Consumer" Service Utility

In addition to all the APIs in the original RSMQ project, a simple to use consumer implementation
is included in this project as `RedisSMQConsumer` and `RedisSMQConsumerThread` classes.

#### RedisSMQConsumer
The `RedisSMQConsumer` instance wraps an RSMQ Controller and is configured with a processor method
which is called every time a new message is received. The processor method returns true or false 
to indicate if message was successfully received and the message is deleted or returned to the
queue based on that. The consumer auto-extends the visibility timeout as long as the processor is
running, reducing the concern that item will become visible again if processing takes too long and
visibility timeout elapses.

NOTE: Since currently the `realtime` functionality is not implemented, Consumer implementation is
currently using polling to check for queue items. 

Example usage:

```
from rsmq.consumer import RedisSMQConsumer

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumer('my-queue', processor, host='127.0.0.1')

# run consumer
consumer.run()
```

For a more complete example, see examples directory.


#### RedisSMQConsumerThread

`RedisSMQConsumerThread` is simply a version of `RedisSMQConsumer` that extends Thread class.

Once created you can start it like any other thread, or stop it using `stop(wait)` method, where
wait specifies maximum time to wait for the thread to stop before returning (the thread would still
be trying to stop if the `wait` time expires)

Note that the thread is by default set to be a `daemon` thread, so on exit of your main thread it
will be stopped. If you wish to disable daemon flag, just disable it before starting the thread as
with any other thread

Example usage:

```
from rsmq.consumer import RedisSMQConsumerThread

# define Processor
def processor(id, message, rc, ts):
  ''' process the message '''
  # Do something
  return True

# create consumer
consumer = RedisSMQConsumerThread('my-queue', processor, host='127.0.0.1')

# start consumer
consumer.start()

# do what else you need to, then stop the consumer
# (waiting for 10 seconds for it to stop):
consumer.stop(10)

```

For a more complete example, see examples directory.

### General Usage Approach

As copied from other versions, the general approach is to create a controller object and use that
object to create, configure and then execute commands

### Error Handling

Commands follow the pattern of other versions and throw exceptions on error.

Exceptions are all extending `RedisSMQException()` and include:

* `InvalidParameterValue()` - Invalid Parameter specified
* `QueueAlreadyExists()` - attempt to create queue which already exists
* `QueueDoesNotExist()` - attempt to use/delete queue that does not exist
* `NoMessageInQueue()` - attempt to retrieve message from queue that has no visible messaged

However, if you do not wish to use exceptions, you can turn them off on per-command or
per-controller basis by using `.exceptions(False)` on the relevant object. For example, the
following will create Queue only if it does not exist without throwing an exception:

    rsmq.createQueue().exceptions(False).execute()


## Usage

### Example Usage

In this example we will create a new queue named "my-queue", deleting previous version, if one
exists, and then send a message with a 2 second delay. We will then demonstrate both the lack of
message before delay expires and getting the message after timeout


    from pprint import pprint
    import time

    from rsmq import RedisSMQ


    # Create controller.
    # In this case we are specifying the host and default queue name
    queue = RedisSMQ(host="127.0.0.1", qname="myqueue")


    # Delete Queue if it already exists, ignoring exceptions
    queue.deleteQueue().exceptions(False).execute()

    # Create Queue with default visibility timeout of 20 and delay of 0
    # demonstrating here both ways of setting parameters
    queue.createQueue(delay=0).vt(20).execute()

    # Send a message with a 2 second delay
    message_id = queue.sendMessage(delay=2).message("Hello World").execute()

    pprint({'queue_status': queue.getQueueAttributes().execute()})

    # Try to get a message - this will not succeed, as our message has a delay and no other
    # messages are in the queue
    msg = queue.receiveMessage().exceptions(False).execute()

    # Message should be False as we got no message
    pprint({"Message": msg})

    print("Waiting for our message to become visible")
    # Wait for our message to become visible
    time.sleep(2)

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # Get our message
    msg = queue.receiveMessage().execute()

    # Message should now be there
    pprint({"Message": msg})

    # Delete Message
    queue.deleteMessage(id=msg['id'])

    pprint({'queue_status': queue.getQueueAttributes().execute()})
    # delete our queue
    queue.deleteQueue().execute()

    # No action
    queue.quit()



### RedisSMQ Controller API Usage

Usage: `rsmq.rqsm.RedisSMQ([options])`

* Options (all options are provided as keyword options):
    * Redis Connection arguments:
        * `client` - provide an existing, configured redis client
        or
        * `host` - redis hostname (Default: `127.0.0.1`)
        * `port` - redis port (Default: `6379`)
        * `options` - additional redis client options. Defaults:
            * `encoding`: `utf-8`
            * `decode_responses`: `True`
    * Controller Options
        * `ns` - namespace - all redis keys are prepended with `<ns>:`. Default: `rsmq`
        * `realtime` - if set to True, enables realtime option. Default: `False`
        * `exceptions` - if set to True, throw exceptions for all commands. Default: `True`
    * Default Command Options. Anything else is passed to each command as defaults. Examples:
        * `qname` - default Queue Name

#### Controller Methods

* `exceptions(True/False)` - enable/disable exceptions
* `setClient(client)` - specify new redis client object
* `ns(namespace)` - set new namespace
* `quit()` - disconnect from redis. This is mainly for compatibility with other versions. Does not do much

#### Controller Commands

* `createQueue()` - Create new queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was created

* `deleteQueue()` - Delete Existing queue
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if queue was deleted

* `setQueueAttributes()` - Update queue attributes. If value is not specified, it is not updated.
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - default visibility timeout in seconds. Default: `30`
        * `delay` - default delay (visibility timeout on insert). Default: `0`
        * `maxsize` - maximum message size (1024-65535, Default: 65535)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * output of `getQueueAttributes()` call

* `getQueueAttributes()` - Get Queue Attributes and statistics
   * Parameters:
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** a dictionary with following fields:
        * `vt` -  default visibility timeout
        * `delay` - default insertion delay
        * `maxsize` -  max size of the message
        * `totalrecv` - number of messages consumed. Note, this is incremented each time message is retrieved, so if it was not deleted and made visible again, it will show up here multiple times.
        * `totalsent` - number of messages sent to queue.
        * `created` -  unix timestamp (seconds since epoch) of when the queue was created
        * `modified` -  unix timestamp (seconds since epoch) of when the queue was last updated
        * `msgs` -  Total number of messages currently in the queue
        * `hiddenmsgs` - Number of messages in queue that are not visible

* `listQueues()` - List all queues in this namespace
    * **Parameters:**
    * **Returns**:
        * All queue names in this namespace as a `set()`

* `changeMessageVisibility()` - Change Message Visibility
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * ???
    * **Returns**:
        * ???

* `sendMessage()` - Send message into queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `message` - (Required) message id
        * `delay` - Optional override of the `delay` for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
        * `encode` if set to `True`, force encode message as JSON string. If False, try to auto-detect if message needs to be encoded
    * **Returns**:
        * message id of the sent message

* `receiveMessage()` - Receive Message from queue and mark it invisible
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `vt` - Optional override for visibility timeout for this message (If not specified, default for queue is used)
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `popMessage()` -  Receive Message from queue and delete it from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns** dictionary for following fields:
        * `id` - message id
        * `message` - message content
        * `rc` - receive count - how many times this message was received
        * `ts` - unix timestamp of when the message was originally sent

* `deleteMessage()` -  Delete Message from queue
    * **Parameters:**
        * `qname` - (Required) name of the queue
        * `id` - (Required) message id
        * `quiet` - if set to `True` and exceptions are disabled, do not produce error log entries
    * **Returns**:
        * `True` if message was deleted




%prep
%autosetup -n PyRSMQ-0.4.5

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-PyRSMQ -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Apr 25 2023 Python_Bot <Python_Bot@openeuler.org> - 0.4.5-1
- Package Spec generated