Module amqp_connection

This module is responsible for maintaining a connection to an AMQP broker and manages channels within the connection.

Description

This module is responsible for maintaining a connection to an AMQP broker and manages channels within the connection. This module is used to open and close connections to the broker as well as creating new channels within a connection.
The connections and channels created by this module are supervised under amqp_client's supervision tree. Please note that connections and channels do not get restarted automatically by the supervision tree in the case of a failure. If you need robust connections and channels, we recommend you use Erlang monitors on the returned connection and channel PIDs.

In case of a failure or an AMQP error, the connection process exits with a meaningful exit reason:

Cause Exit reason
Any reason, where Code would have been 200 otherwise
  normal
User application calls amqp_connection:close/3
  close_reason(app_initiated_close)
Server closes connection (hard error)
  close_reason(server_initiated_close)
Server misbehaved (did not follow protocol)
  close_reason(server_misbehaved)
AMQP client internal error - usually caused by a channel exiting with an unusual reason. This is usually accompanied by a more detailed error log from the channel
  close_reason(internal_error)
Other error (various error reasons, causing more detailed logging)

See type definitions below.

Data Types

amqp_adapter_info()

amqp_adapter_info() = #amqp_adapter_info{}

amqp_params_direct()

amqp_params_direct() = #amqp_params_direct{}

As defined in amqp_client.hrl. It contains the following fields:

amqp_params_network()

amqp_params_network() = #amqp_params_network{}

As defined in amqp_client.hrl. It contains the following fields:

amqp_reason()

amqp_reason(Type) = {Type, Code, Text}

close_reason()

close_reason(Type) = {shutdown, amqp_reason(Type)}

Function Index

close/1Closes the channel, invokes close(Channel, 200, <<"Goodbye">>).
close/2Closes the channel, using the supplied Timeout value.
close/3Closes the AMQP connection, allowing the caller to set the reply code and text.
close/4Closes the AMQP connection, allowing the caller to set the reply code and text, as well as a timeout for the operation, after which the connection will be abruptly terminated.
connection_name/1Returns user specified connection name from client properties.
error_atom/1Returns a descriptive atom corresponding to the given AMQP error code.
info/2Returns information about the connection, as specified by the Items list.
info_keys/0Returns a list of atoms that can be used in conjunction with info/2.
info_keys/1Returns a list of atoms that can be used in conjunction with info/2.
open_channel/1Invokes open_channel(ConnectionPid, none, {amqp_selective_consumer, []}).
open_channel/2Invokes open_channel(ConnectionPid, none, Consumer).
open_channel/3Opens an AMQP channel.
register_blocked_handler/2
socket_adapter_info/2Takes a socket and a protocol, returns an #amqp_adapter_info{} based on the socket for the protocol given.
start/1same as start(Params, undefined)
start/2Starts a connection to an AMQP server.
update_secret/3

Function Details

close/1

close(ConnectionPid) -> ok | Error

Closes the channel, invokes close(Channel, 200, <<"Goodbye">>).

close/2

close(ConnectionPid, Timeout) -> ok | Error

Closes the channel, using the supplied Timeout value.

close/3

close(ConnectionPid, Code, Text) -> ok | closing

Closes the AMQP connection, allowing the caller to set the reply code and text.

close/4

close(ConnectionPid, Code, Text, Timeout) -> ok | closing

Closes the AMQP connection, allowing the caller to set the reply code and text, as well as a timeout for the operation, after which the connection will be abruptly terminated.

connection_name/1

connection_name(ConnectionPid) -> ConnectionName

Returns user specified connection name from client properties

error_atom/1

error_atom(Code) -> atom()

Returns a descriptive atom corresponding to the given AMQP error code.

info/2

info(ConnectionPid, Items) -> ResultList

Returns information about the connection, as specified by the Items list. Item may be any atom returned by info_keys/1:

info_keys/0

info_keys() -> Items

Returns a list of atoms that can be used in conjunction with info/2. These are general info keys, which can be used in any type of connection. Other info keys may exist for a specific type. To get the full list of atoms that can be used for a certain connection, use info_keys/1.

info_keys/1

info_keys(ConnectionPid) -> Items

Returns a list of atoms that can be used in conjunction with info/2. Note that the list differs from a type of connection to another (network vs. direct). Use info_keys/0 to get a list of info keys that can be used for any connection.

open_channel/1

open_channel(ConnectionPid) -> any()

Invokes open_channel(ConnectionPid, none, {amqp_selective_consumer, []}). Opens a channel without having to specify a channel number. This uses the default consumer implementation.

open_channel/2

open_channel(ConnectionPid, Consumer) -> any()

Invokes open_channel(ConnectionPid, none, Consumer). Opens a channel without having to specify a channel number.

open_channel/3

open_channel(ConnectionPid, ChannelNumber, Consumer) -> Result

Opens an AMQP channel.
Opens a channel, using a proposed channel number and a specific consumer implementation.
ConsumerModule must implement the amqp_gen_consumer behaviour. ConsumerArgs is passed as parameter to ConsumerModule:init/1.
This function assumes that an AMQP connection (networked or direct) has already been successfully established.
ChannelNumber must be less than or equal to the negotiated max_channel value, or less than or equal to ?MAX_CHANNEL_NUMBER (65535) if the negotiated max_channel value is 0.
In the direct connection, max_channel is always 0.

register_blocked_handler/2

register_blocked_handler(ConnectionPid, BlockHandler) -> any()

socket_adapter_info/2

socket_adapter_info(Sock, Protocol) -> any()

Takes a socket and a protocol, returns an #amqp_adapter_info{} based on the socket for the protocol given.

start/1

start(AmqpParams::Params) -> {ok, Connection} | {error, Error}

same as start(Params, undefined)

start/2

start(AmqpParams::Params, ConnName::ConnectionName) -> {ok, Connection} | {error, Error}

Starts a connection to an AMQP server. Use network params to connect to a remote AMQP server or direct params for a direct connection to a RabbitMQ server, assuming that the server is running in the same process space. If the port is set to 'undefined', the default ports will be selected depending on whether this is a normal or an SSL connection. If ConnectionName is binary - it will be added to client_properties as user specified connection name.

update_secret/3

update_secret(ConnectionPid::pid(), NewSecret::term(), Reason::binary()) -> {ok, rabbit_types:auth_user()} | {refused, string(), [any()]} | {error, any()}


Generated by EDoc