Skip to content

Commit 3120445

Browse files
author
Emile Joubert
committed
Replace URI with hostname and port in WCF
1 parent e14662f commit 3120445

File tree

11 files changed

+191
-84
lines changed

11 files changed

+191
-84
lines changed

docs/RabbitMQ Service Model.doc

22.5 KB
Binary file not shown.

docs/RabbitMQ Service Model.docx

-17.8 KB
Binary file not shown.

docs/RabbitMQ Service Model.pdf

4.79 KB
Binary file not shown.

projects/examples/wcf/Test/App.config

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
<bindings>
4343
<rabbitMQBinding>
4444
<binding
45-
name="rabbitMQConfig"
46-
broker="amqp://localhost:5672/"
45+
name="rabbitMQConfig"
46+
hostname="localhost"
47+
port="5672"
4748
protocolversion="AMQP_0_9_1" />
4849
</rabbitMQBinding>
4950
</bindings>
5051
</system.serviceModel>
5152

5253
<appSettings>
53-
<add key="manual-test-broker-uri" value="amqp://localhost:5672/"/>
54+
<add key="manual-test-broker-hostname" value="localhost"/>
55+
<add key="manual-test-broker-port" value="5672"/>
5456
<add key="manual-test-broker-protocol" value="AMQP_0_9_1"/>
5557
</appSettings>
5658
</configuration>

projects/examples/wcf/Test/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ class Program
5353
{
5454
public static Binding GetBinding() {
5555
//return new WSHttpBinding();
56-
57-
return new RabbitMQBinding(System.Configuration.ConfigurationManager.AppSettings["manual-test-broker-uri"],
56+
57+
return new RabbitMQBinding(System.Configuration.ConfigurationManager.AppSettings["manual-test-broker-hostname"],
58+
int.Parse(System.Configuration.ConfigurationManager.AppSettings["manual-test-broker-port"]),
5859
RabbitMQ.Client.Protocols.FromConfiguration("manual-test-broker-protocol"));
5960
}
6061

projects/examples/wcf/configDemo/Client/App.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<rabbitMQBinding>
1515
<binding name="rabbitMQConfig"
1616
protocolversion="AMQP_0_9_1"
17-
broker="amqp://localhost:5672/" />
17+
hostname="localhost"
18+
port="5672" />
1819
</rabbitMQBinding>
1920
</bindings>
2021

projects/examples/wcf/configDemo/Server/App.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
<bindings>
2121
<rabbitMQBinding>
2222
<binding name="rabbitMQConfig"
23-
broker="amqp://localhost:5672/"
24-
protocolversion="AMQP_0_9_1"
25-
oneWay="false"/>
23+
hostname="localhost"
24+
port="5672"
25+
protocolversion="AMQP_0_9_1"
26+
oneWay="false"/>
2627
</rabbitMQBinding>
2728
</bindings>
2829

projects/wcf/RabbitMQ.ServiceModel/src/serviceModel/RabbitMQBinding.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ namespace RabbitMQ.ServiceModel
5454
/// </summary>
5555
public sealed class RabbitMQBinding : Binding
5656
{
57-
private Uri m_broker;
57+
private String m_host;
58+
private int m_port;
5859
private IProtocol m_brokerProtocol;
5960
private CompositeDuplexBindingElement m_compositeDuplex;
6061
private MessageEncodingBindingElement m_encoding;
@@ -79,19 +80,21 @@ public RabbitMQBinding()
7980
/// Uri.
8081
/// </summary>
8182
/// <param name="broker">The address of the broker to connect to</param>
82-
public RabbitMQBinding(Uri broker)
83-
: this(broker, Protocols.DefaultProtocol)
83+
public RabbitMQBinding(String hostname, int port)
84+
: this(hostname, port, Protocols.DefaultProtocol)
8485
{ }
8586

8687
/// <summary>
8788
/// Uses the broker and protocol specified
8889
/// </summary>
89-
/// <param name="broker">The address of the broker to connect to</param>
90+
/// <param name="hostname">The hostname of the broker to connect to</param>
91+
/// <param name="port">The port of the broker to connect to</param>
9092
/// <param name="protocol">The protocol version to use</param>
91-
public RabbitMQBinding(Uri broker, IProtocol protocol)
93+
public RabbitMQBinding(String hostname, int port, IProtocol protocol)
9294
: this(protocol)
9395
{
94-
this.Broker = broker;
96+
this.HostName = hostname;
97+
this.Port = port;
9598
}
9699

97100
/// <summary>
@@ -109,26 +112,10 @@ public RabbitMQBinding(IProtocol protocol)
109112
this.TransactionFlow = true;
110113
}
111114

112-
/// <summary>
113-
/// Uses the default protocol and the broker whose address is specified.
114-
/// </summary>
115-
/// <param name="brokerUri">The address of the broker to connect to</param>
116-
public RabbitMQBinding(string brokerUri)
117-
: this(new Uri(brokerUri))
118-
{ }
119-
120-
/// <summary>
121-
/// Uses the broker and protocol specified
122-
/// </summary>
123-
/// <param name="brokerUri">The address of the broker to connect to</param>
124-
/// <param name="protocol">The protocol version to use</param>
125-
public RabbitMQBinding(string brokerUri, IProtocol protocol)
126-
: this(new Uri(brokerUri), protocol)
127-
{ }
128-
129115
public override BindingElementCollection CreateBindingElements()
130116
{
131-
m_transport.Broker = this.Broker;
117+
m_transport.HostName = this.HostName;
118+
m_transport.Port = this.Port;
132119
m_transport.BrokerProtocol = this.BrokerProtocol;
133120
BindingElementCollection elements = new BindingElementCollection();
134121

@@ -173,13 +160,23 @@ public override string Scheme
173160
}
174161

175162
/// <summary>
176-
/// Specifies the broker that the binding should connect to.
163+
/// Specifies the hostname of the RabbitMQ Server
164+
/// </summary>
165+
[ConfigurationProperty("hostname")]
166+
public String HostName
167+
{
168+
get { return m_host; }
169+
set { m_host = value; }
170+
}
171+
172+
/// <summary>
173+
/// Specifies the RabbitMQ Server port
177174
/// </summary>
178-
[ConfigurationProperty("broker")]
179-
public Uri Broker
175+
[ConfigurationProperty("port")]
176+
public int Port
180177
{
181-
get { return m_broker; }
182-
set { m_broker = value; }
178+
get { return m_port; }
179+
set { m_port = value; }
183180
}
184181

185182
/// <summary>

projects/wcf/RabbitMQ.ServiceModel/src/serviceModel/RabbitMQBindingConfigurationElement.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ protected override void InitializeFrom(Binding binding)
8181
RabbitMQBinding rabbind = binding as RabbitMQBinding;
8282
if (rabbind != null)
8383
{
84-
this.Broker = rabbind.Broker;
84+
this.HostName = rabbind.HostName;
85+
this.Port = rabbind.Port;
8586
this.OneWayOnly = rabbind.OneWayOnly;
8687
this.TransactionFlowEnabled = rabbind.TransactionFlow;
8788
this.VirtualHost = rabbind.Transport.ConnectionFactory.VirtualHost;
@@ -104,7 +105,8 @@ protected override void OnApplyConfiguration(Binding binding)
104105
binding.GetType().AssemblyQualifiedName));
105106
}
106107

107-
rabbind.Broker = this.Broker;
108+
rabbind.HostName = this.HostName;
109+
rabbind.Port = this.Port;
108110
rabbind.BrokerProtocol = this.Protocol;
109111
rabbind.OneWayOnly = this.OneWayOnly;
110112
rabbind.TransactionFlow = this.TransactionFlowEnabled;
@@ -114,13 +116,23 @@ protected override void OnApplyConfiguration(Binding binding)
114116
}
115117

116118
/// <summary>
117-
/// Specifies the broker that the binding should connect to.
119+
/// Specifies the hostname of the broker that the binding should connect to.
118120
/// </summary>
119-
[ConfigurationProperty("broker", IsRequired=true)]
120-
public Uri Broker
121+
[ConfigurationProperty("hostname", IsRequired = true)]
122+
public String HostName
121123
{
122-
get { return ((Uri)base["broker"]); }
123-
set { base["broker"] = value; }
124+
get { return ((String)base["hostname"]); }
125+
set { base["hostname"] = value; }
126+
}
127+
128+
/// <summary>
129+
/// Specifies the port of the broker that the binding should connect to.
130+
/// </summary>
131+
[ConfigurationProperty("port", DefaultValue = AmqpTcpEndpoint.UseDefaultPort)]
132+
public int Port
133+
{
134+
get { return ((int)base["port"]); }
135+
set { base["port"] = value; }
124136
}
125137

126138
/// <summary>

0 commit comments

Comments
 (0)