Skip to content

Commit 90332e1

Browse files
author
David R. MacIver
committed
fix examples
1 parent 6f60040 commit 90332e1

File tree

13 files changed

+94
-52
lines changed

13 files changed

+94
-52
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public class ConnectionFactory
157157
///<summary>The AMQP protocol to be used</summary>
158158
public IProtocol Protocol = Protocols.FromEnvironment();
159159

160-
161160
public AmqpTcpEndpoint Endpoint
162161
{
163162
get
@@ -172,6 +171,23 @@ public AmqpTcpEndpoint Endpoint
172171
}
173172
}
174173

174+
public String Address
175+
{
176+
get
177+
{
178+
String result = HostName;
179+
if(Port != AmqpTcpEndpoint.UseDefaultPort)
180+
{
181+
result += (":" + Port);
182+
}
183+
return result;
184+
}
185+
set
186+
{
187+
Endpoint = AmqpTcpEndpoint.Parse(Protocol, value);
188+
}
189+
}
190+
175191
///<summary>Construct a fresh instance, with all fields set to
176192
///their respective defaults.</summary>
177193
public ConnectionFactory() { }

projects/examples/client/AddClient/src/examples/AddClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ public static int Main(string[] args) {
7070
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
7171
return 2;
7272
}
73-
74-
using (IConnection conn = new ConnectionFactory().CreateConnection(args[0])) {
73+
74+
ConnectionFactory cf = new ConnectionFactory();
75+
cf.Address = args[0];
76+
77+
using (IConnection conn = cf.CreateConnection()) {
7578
using (IModel ch = conn.CreateModel()) {
7679

7780
object[] addends = new object[args.Length - 1];

projects/examples/client/AddServer/src/examples/AddServer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public static int Main(string[] args) {
7272
return 2;
7373
}
7474

75-
using (IConnection conn = new ConnectionFactory().CreateConnection(args[0])) {
75+
ConnectionFactory cf = new ConnectionFactory();
76+
cf.Address = args[0];
77+
using (IConnection conn = cf.CreateConnection()) {
7678
using (IModel ch = conn.CreateModel()) {
7779
Subscription sub = new Subscription(ch, "AddServer");
7880
new AddServer(sub).MainLoop();

projects/examples/client/DeclareQueue/src/examples/DeclareQueue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ public static int Main(string[] args) {
9999

100100
string serverAddress = args[optionIndex++];
101101
string inputQueueName = args[optionIndex++];
102+
ConnectionFactory cf = new ConnectionFactory();
103+
cf.Address = serverAddress;
102104

103-
using (IConnection conn = new ConnectionFactory().CreateConnection(serverAddress))
105+
using (IConnection conn = cf.CreateConnection())
104106
{
105107
using (IModel ch = conn.CreateModel()) {
106108

projects/examples/client/ExceptionTest/src/examples/ExceptionTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ public static int Main(string[] args) {
7474
}
7575

7676
string serverAddress = args[0];
77+
ConnectionFactory cf = new ConnectionFactory();
78+
cf.Address = serverAddress;
7779

78-
using (IConnection conn = new ConnectionFactory().CreateConnection(serverAddress))
80+
using (IConnection conn = cf.CreateConnection())
7981
{
8082
conn.ConnectionShutdown += new ConnectionShutdownEventHandler(First);
8183
conn.ConnectionShutdown += new ConnectionShutdownEventHandler(OnConnectionShutdown);

projects/examples/client/LogTail/src/examples/LogTail.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ public static int Main(string[] args) {
7979
string exchange = args[1];
8080
string exchangeType = args[2];
8181
string routingKey = args[3];
82-
83-
using (IConnection conn = new ConnectionFactory().CreateConnection(serverAddress))
82+
83+
ConnectionFactory cf = new ConnectionFactory();
84+
cf.Address = serverAddress;
85+
86+
using (IConnection conn = cf.CreateConnection())
8487
{
8588
using (IModel ch = conn.CreateModel()) {
8689
Subscription sub;

projects/examples/client/LowlevelLogTail/src/examples/LowlevelLogTail.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ public static int Main(string[] args) {
8080
string exchange = args[1];
8181
string exchangeType = args[2];
8282
string routingKey = args[3];
83-
84-
using (IConnection conn = new ConnectionFactory().CreateConnection(serverAddress))
83+
84+
ConnectionFactory cf = new ConnectionFactory();
85+
cf.Address = serverAddress;
86+
using (IConnection conn = cf.CreateConnection())
8587
{
8688
using (IModel ch = conn.CreateModel())
8789
{

projects/examples/client/PerfTest/src/examples/PerfTest.cs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,48 +74,49 @@ public static int Main(string[] args) {
7474

7575
string serverAddress = args[0];
7676
int messageCount = int.Parse(args[1]);
77-
78-
using (IConnection conn =
79-
new ConnectionFactory().CreateConnection(serverAddress))
80-
{
81-
Stopwatch sendTimer = new Stopwatch();
82-
Stopwatch receiveTimer = new Stopwatch();
83-
84-
using (IModel ch = conn.CreateModel()) {
85-
sendTimer.Start();
86-
87-
for (int i = 0; i < messageCount; ++i) {
88-
ch.BasicPublish("", "", null, Message);
89-
}
77+
78+
ConnectionFactory cf = new ConnectionFactory();
79+
cf.Address = serverAddress;
80+
using (IConnection conn = cf.CreateConnection())
81+
{
82+
Stopwatch sendTimer = new Stopwatch();
83+
Stopwatch receiveTimer = new Stopwatch();
84+
85+
using (IModel ch = conn.CreateModel()) {
86+
sendTimer.Start();
87+
88+
for (int i = 0; i < messageCount; ++i) {
89+
ch.BasicPublish("", "", null, Message);
9090
}
91-
sendTimer.Stop();
91+
}
92+
sendTimer.Stop();
9293

93-
using (IModel ch = conn.CreateModel()) {
94-
string q = ch.QueueDeclare();
95-
96-
for (int i = 0; i < messageCount + 1; ++i) {
97-
ch.BasicPublish("", q, null, Message);
98-
}
99-
//This ensures that all messages have been enqueued
100-
ch.BasicGet(q, true);
94+
using (IModel ch = conn.CreateModel()) {
95+
string q = ch.QueueDeclare();
96+
97+
for (int i = 0; i < messageCount + 1; ++i) {
98+
ch.BasicPublish("", q, null, Message);
99+
}
100+
//This ensures that all messages have been enqueued
101+
ch.BasicGet(q, true);
101102

102-
QueueingBasicConsumer consumer =
103-
new QueueingBasicConsumer(ch);
104-
receiveTimer.Start();
105-
ch.BasicConsume(q, true, null, consumer);
106-
107-
for (int i = 0; i < messageCount; ++i) {
108-
consumer.Queue.Dequeue();
109-
}
110-
receiveTimer.Stop();
103+
QueueingBasicConsumer consumer =
104+
new QueueingBasicConsumer(ch);
105+
receiveTimer.Start();
106+
ch.BasicConsume(q, true, null, consumer);
107+
108+
for (int i = 0; i < messageCount; ++i) {
109+
consumer.Queue.Dequeue();
111110
}
111+
receiveTimer.Stop();
112+
}
112113

113-
Console.WriteLine("Performance Test Completed");
114-
Console.WriteLine("Send: {0}Hz", ToHertz(sendTimer.ElapsedMilliseconds, messageCount));
115-
Console.WriteLine("Receive: {0}Hz", ToHertz(receiveTimer.ElapsedMilliseconds, messageCount));
114+
Console.WriteLine("Performance Test Completed");
115+
Console.WriteLine("Send: {0}Hz", ToHertz(sendTimer.ElapsedMilliseconds, messageCount));
116+
Console.WriteLine("Receive: {0}Hz", ToHertz(receiveTimer.ElapsedMilliseconds, messageCount));
116117

117-
return 0;
118-
}
118+
return 0;
119+
}
119120
}
120121

121122
private static double ToHertz(long milliseconds, int messageCount) {

projects/examples/client/SendMap/src/examples/SendMap.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ public static int Main(string[] args) {
111111
exchange = "";
112112
}
113113

114-
using (IConnection conn = new ConnectionFactory().CreateConnection(uri))
114+
ConnectionFactory cf = new ConnectionFactory();
115+
cf.Endpoint = new AmqpTcpEndpoint(uri);
116+
117+
using (IConnection conn = cf.CreateConnection())
115118
{
116119
using (IModel ch = conn.CreateModel()) {
117120

projects/examples/client/SendString/src/examples/SendString.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public static int Main(string[] args) {
7474
string routingKey = args[3];
7575
string message = args[4];
7676

77-
using (IConnection conn = new ConnectionFactory().CreateConnection(serverAddress))
77+
ConnectionFactory cf = new ConnectionFactory();
78+
cf.Address = serverAddress;
79+
80+
using (IConnection conn = cf.CreateConnection())
7881
{
7982
using (IModel ch = conn.CreateModel()) {
8083

0 commit comments

Comments
 (0)