# Module cloudi_queue

- Description
- Data Types
- Function Index
- Function Details

### CloudI Send Queue

For internal services that need to have successful service request sends (i.e., a timeout does not occur because a response is received within the timeout period) with each send done asynchronously and all tracking done with in-memory data.

.

Copyright © 2015-2020 Michael Truog

Version: 2.0.1 Dec 3 2021 17:15:33 ------------------------------------------------------------------------

Authors: Michael Truog (`mjtruog at protonmail dot com`).

## Description

### CloudI Send Queue

For internal services that need to have successful service request sends (i.e., a timeout does not occur because a response is received within the timeout period) with each send done asynchronously and all tracking done with in-memory data.

The data is not queued within this module's internal data structure, but like all service requests, the queueing occurs in the destination service process. This module's internal data provides tracking based on the service request transaction id so many asynchronous service requests may be easily managed concurrently. The alternative is to rely on synchronous service requests and increase the sending service's process count as necessary for concurrency, which is a simpler approach. So, cloudi_queue usage is necessary when multiple service requests must be sent concurrently and every request must receive a response (receiving a response is the only proof the transaction was successful).

Only one instance of cloudi_queue is necessary within a service's state due to the transaction id being globally unique.

If retries are enabled (by default, no retries are attempted), it is possible that a service request will be delivered more than once (e.g., if the service request is processed but the response is not sent before a timeout occurs). Each retry sends a service request with the same transaction id, so it may be used to detect a duplicate receive (or a separate unique id could be used from within the RequestInfo or Request data) by checking and modifying service state.

## Data Types

### options()

`options() = [{retry, non_neg_integer()} | {retry_delay, non_neg_integer()} | {suspended, boolean()} | {ordered, boolean()} | {timeout_default, cloudi_service:timeout_milliseconds()} | {priority_default, cloudi_service:priority()} | {validate_request_info, fun((RequestInfo::cloudi_service:request_info()) -> boolean()) | {Module1::module(), Function1::atom()}} | {validate_request, fun((RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request()) -> boolean()) | {Module2::module(), Function2::atom()}} | {validate_response_info, fun((ResponseInfo::cloudi_service:response_info()) -> boolean()) | {Module3::module(), Function3::atom()}} | {validate_response, fun((ResponseInfo::cloudi_service:response_info(), Response::cloudi_service:response()) -> boolean()) | {Module4::module(), Function4::atom()}} | {failures_source_die, boolean()} | {failures_source_max_count, pos_integer()} | {failures_source_max_period, infinity | pos_integer()}]`

### ordered_requests()

`ordered_requests() = queue:queue(#request_ordered_send{name = cloudi_service:service_name(), request_info = cloudi_service:request_info(), request = cloudi_service:request(), timeout = cloudi_service:timeout_milliseconds(), priority = cloudi_service:priority(), id = cloudi_service:trans_id(), pattern_pid = cloudi_service:pattern_pid() | undefined} | #request_ordered_mcast{name = cloudi_service:service_name(), request_info = cloudi_service:request_info(), request = cloudi_service:request(), timeout = cloudi_service:timeout_milliseconds(), priority = cloudi_service:priority()})`

### requests()

`requests() = #{cloudi_service:trans_id() := #request{name = cloudi_service:service_name(), request_info = cloudi_service:request_info(), request = cloudi_service:request(), timeout = cloudi_service:timeout_milliseconds(), priority = cloudi_service:priority(), id = cloudi_service:trans_id(), pattern_pid = cloudi_service:pattern_pid(), retry_pattern_pid = boolean(), retry_count = non_neg_integer(), retry_delay = boolean()}}`

### state()

`state() = #cloudi_queue{retry = non_neg_integer(), retry_delay = non_neg_integer(), suspended = boolean(), ordered = boolean(), timeout_default = cloudi_service:timeout_milliseconds(), priority_default = cloudi_service:priority(), word_size = pos_integer(), service = undefined | pid(), validate_request_info = undefined | fun((any()) -> boolean()), validate_request = undefined | fun((any(), any()) -> boolean()), validate_response_info = undefined | fun((any()) -> boolean()), validate_response = undefined | fun((any(), any()) -> boolean()), failures_source_die = boolean(), failures_source_max_count = pos_integer(), failures_source_max_period = infinity | pos_integer(), failures_source = [cloudi_timestamp:seconds_monotonic()], suspend_requests = suspend_requests(), ordered_requests = ordered_requests(), ordered_pending = non_neg_integer(), requests = requests()}`

### suspend_requests()

`suspend_requests() = queue:queue(#request_suspend_send{name = cloudi_service:service_name(), request_info = cloudi_service:request_info(), request = cloudi_service:request(), timeout = cloudi_service:timeout_milliseconds(), priority = cloudi_service:priority(), id = cloudi_service:trans_id(), pattern_pid = cloudi_service:pattern_pid() | undefined} | #request_suspend_mcast{name = cloudi_service:service_name(), request_info = cloudi_service:request_info(), request = cloudi_service:request(), timeout = cloudi_service:timeout_milliseconds(), priority = cloudi_service:priority()})`

## Function Index

byte_size/2 | #### Return the size of the CloudI queue in bytes. .
byte_size/4 | #### Return the size of the CloudI queue in bytes with the additional service request added. .
byte_size/5 | #### Return the size of the CloudI queue in bytes with the additional service request added. .
byte_size/6 | #### Return the size of the CloudI queue in bytes with the additional service request added. .
byte_size/7 | #### Return the size of the CloudI queue in bytes with the additional service request added. .
byte_size/8 | #### Return the size of the CloudI queue in bytes with the additional service request added. .
failures/2 | #### Return the current number of failures to send and validate. .
handle_info/3 | #### Handle all info messages related to the CloudI queue. Must be called from the `cloudi_service_handle_info/3` callback function.
mcast/4 | #### Send a multicast service request. .
mcast/5 | #### Send a multicast service request. .
mcast/7 | #### Send a multicast service request. .
new/0 | #### Create a CloudI queue. .
new/1 | #### Create a CloudI queue. .
recv/3 | #### Receive a service request. Must be called from the `cloudi_service_handle_info/3` callback function.
recv_id/3 | #### Receive a service request and provide the first transaction id. Must be called from the `cloudi_service_handle_info/3` callback function.
resume/2 | #### Resume sending service requests. .
send/4 | #### Send a service request. .
send/5 | #### Send a service request. .
send/6 | #### Send a service request. .
send/7 | #### Send a service request. .
send/8 | #### Send a service request. .
send_id/4 | #### Send a service request and provide the first transaction id. .
send_id/5 | #### Send a service request and provide the first transaction id. .
send_id/6 | #### Send a service request and provide the first transaction id. .
send_id/7 | #### Send a service request and provide the first transaction id. .
send_id/8 | #### Send a service request and provide the first transaction id. .
size/2 | #### Return the size of the CloudI queue. .
suspend/2 | #### Suspend sending service requests. .
timeout/3 | #### A service request timeout. `ok` is returned if a service request is retried.

## Function Details

### byte_size/2

`byte_size(Dispatcher::cloudi_service:dispatcher(), State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes.

### byte_size/4

`byte_size(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes with the additional service request added.

### byte_size/5

`byte_size(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes with the additional service request added.

### byte_size/6

`byte_size(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes with the additional service request added.

### byte_size/7

`byte_size(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes with the additional service request added.

### byte_size/8

`byte_size(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue in bytes with the additional service request added.

### failures/2

`failures(Dispatcher::cloudi_service:dispatcher(), State::state()) -> non_neg_integer()`

#### Return the current number of failures to send and validate.

### handle_info/3

`handle_info(Return_async_active::any(), State::state(), Dispatcher::cloudi_service:dispatcher()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()} | {ignored, State::state()}`

#### Handle all info messages related to the CloudI queue.

Must be called from the `cloudi_service_handle_info/3` callback function.

### mcast/4

`mcast(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), State::state()) -> {ok, State::state()} | {{error, Reason::cloudi_service:error_reason()}, State::state()}`

#### Send a multicast service request.

### mcast/5

`mcast(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), State::state()) -> {ok, State::state()} | {{error, Reason::cloudi_service:error_reason()}, State::state()}`

#### Send a multicast service request.

### mcast/7

`mcast(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), State::state()) -> {ok, State::state()} | {{error, Reason::cloudi_service:error_reason()}, State::state()}`

#### Send a multicast service request.

### new/0

`new() -> state()`

#### Create a CloudI queue.

### new/1

`new(Options::options()) -> state()`

#### Create a CloudI queue.

### recv/3

`recv(Dispatcher::cloudi_service:dispatcher(), ReturnAsync::#return_async_active{name = cloudi_service:service_name(), pattern = cloudi_service:service_name_pattern(), response_info = cloudi_service:response_info(), response = cloudi_service:response(), timeout = cloudi_service:timeout_value_milliseconds(), trans_id = cloudi_service:trans_id()}, State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()} | {ignored, State::state()}`

#### Receive a service request.

Must be called from the `cloudi_service_handle_info/3` callback function.

### recv_id/3

`recv_id(Dispatcher::cloudi_service:dispatcher(), Return_async_active::#return_async_active{name = cloudi_service:service_name(), pattern = cloudi_service:service_name_pattern(), response_info = cloudi_service:response_info(), response = cloudi_service:response(), timeout = cloudi_service:timeout_value_milliseconds(), trans_id = cloudi_service:trans_id()}, State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()} | {ignored, State::state()}`

#### Receive a service request and provide the first transaction id.

Must be called from the `cloudi_service_handle_info/3` callback function.

### resume/2

`resume(Dispatcher::cloudi_service:dispatcher(), State::state()) -> StateNew::state()`

#### Resume sending service requests.

### send/4

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request.

### send/5

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request.

### send/6

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request.

### send/7

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request.

### send/8

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request.

### send_id/4

`send_id(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request and provide the first transaction id.

### send_id/5

`send_id(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request and provide the first transaction id.

### send_id/6

`send_id(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request and provide the first transaction id.

### send_id/7

`send_id(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request and provide the first transaction id.

### send_id/8

`send_id(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), RequestInfo::cloudi_service:request_info(), Request::cloudi_service:request(), Timeout::cloudi_service:timeout_milliseconds(), Priority::cloudi_service:priority(), PatternPid::cloudi_service:pattern_pid() | undefined, State::state()) -> {ok, Id::cloudi_service:trans_id(), StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()}`

#### Send a service request and provide the first transaction id.

### size/2

`size(Dispatcher::cloudi_service:dispatcher(), State::state()) -> non_neg_integer()`

#### Return the size of the CloudI queue.

### suspend/2

`suspend(Dispatcher::cloudi_service:dispatcher(), State::state()) -> StateNew::state()`

#### Suspend sending service requests.

### timeout/3

`timeout(Dispatcher::cloudi_service:dispatcher(), TimeoutAsync::#timeout_async_active{trans_id = cloudi_service:trans_id()}, State::state()) -> {ok, StateNew::state()} | {{error, Reason::cloudi_service:error_reason()}, StateNew::state()} | {ignored, State::state()}`

#### A service request timeout.

`ok` is returned if a service request is retried. Must be called from the `cloudi_service_handle_info/3` callback function.

Generated by EDoc