Skip to content

Commit 7118742

Browse files
author
Vlad Ionescu
committed
additional client properties can now be specified via ConnectionFactory.ClientProperties
1 parent bd6a1c3 commit 7118742

File tree

4 files changed

+35
-178
lines changed

4 files changed

+35
-178
lines changed

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace RabbitMQ.Client
8080
/// factory.VirtualHost = ConnectionFactory.DefaultVHost;
8181
/// factory.Protocol = Protocols.FromEnvironment();
8282
/// factory.HostName = hostName;
83-
// factory.PortNumber = AmqpTcpEndpoint.UseDefaultPort;
83+
/// factory.PortNumber = AmqpTcpEndpoint.UseDefaultPort;
8484
/// //
8585
/// IConnection conn = factory.CreateConnection();
8686
/// //
@@ -126,6 +126,10 @@ public class ConnectionFactory
126126
/// seconds, with zero meaning none (value: 0)</summary>
127127
public const ushort DefaultHeartbeat = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
128128

129+
/// <summary>Default value for extra client properties to be sent to
130+
/// the server (value: empty Hashtable)
131+
public static readonly IDictionary DefaultClientProperties = new Hashtable(); // PLEASE KEEP THIS MATCHING THE DOC ABOVE
132+
129133
/// <summary>Username to use when authenticating to the server</summary>
130134
public string UserName = DefaultUser;
131135

@@ -144,6 +148,10 @@ public class ConnectionFactory
144148
/// <summary>Heartbeat setting to request (in seconds)</summary>
145149
public ushort RequestedHeartbeat = DefaultHeartbeat;
146150

151+
/// <summary>Dictionary of extra client properties to be sent to the
152+
/// server</summary>
153+
public IDictionary ClientProperties = DefaultClientProperties;
154+
147155
///<summary>Ssl options setting</summary>
148156
public SslOption Ssl = new SslOption();
149157

projects/client/RabbitMQ.Client/src/client/api/ConnectionParameters.cs

Lines changed: 0 additions & 173 deletions
This file was deleted.

projects/client/RabbitMQ.Client/src/client/api/IConnection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public interface IConnection: IDisposable
116116
///(0 for disabled), in seconds.</summary>
117117
ushort Heartbeat { get; }
118118

119+
///<summary>The client properties that has been sent to the
120+
///server.</summary>
121+
IDictionary ClientProperties { get; }
122+
119123
///<summary>Returns the known hosts that came back from the
120124
///broker in the connection.open-ok method at connection
121125
///startup time. Null until the connection is completely open

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public abstract class ConnectionBase : IConnection
9393
public IFrameHandler m_frameHandler;
9494
public uint m_frameMax = 0;
9595
public ushort m_heartbeat = 0;
96+
public IDictionary m_clientProperties;
9697
public AmqpTcpEndpoint[] m_knownHosts = null;
9798

9899
public MainSession m_session0;
@@ -250,6 +251,18 @@ public ushort Heartbeat
250251
}
251252
}
252253

254+
public IDictionary ClientProperties
255+
{
256+
get
257+
{
258+
return m_clientProperties;
259+
}
260+
set
261+
{
262+
m_clientProperties = value;
263+
}
264+
}
265+
253266
public AmqpTcpEndpoint[] KnownHosts
254267
{
255268
get { return m_knownHosts; }
@@ -896,9 +909,12 @@ public void OnCallbackException(CallbackExceptionEventArgs args)
896909
}
897910
}
898911

899-
public IDictionary BuildClientPropertiesTable()
912+
private static IDictionary BuildClientPropertiesTable(
913+
IDictionary extraClientProperties)
900914
{
901-
string version = this.GetType().Assembly.GetName().Version.ToString();
915+
System.Reflection.Assembly assembly =
916+
System.Reflection.Assembly.GetAssembly(typeof(ConnectionBase));
917+
string version = assembly.GetName().Version.ToString();
902918
//TODO: Get the rest of this data from the Assembly Attributes
903919
Hashtable table = new Hashtable();
904920
table["product"] = Encoding.UTF8.GetBytes("RabbitMQ");
@@ -910,7 +926,7 @@ public IDictionary BuildClientPropertiesTable()
910926
table["information"] = Encoding.UTF8.GetBytes("Licensed under the MPL. " +
911927
"See http://www.rabbitmq.com/");
912928

913-
foreach(DictionaryEntry de in Parameters.ClientProperties)
929+
foreach(DictionaryEntry de in extraClientProperties)
914930
table[de.Key] = de.Value;
915931

916932
return table;
@@ -957,10 +973,12 @@ public void Open(bool insist)
957973
serverVersion.Minor);
958974
}
959975

976+
ClientProperties = BuildClientPropertiesTable(m_factory.ClientProperties);
977+
960978
// FIXME: check that PLAIN is supported.
961979
// FIXME: parse out locales properly!
962980
ConnectionTuneDetails connectionTune =
963-
m_model0.ConnectionStartOk(BuildClientPropertiesTable(),
981+
m_model0.ConnectionStartOk(ClientProperties,
964982
"PLAIN",
965983
Encoding.UTF8.GetBytes("\0" + m_factory.UserName +
966984
"\0" + m_factory.Password),

0 commit comments

Comments
 (0)