diff --git a/src/amqp_auth_mechanisms.erl b/src/amqp_auth_mechanisms.erl index 56b3a062..767b6c1e 100644 --- a/src/amqp_auth_mechanisms.erl +++ b/src/amqp_auth_mechanisms.erl @@ -19,7 +19,7 @@ -include("amqp_client.hrl"). --export([plain/3, amqplain/3, external/3]). +-export([plain/3, amqplain/3, external/3, crdemo/3]). %%--------------------------------------------------------------------------- @@ -41,3 +41,11 @@ external(none, _, init) -> {<<"EXTERNAL">>, []}; external(none, _, _State) -> {<<"">>, _State}. + +crdemo(none, _, init) -> + {<<"RABBIT-CR-DEMO">>, 0}; +crdemo(none, #amqp_params_network{username = Username}, 0) -> + {Username, 1}; +crdemo(<<"Please tell me your password">>, + #amqp_params_network{password = Password}, 1) -> + {<<"My password is ", Password/binary>>, 2}. diff --git a/src/amqp_network_connection.erl b/src/amqp_network_connection.erl index 3200d7a2..20296cc9 100644 --- a/src/amqp_network_connection.erl +++ b/src/amqp_network_connection.erl @@ -289,6 +289,8 @@ handshake_recv(Expecting) -> case {Expecting, element(1, Method)} of {E, M} when E =:= M -> Method; + {'connection.tune', 'connection.secure'} -> + Method; {'connection.open_ok', _} -> {closing, #amqp_error{name = command_invalid, diff --git a/src/amqp_rpc_client.erl b/src/amqp_rpc_client.erl index e3ea8d2f..40fcbefb 100644 --- a/src/amqp_rpc_client.erl +++ b/src/amqp_rpc_client.erl @@ -25,7 +25,7 @@ -behaviour(gen_server). --export([start/2, stop/1]). +-export([start/2, start_link/2, stop/1]). -export([call/2]). -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). @@ -53,6 +53,18 @@ start(Connection, Queue) -> {ok, Pid} = gen_server:start(?MODULE, [Connection, Queue], []), Pid. +%% @spec (Connection, Queue) -> RpcClient +%% where +%% Connection = pid() +%% Queue = binary() +%% RpcClient = pid() +%% @doc Starts, and links to, a new RPC client instance that sends requests +%% to a specified queue. This function returns the pid of the RPC client +%% process that can be used to invoke RPCs and stop the client. +start_link(Connection, Queue) -> + {ok, Pid} = gen_server:start_link(?MODULE, [Connection, Queue], []), + Pid. + %% @spec (RpcClient) -> ok %% where %% RpcClient = pid() diff --git a/src/amqp_rpc_server.erl b/src/amqp_rpc_server.erl index a9b7353d..3ce6a313 100644 --- a/src/amqp_rpc_server.erl +++ b/src/amqp_rpc_server.erl @@ -27,7 +27,7 @@ -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). --export([start/3]). +-export([start/3, start_link/3]). -export([stop/1]). -record(state, {channel, @@ -51,6 +51,20 @@ start(Connection, Queue, Fun) -> {ok, Pid} = gen_server:start(?MODULE, [Connection, Queue, Fun], []), Pid. +%% @spec (Connection, Queue, RpcHandler) -> RpcServer +%% where +%% Connection = pid() +%% Queue = binary() +%% RpcHandler = function() +%% RpcServer = pid() +%% @doc Starts, and links to, a new RPC server instance that receives +%% requests via a specified queue and dispatches them to a specified +%% handler function. This function returns the pid of the RPC server that +%% can be used to stop the server. +start_link(Connection, Queue, Fun) -> + {ok, Pid} = gen_server:start_link(?MODULE, [Connection, Queue, Fun], []), + Pid. + %% @spec (RpcServer) -> ok %% where %% RpcServer = pid()