module Netamqp_endpoint:sig
..end
They implement the send/receive queues, and the message dispatcher
typeconnector =
[ `Implied | `Inet of string * int | `Sockaddr of Unix.sockaddr ]
`Sockaddr a
: the server port is given by socket address a
`Inet(host,port)
: the server is identified by this host/port pair`Implied
: a reserved connector when the server address is implicitly
known onlytypetransport_layer =
[ `Custom of
unit -> Netamqp_transport.amqp_multiplex_controller Uq_engines.engine
| `TCP of connector
| `TLS of
connector * (module Netsys_crypto_types.TLS_CONFIG) ]
`TCP connector
: Use TCP`Custom f
: Call f ()
to get a new transport streamtype
endpoint
typestate =
[ `Connected of bool
| `Disconnected
| `Disconnecting of bool
| `Error of exn
| `Off ]
`Off
: Endpoint is still down (initial state)`Connected flag
: The endpoint accepts requests. If flag
,
the TCP connection is established. Note that the endpoint
already allows to add requests before the TCP connection is
fully established.`Disconnecting flag
: A disconnect is requested when all async
methods are sent and all sync methods are responded, i.e. when
all locally requested operations are done. If flag
, the
TCP connection is established. The case flag=false
can only
happen if a not-yet fully connected endpoint is disconnected.`Disconnected
: Endpoint is down after regular disconnect`Error
: A low-level error occurred, and the endpoint is downtypeproto_revision_0_9 =
[ `One ]
typeprotocol =
[ `AMQP_0_9 of proto_revision_0_9 ]
`AMQP_0_9
: This actually chooses AMQP-0-9-1 with as much
compatibility as possible for existing servers. 0-9-1 is
the subset of 0-9 that is widely implemented.
Both styles of message exchange can be started by either peer, client or server.
In a request/response pair, each of the two control messages is called a method.
A method usually has arguments. The method type is the method without arguments.
The methods are described in more detail in an XML file (e.g.
amqp0-9-1.xml). There is also a version-specific Ocaml module that
is generated: Netamqp_method_0_9
. See there how the methods
are formalized (e.g. which types the arguments have).
typesync_client_to_server_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.sync_client_to_server_method_t ]
typesync_server_to_client_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.sync_server_to_client_method_t ]
typesync_client_initiated_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.sync_client_initiated_method_t ]
typesync_server_initiated_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.sync_server_initiated_method_t ]
typesync_server_initiated_method_type_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.sync_server_initiated_method_type_t ]
typeasync_client_to_server_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.async_client_to_server_method_t ]
typeasync_server_to_client_method_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.async_server_to_client_method_t ]
typeasync_server_to_client_method_type_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.async_server_to_client_method_type_t ]
typemethod_type_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.method_type_t ]
typeprops_t =
[ `AMQP_0_9 of Netamqp_methods_0_9.props_t ]
`P_basic
is actually available.typedata =
props_t * Netxdr_mstring.mstring list
mstring
, an abstraction over several
possible representations of byte arrays provided by Ocamlnet
(see the rpc
library for Netxdr_mstring
).
Data received from the server is often returned as a true list with more than one element. Each element represents a frame on the transport level.
There is no need to split strings into frames before passing
the strings to the endpoint for sending them to the server. This
is done automatically if needed.
val create : transport_layer ->
protocol ->
Unixqueue.event_system -> endpoint
`Off
.val configure_timeout : endpoint -> float -> unit
val get_timeout : endpoint -> float
val default_port : int
val connect : endpoint -> unit
`Connected false
.
If the endpoint is already connected, nothing changes.
After calling connect
the underlying transport is still inactive,
but the connection procedure is triggered. It is nevertheless immediately
possible to add requests to the endpoint. These will be carried out
once the connection on the transport level is established.
val disconnect : endpoint -> unit
`Disconnecting
.val quick_disconnect : endpoint -> unit
val reset : endpoint -> unit
val state : endpoint -> state
val state_change_e : endpoint -> state Uq_engines.engine
state
change.
It is possible to immediately create another state_change_e
when
the previous engine finishes. This allows it to continuously watch
for state changes.
val event_system : endpoint -> Unixqueue.event_system
val protocol : endpoint -> protocol
`Connected
, i.e. after calling connect
.val getsockname : endpoint -> Netamqp_transport.sockaddr
val getpeername : endpoint -> Netamqp_transport.sockaddr
val enable_channel : endpoint -> Netamqp_types.channel -> unit
val disable_channel : endpoint -> Netamqp_types.channel -> unit
Channel 0 is always enabled.
Disabling a channel immediately drops all unsent messages except
those on the priority queue. Also,
pending synchronous calls will get the exception
Netamqp_types.Method_dropped
. All registrations
for the channel are deleted.
val is_channel_enabled : endpoint -> Netamqp_types.channel -> bool
val suggest_channel : endpoint -> Netamqp_types.channel
val flow_control : endpoint -> Netamqp_types.channel -> bool -> unit
This only affects content messages sent to the server.
val drop_frames : endpoint -> unit
val clear_output : endpoint -> unit
val expect_eof : endpoint -> unit
Netamqp_types.Unexpected_eof
exception when EOF is seen from the serverval set_max_frame_size : endpoint -> int -> unit
val eff_max_frame_size : endpoint -> int
Netampq_transport.amqp_multiplex_controller
val announce_e : endpoint -> unit Uq_engines.engine
val announce_s : endpoint -> unit
val sync_c2s_e : ?no_wait:sync_server_to_client_method_t ->
?on_timeout:(unit -> unit) ->
endpoint ->
sync_client_initiated_method_t ->
data option ->
Netamqp_types.channel ->
float ->
(sync_server_to_client_method_t *
data option)
Uq_engines.engine
val sync_c2s_s : ?no_wait:sync_server_to_client_method_t ->
?on_timeout:(unit -> unit) ->
endpoint ->
sync_client_initiated_method_t ->
data option ->
Netamqp_types.channel ->
float ->
sync_server_to_client_method_t *
data option
Only certain methods may be accompanied with a data item
(`Basic_return
). Only certain methods
can have a data item in the response (`Basic_get_ok
).
Actually, the possible return methods are much more restricted
than sync_server_to_client_method_t
, e.g. `Channel_open
can only be responded with `Channel_open_ok
. This is not
reflected in the function type, though.
The float
arg is the timeout. If the message is not responded
within that time frame, the exception Timeout
is raised.
Option no_wait
: If set, the function does not wait for the reply,
but immediately returns the method no_wait
(and no data).
Option on_timeout
: This function is called first when a timeout
occurs. (Additionally, all pending sync_c2s calls on the same
channel get a Timeout
exception.)
val register_sync_s2c : endpoint ->
sync_server_initiated_method_type_t ->
Netamqp_types.channel ->
(sync_server_initiated_method_t ->
sync_client_to_server_method_t option) ->
(unit -> unit) -> unit
Normally, the callback returns Some r
where r
is the
response method. The callback is also allowed to return None
in case of an error.
Some additional reaction should be provided, though, e.g. by requesting a
connection close.
The post action function is only invoked if the callback returns a result. The idea is that another action can be triggered after the response has been added to the output queue.
The response is not added to the normal output queue, but to the priority output queue, and has precedence to all other methods emitted by the client.
The registered handler is not notified if there is a state
change of the endpoint or if an error is propagated. If this
is required, the handler should configure additional monitoring
for these events.
val async_c2s : endpoint ->
async_client_to_server_method_t ->
data option -> Netamqp_types.channel -> unit
Only certain methods may be accompanied with a data item
(`Basic_publish
).
There is no indication of any kind whether the operation was
successful, not even whether it could be sent to the
server. If feedback is required one must use transactions
(Tx
class).
val async_c2s_e : endpoint ->
async_client_to_server_method_t ->
data option ->
Netamqp_types.channel -> unit Uq_engines.engine
val async_c2s_s : endpoint ->
async_client_to_server_method_t ->
data option -> Netamqp_types.channel -> unit
async_c2s
return first when the message is
passed to the socket.val register_async_s2c : endpoint ->
async_server_to_client_method_type_t ->
Netamqp_types.channel ->
(async_server_to_client_method_t ->
data option -> unit) ->
unit
The registered handler is not notified if there is a state
change of the endpoint or if an error is propagated. If this
is required, the handler should configure additional monitoring
for these events.
`Error e
, where the exception e
describes the error. Some other kinds of locally detected errors are also
handled like this. After shutting the endpoint down, the error is
propagated (see below).
Exception codes coming from the server are wrapped as `Connection_close
or `Channel_close
methods. These are forwarded to registered
handlers (register_sync_s2c
). The handlers can decide to propagate
the error code further by calling propagate_error
with a
Method_exception
.
Error propagation is done for all errors detected by the endpoint,
but it can also be invoked from outside (function propagate_error
,
see below).
The following kinds of errors can be generated by the endpoint:
Unix.Unix_error
) (1) (2)Netamqp_types.Decode
) (1) (2)Netamqp_types.Encode
) (1) (2)Netamqp_types.Protocol_is_not_supported
(1) (2)Netamqp_types.Timeout
: when a synchronous call times outNetamqp_types.Method_cannot_be_dispatched
: when the endpoint
finds a frame
that can be decoded but not be dispatched (no handler) (2)Netamqp_types.Unexpected_eof
(1) (2)Netamqp_types.Unexpected_frame
(1) (2)(2) = This error is not associated to a particular channel
The following codes should be used for injecting errors from outside:
Netamqp_types.Method_exception
: for all exceptions coming from the
serverNetamqp_types.Protocol_violation
: for all hard violations of the
protocol, especially those that lead to a shutdownNetamqp_types.Method_dropped
: when a synchronous call cannot
be continued because
the client is shut down, and no better error code existsval propagate_error : endpoint -> exn -> Netamqp_types.channel option -> unit
If the channel is None
, all possible handlers and engines receive
the exception. Otherwise, only the handlers and engines get it that
are connected with the given channel.
The engines and handlers receiving the exceptions:
announce_e
sync_c2s_e
listen_for_errors
).register_sync_s2c
and
register_async_s2c
). If these handlers need to be notified about
errors they should register an error listener.
The endpoint state is not modified.
val abort_and_propagate_error : endpoint -> exn -> unit
`Error
state. Also,
the passed exception is propagated unconditionally.val listen_for_errors : endpoint ->
Netamqp_types.channel option -> (exn -> bool) -> unit
The callback function must return true
to remain active; otherwise
the listener is disabled.
val create_method_exception : protocol ->
class_id:int -> meth_id:int -> reply_code:int -> reply_text:string -> exn
Method_exception
val tls_session_props : endpoint -> Nettls_support.tls_session_props option
module Debug:sig
..end