Skip to content

Commit 2ea460d

Browse files
author
Alexandru Scvortov
committed
support amqps scheme + update example docs
We need to ignore RemoteCertificateNameMismatches because the server name may not also be it's network name (and it's also Java's default behaviour). We still need to set ServerName, though; the ssl connect function needs it.
1 parent cc26536 commit 2ea460d

File tree

14 files changed

+22
-14
lines changed

14 files changed

+22
-14
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
@@ -41,6 +41,7 @@
4141
using System;
4242
using System.IO;
4343
using System.Net;
44+
using System.Net.Security;
4445
using System.Net.Sockets;
4546
using System.Collections;
4647

@@ -181,14 +182,21 @@ public String Uri
181182

182183
Uri uri = new Uri(value, UriKind.Absolute);
183184

184-
if ("amqp".CompareTo(uri.Scheme) != 0) {
185+
if ("amqp".CompareTo(uri.Scheme.ToLower()) == 0) {
186+
// nothing special to do
187+
} else if ("amqps".CompareTo(uri.Scheme.ToLower()) == 0) {
188+
Ssl.Enabled = true;
189+
Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch;
190+
Port = AmqpTcpEndpoint.DefaultAmqpSslPort;
191+
} else {
185192
throw new ArgumentException("Wrong scheme in AMQP URI: " +
186193
value);
187194
}
188195
string host = uri.Host;
189196
if (!String.IsNullOrEmpty(host)) {
190197
HostName = host;
191198
}
199+
Ssl.ServerName = HostName;
192200

193201
int port = uri.Port;
194202
if (port != -1) {

projects/client/Unit/src/unit/TestAmqpUri.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void ParseFail(string uri)
144144
ConnectionFactory cf = new ConnectionFactory();
145145
cf.Uri = uri;
146146
Assert.Fail("URI parse didn't fail: '" + uri + "'");
147-
} catch (Exception e) {
147+
} catch (Exception) {
148148
// whoosh!
149149
}
150150
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace RabbitMQ.Client.Examples {
5050
public class AddClient {
5151
public static int Main(string[] args) {
5252
if (args.Length < 1) {
53-
Console.Error.WriteLine("Usage: AddClient <hostname>[:<portnumber>] [<number> ...]");
53+
Console.Error.WriteLine("Usage: AddClient <uri> [<number> ...]");
5454
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5555
return 2;
5656
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace RabbitMQ.Client.Examples {
5151
public class AddServer: SimpleRpcServer {
5252
public static int Main(string[] args) {
5353
if (args.Length < 1) {
54-
Console.Error.WriteLine("Usage: AddServer <hostname>[:<portnumber>]");
54+
Console.Error.WriteLine("Usage: AddServer <uri>");
5555
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5656
return 2;
5757
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static int Main(string[] args) {
7272
if (((args.Length - optionIndex) < 2) ||
7373
(((args.Length - optionIndex) % 2) != 0))
7474
{
75-
Console.Error.WriteLine("Usage: DeclareQueue [<option> ...] <hostname>[:<portnumber>] <queue> [<exchange> <routingkey>] ...");
75+
Console.Error.WriteLine("Usage: DeclareQueue [<option> ...] <uri> <queue> [<exchange> <routingkey>] ...");
7676
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
7777
Console.Error.WriteLine("Available options:");
7878
Console.Error.WriteLine(" /durable declare a durable queue");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ExceptionTest {
5252
public static int Main(string[] args) {
5353
try {
5454
if (args.Length < 1) {
55-
Console.Error.WriteLine("Usage: ExceptionTest <hostname>[:<portnumber>]");
55+
Console.Error.WriteLine("Usage: ExceptionTest <uri>");
5656
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5757
return 2;
5858
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace RabbitMQ.Client.Examples {
5252
public class LogTail {
5353
public static int Main(string[] args) {
5454
if (args.Length < 4) {
55-
Console.Error.WriteLine("Usage: LogTail <hostname>[:<portnumber>] <exchange> <exchangetype> <routingkey>");
55+
Console.Error.WriteLine("Usage: LogTail <uri> <exchange> <exchangetype> <routingkey>");
5656
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5757
Console.Error.WriteLine("If the exchange name is the empty string, will instead declare a queue named");
5858
Console.Error.WriteLine("by the routingkey, and consume from that queue.");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace RabbitMQ.Client.Examples {
5252
public class LowlevelLogTail {
5353
public static int Main(string[] args) {
5454
if (args.Length < 4) {
55-
Console.Error.WriteLine("Usage: LowlevelLogTail <hostname>[:<portnumber>] <exchange> <exchangetype> <routingkey>");
55+
Console.Error.WriteLine("Usage: LowlevelLogTail <uri> <exchange> <exchangetype> <routingkey>");
5656
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5757
Console.Error.WriteLine("If the exchange name is the empty string, will instead declare a queue named");
5858
Console.Error.WriteLine("by the routingkey, and consume from that queue.");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class PerfTest {
5151

5252
public static int Main(string[] args) {
5353
if (args.Length < 2) {
54-
Console.Error.WriteLine("Usage: PerfTest <hostname>[:<portnumber>] <number of messages>");
54+
Console.Error.WriteLine("Usage: PerfTest <uri> <number of messages>");
5555
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5656
return 2;
5757
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace RabbitMQ.Client.Examples {
4747
public class SendString {
4848
public static int Main(string[] args) {
4949
if (args.Length < 5) {
50-
Console.Error.WriteLine("Usage: SendString <hostname>[:<portnumber>] <exchange> <exchangetype> <routingkey> <message>");
50+
Console.Error.WriteLine("Usage: SendString <uri> <exchange> <exchangetype> <routingkey> <message>");
5151
Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
5252
return 2;
5353
}

0 commit comments

Comments
 (0)