Packages
amqp10_client
4.0.3
4.2.1
4.2.0
retired
4.1.6
4.1.5
retired
4.1.5-rc.2
retired
4.1.5-rc.1
retired
4.1.5-1
4.0.3
4.0.3-rc.1
3.13.0-rc.2
3.13.0-rc.1
3.12.14
3.12.13
3.12.12
3.12.11
3.12.10
3.12.9
3.12.8
3.12.7
3.12.6
3.12.5
3.12.4
3.12.3
3.12.2
3.12.1
3.12.0
3.12.0-rc.4
3.12.0-rc.3
3.12.0-rc.2
3.12.0-rc.1
3.11.28
3.11.27
3.11.26
3.11.25
3.11.24
3.11.23
3.11.22
3.11.21
3.11.20
3.11.19
3.11.18
3.11.17
3.11.16
3.11.15
3.11.14
3.11.13
3.11.12
3.11.11
3.11.10
3.11.9
3.11.8
3.11.7
3.11.6
3.11.5
3.11.4
3.11.3
3.11.2
3.11.1
3.11.0
3.11.0-rc.2
3.11.0-rc.1
3.11.0-1
3.10.25
3.10.24
3.10.23
3.10.22
3.10.20
3.10.19
3.10.18
3.10.17
3.10.16
3.10.15
3.10.14
3.10.13
3.10.12
3.10.11
3.10.10
3.10.9
3.10.8
3.10.7
3.10.6
3.10.5
3.10.4
3.10.3
3.10.2
retired
3.10.2-1
3.10.1
retired
3.10.0
retired
3.10.0-rc.6
3.10.0-rc.5
3.10.0-rc.1
3.9.29
3.9.28
3.9.27
3.9.26
3.9.25
3.9.24
3.9.23
3.9.22
3.9.21
3.9.20
3.9.19
3.9.18
retired
3.9.17
3.9.16
3.9.15
3.8.35
3.8.34
3.8.33
3.8.32
3.8.31
3.8.30
0.0.0-rc.1
AMQP 1.0 client
Current section
Files
Jump to
Current section
Files
amqp10_client
README.md
README.md
# Erlang AMQP 1.0 clientThis is an [Erlang client for the AMQP 1.0](https://www.amqp.org/resources/specifications) protocol.Its primary purpose is to be used in RabbitMQ related projects but it is ageneric client that was tested with at least 3 implementations of AMQP 1.0.If you are looking for an Erlang client for [AMQP 0-9-1](https://www.rabbitmq.com/tutorials/amqp-concepts.html) — a completely differentprotocol despite the name — [consider this one](../amqp_client).## Project Maturity and StatusThis client is used in the cross-protocol version of the RabbitMQ Shovel plugin. It is not 100%feature complete but moderately mature and was tested against at least 3 AMQP 1.0 servers:RabbitMQ, Azure ServiceBus, ActiveMQ.This client library is not officially supported by VMware at this time.## Usage### Connection SettingsThe `connection_config` map contains various configuration properties.``` -type address :: inet:socket_address() | inet:hostname().-type connection_config() :: #{container_id => binary(), % mandatory %% must provide a list of addresses or a single address addresses => [address()], address => address(), %% defaults to 5672, mandatory for TLS port => inet:port_number(), % the dns name of the target host % required by some vendors such as Azure ServiceBus hostname => binary(), tls_opts => {secure_port, [ssl:tls_option()]}, % optional notify => pid(), % Pid to receive protocol notifications. Set to self() if not provided max_frame_size => non_neg_integer(), % incoming max frame size idle_time_out => non_neg_integer(), % heartbeat sasl => none | anon | {plain, User :: binary(), Password :: binary(), % set this to a negative value to allow a sender to "overshoot" the flow % control by this margin transfer_limit_margin => 0 | neg_integer()} }.```### TLSTLS is enabled by setting the `tls_opts` connection configuration property.Currently the only valid value is `{secure_port, [tls_option]}` where the portspecified only accepts TLS. It is possible that tls negotiation as describedin the amqp 1.0 protocol will be supported in the future. If no value is providedfor `tls_opt` then a plain socket will be used.### Basic Example```%% this will connect to a localhost node{ok, Hostname} = inet:gethostname(),User = <<"guest">>,Password = <<"guest">>,%% create a configuration mapOpnConf = #{address => Hostname, port => Port, container_id => <<"test-container">>, sasl => {plain, User, Password}},{ok, Connection} = amqp10_client:open_connection(OpnConf),{ok, Session} = amqp10_client:begin_session(Connection),SenderLinkName = <<"test-sender">>,{ok, Sender} = amqp10_client:attach_sender_link(Session, SenderLinkName, <<"a-queue-maybe">>),%% wait for credit to be receivedreceive {amqp10_event, {link, Sender, credited}} -> okafter 2000 -> exit(credited_timeout)end.%% Create a new message using a delivery-tag, body and indicate%% its settlement status (true meaning no disposition confirmation%% will be sent by the receiver).OutMsg = amqp10_msg:new(<<"my-tag">>, <<"my-body">>, true),ok = amqp10_client:send_msg(Sender, OutMsg),ok = amqp10_client:detach_link(Sender),%% create a receiver link{ok, Receiver} = amqp10_client:attach_receiver_link(Session, <<"test-receiver">>, <<"a-queue-maybe">>),%% grant some credit to the remote sender but don't auto-renew itok = amqp10_client:flow_link_credit(Receiver, 5, never),%% wait for a deliveryreceive {amqp10_msg, Receiver, InMsg} -> okafter 2000 -> exit(delivery_timeout)end.ok = amqp10_client:close_connection(Connection),```### EventsThe `ampq10_client` API is mostly asynchronous with respect to the AMQP 1.0protocol. Functions such as `amqp10_client:open_connection` typically returnafter the `Open` frame has been successfully written to the socket rather thanwaiting until the remote end returns with their `Open` frame. The client willnotify the caller of various internal/async events using `amqp10_event`messages. In the example above when the remote replies with their `Open` framea message is sent of the following form:```{amqp10_event, {connection, ConnectionPid, opened}}```When the connection is closed an event is issued as such:```{amqp10_event, {connection, ConnectionPid, {closed, Why}}}````Why` could be `normal` or contain a description of an error that occuredand resulted in the closure of the connection.Likewise sessions and links have similar events using a similar format.```%% success events{amqp10_event, {connection, ConnectionPid, opened}}{amqp10_event, {session, SessionPid, begun}}{amqp10_event, {link, LinkRef, attached}}``````%% error events{amqp10_event, {connection, ConnectionPid, {closed, Why}}}{amqp10_event, {session, SessionPid, {ended, Why}}}{amqp10_event, {link, LinkRef, {detached, Why}}}```In addition the client may notify the initiator of certain protocolevents such as a receiver running out of credit or credit being availableto a sender.```%% no more credit available to sender{amqp10_event, {link, Sender, credit_exhausted}}%% sender credit received{amqp10_event, {link, Sender, credited}}```Other events may be declared as necessary, Hence it makes sense for a userof the client to handle all `{amqp10_event, _}` events to ensure unexpectedmessages aren't kept around in the mailbox.