Reference
Client
Bases: Client
Source code in src/nats_contrib/request_many/client.py
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 |
|
request_many(subject, payload=None, headers=None, reply_inbox=None, max_wait=None, max_count=None, max_interval=None, stop_on_sentinel=False)
async
Request many responses from the same subject.
This function does not raise an error when no responses are received.
Responses are received until one of the following conditions is met:
- max_wait seconds have passed.
- max_count responses have been received.
- max_interval seconds have passed between responses.
- A sentinel message is received and stop_on_sentinel is True.
Subscription is always stopped when the function returns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
str
|
The subject to send the request to. |
required |
payload |
bytes | None
|
The payload to send with the request. |
None
|
headers |
dict[str, str] | None
|
The headers to send with the request. |
None
|
reply_inbox |
str | None
|
The inbox to receive the responses in. A new inbox is created if None. |
None
|
max_wait |
float | None
|
The maximum amount of time to wait for responses. 1 second by default. |
None
|
max_count |
int | None
|
The maximum number of responses to accept. No limit by default. |
None
|
max_interval |
float | None
|
The maximum amount of time between responses. No limit by default. |
None
|
stop_on_sentinel |
bool
|
Whether to stop when a sentinel message is received. False by default. |
False
|
Source code in src/nats_contrib/request_many/client.py
request_many_iter(subject, payload=None, headers=None, reply_inbox=None, max_wait=None, max_count=None, max_interval=None, stop_on_sentinel=False)
Request many responses from the same subject.
The iterator exits without raising an error when no responses are received.
Responses are received until one of the following conditions is met:
- max_wait seconds have passed.
- max_count responses have been received.
- max_interval seconds have passed between responses.
- A sentinel message is received and stop_on_sentinel is True.
When any of the condition is met, the async iterator yielded by the context manager raises StopAsyncIteration on the next iteration.
The subscription is started when entering the async context manager and stopped when exiting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
str
|
The subject to send the request to. |
required |
payload |
bytes | None
|
The payload to send with the request. |
None
|
headers |
dict[str, str] | None
|
The headers to send with the request. |
None
|
reply_inbox |
str | None
|
The inbox to receive the responses in. A new inbox is created if None. |
None
|
max_wait |
float | None
|
The maximum amount of time to wait for responses. 1 second by default. |
None
|
max_count |
int | None
|
The maximum number of responses to accept. No limit by default. |
None
|
max_interval |
float | None
|
The maximum amount of time between responses. No limit by default. |
None
|
stop_on_sentinel |
bool
|
Whether to stop when a sentinel message is received. False by default. |
False
|
Source code in src/nats_contrib/request_many/client.py
RequestManyExecutor
Source code in src/nats_contrib/request_many/executor.py
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 |
|
__call__(subject, reply_inbox=None, payload=None, headers=None, max_wait=None, max_count=None, max_interval=None, stop_on_sentinel=False)
async
Request many responses from the same subject.
This function does not raise an error when no responses are received.
Responses are received until one of the following conditions is met:
- max_wait seconds have passed.
- max_count responses have been received.
- max_interval seconds have passed between responses.
- A sentinel message is received and stop_on_sentinel is True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
str
|
The subject to send the request to. |
required |
payload |
bytes | None
|
The payload to send with the request. |
None
|
headers |
dict[str, str] | None
|
The headers to send with the request. |
None
|
reply_inbox |
str | None
|
The inbox to receive the responses in. A new inbox is created if None. |
None
|
max_wait |
float | None
|
The maximum amount of time to wait for responses. Default max wait can be configured at the instance level. |
None
|
max_count |
int | None
|
The maximum number of responses to accept. No limit by default. |
None
|
max_interval |
float | None
|
The maximum amount of time between responses. No limit by default. |
None
|
stop_on_sentinel |
bool
|
Whether to stop when a sentinel message is received. False by default. |
False
|
Source code in src/nats_contrib/request_many/executor.py
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 |
|
RequestManyIterator
Source code in src/nats_contrib/request_many/iterator.py
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 |
|
__aenter__()
async
Start the subscription and publish the request.
Source code in src/nats_contrib/request_many/iterator.py
__aexit__(*args, **kwargs)
async
__aiter__()
__anext__()
async
Return the next message or raise StopAsyncIteration.
Source code in src/nats_contrib/request_many/iterator.py
__init__(nc, subject, inbox, payload=None, headers=None, max_wait=None, max_interval=None, max_count=None, stop_on_sentinel=False)
Request many responses from the same subject.
Request is sent when entering the async context manager and unsubscribed when exiting.
The async iterator yieled by the context manager do not raise an error when no responses are received.
Responses are received until one of the following conditions is met:
- max_wait seconds have passed.
- max_count responses have been received.
- max_interval seconds have passed between responses.
- A sentinel message is received and stop_on_sentinel is True.
When any of the condition is met, the async iterator raises StopAsyncIteration on the next call to anext, and the subscription is unsubscribed on exit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
str
|
The subject to send the request to. |
required |
payload |
bytes | None
|
The payload to send with the request. |
None
|
headers |
dict[str, str] | None
|
The headers to send with the request. |
None
|
inbox |
str
|
The inbox to receive the responses in. A new inbox is created if None. |
required |
max_wait |
float | None
|
The maximum amount of time to wait for responses. Default max wait can be configured at the instance level. |
None
|
max_count |
int | None
|
The maximum number of responses to accept. No limit by default. |
None
|
max_interval |
float | None
|
The maximum amount of time between responses. No limit by default. |
None
|
stop_on_sentinel |
bool
|
Whether to stop when a sentinel message is received. False by default. |
False
|
Source code in src/nats_contrib/request_many/iterator.py
cleanup()
async
Unsubscribe from the inbox and cancel all the tasks.
Source code in src/nats_contrib/request_many/iterator.py
transform(source, map)
Create a new async context manager which will yield an async iterator that applies the map function to each value yielded by the source async iterator.
It is useful for example to transform the return value of the
request_many_iter
method.