Permalink
Browse files

Pedrams AMQP Client patch.

  • Loading branch information...
1 parent 7b2e9a5 commit 99820e6279214b836548b29a050735996740018d @jlouis jlouis committed Feb 2, 2013
Showing with 26 additions and 12 deletions.
  1. +2 −2 include/amqp_client.hrl
  2. +1 −1 src/amqp_client.app.src
  3. +19 −5 src/amqp_connection.erl
  4. +4 −4 src/amqp_direct_connection.erl
@@ -45,9 +45,9 @@
adapter_info = none,
client_properties = []}).
--record(amqp_adapter_info, {address = unknown,
+-record(amqp_adapter_info, {host = unknown,
port = unknown,
- peer_address = unknown,
+ peer_host = unknown,
peer_port = unknown,
name = unknown,
protocol = unknown,
@@ -3,6 +3,6 @@
{vsn, "3.0.0"},
{modules, []},
{registered, []},
- {env, []},
+ {env,[{prefer_ipv6,false}]},
{mod, {amqp_client, []}},
{applications, [kernel, stdlib]}]}.
@@ -147,11 +147,7 @@
%% the default ports will be selected depending on whether this is a
%% normal or an SSL connection.
start(AmqpParams) ->
- case amqp_client:start() of
- ok -> ok;
- {error, {already_started, amqp_client}} -> ok;
- {error, _} = E -> throw(E)
- end,
+ ensure_started(),
AmqpParams1 =
case AmqpParams of
#amqp_params_network{port = undefined, ssl_options = none} ->
@@ -164,6 +160,24 @@ start(AmqpParams) ->
{ok, _Sup, Connection} = amqp_sup:start_connection_sup(AmqpParams1),
amqp_gen_connection:connect(Connection).
+%% Usually the amqp_client application will already be running. We
+%% check whether that is the case by invoking an undocumented function
+%% which does not require a synchronous call to the application
+%% controller. That way we don't risk a dead-lock if, say, the
+%% application controller is in the process of shutting down the very
+%% application which is making this call.
+ensure_started() ->
+ case application_controller:get_master(amqp_client) of
+ undefined ->
+ case amqp_client:start() of
+ ok -> ok;
+ {error, {already_started, amqp_client}} -> ok;
+ {error, _} = E -> throw(E)
+ end;
+ _ ->
+ ok
+ end.
+
%%---------------------------------------------------------------------------
%% Commands
%%---------------------------------------------------------------------------
@@ -37,8 +37,8 @@
-define(INFO_KEYS, [type]).
--define(CREATION_EVENT_KEYS, [pid, protocol, address, port, name,
- peer_address, peer_port,
+-define(CREATION_EVENT_KEYS, [pid, protocol, host, port, name,
+ peer_host, peer_port,
user, vhost, client_properties, type]).
%%---------------------------------------------------------------------------
@@ -96,9 +96,9 @@ i(client_properties, #state{params = P}) ->
P#amqp_params_direct.client_properties;
%% Optional adapter info
i(protocol, #state{adapter_info = I}) -> I#amqp_adapter_info.protocol;
-i(address, #state{adapter_info = I}) -> I#amqp_adapter_info.address;
+i(host, #state{adapter_info = I}) -> I#amqp_adapter_info.host;
i(port, #state{adapter_info = I}) -> I#amqp_adapter_info.port;
-i(peer_address, #state{adapter_info = I}) -> I#amqp_adapter_info.peer_address;
+i(peer_host, #state{adapter_info = I}) -> I#amqp_adapter_info.peer_host;
i(peer_port, #state{adapter_info = I}) -> I#amqp_adapter_info.peer_port;
i(name, #state{adapter_info = I}) -> I#amqp_adapter_info.name;

0 comments on commit 99820e6

Please sign in to comment.