# 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-2016 Michael Truog

Version: 1.5.5 Mar 28 2017 19:21:39 ------------------------------------------------------------------------

Authors: Michael Truog (`mjtruog [at] gmail (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.

## Data Types

### dict_proxy()

`dict_proxy(Key, Value) = dict:dict(Key, Value)`

### options()

`options() = [{retry, non_neg_integer()} | {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()}]`

### state()

`state() = #cloudi_queue{retry_max = non_neg_integer(), 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 = [erlang:timestamp()], requests = dict_proxy(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(), pattern_pid = cloudi_service:pattern_pid(), retry_count = non_neg_integer()})}`

## Function Index

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.
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. .
timeout/3 | #### A service request timeout. `ok` is returned if a service request is retried.

## Function Details

### 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(), 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, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::state()}`

#### Receive a service request.

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

### send/4

`send(Dispatcher::cloudi_service:dispatcher(), Name::cloudi_service:service_name(), Request::cloudi_service:request(), State::state()) -> {ok, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::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, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::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(), State::state()) -> {ok, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::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, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::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, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::state()}`

#### Send a service request.

### timeout/3

`timeout(Dispatcher::cloudi_service:dispatcher(), Timeout_async_active::#timeout_async_active{trans_id = cloudi_service:trans_id()}, State::state()) -> {ok, NewState::state()} | {{error, Reason::cloudi_service:error_reason()}, NewState::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, Mar 28 2017, 19:21:39.