Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Normalizing line endings

- Updating .gitignore to include bin dir in tools directory (by scoping
bin ignore to src/**/[Bb]in
- Adding .gitattributes
- Normalizing line endings
  • Loading branch information...
commit cf5bc3f67ee889977d41e7f6d57b19df3be71c77 1 parent a54f1bc
@joefitzgerald joefitzgerald authored
Showing with 20,885 additions and 3,427 deletions.
  1. +22 −0 .gitattributes
  2. +2 −2 .gitignore
  3. +1 −1  doc/docx/Spring.Messaging.Amqp-1.0/.gitignore
  4. +1 −1  doc/reference/.gitignore
  5. +2 −2 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/.gitignore
  6. +33 −33 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/Program.cs
  7. +36 −36 ...s/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/Properties/AssemblyInfo.cs
  8. +17 −17 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/app.config
  9. +67 −67 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Client/Program.cs
  10. +66 −66 ...ples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Server/Gateways/MarketDataServiceGateway.cs
  11. +37 −37 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Server/Program.cs
  12. +216 −216 src/Spring.Messaging.Amqp.Rabbit.Admin/Admin/QueueInfo.cs
  13. +1 −1  src/Spring.Messaging.Amqp.Rabbit/.gitignore
  14. +234 −234 src/Spring.Messaging.Amqp.Rabbit/Connection/AbstractConnectionFactory.cs
  15. +66 −66 src/Spring.Messaging.Amqp.Rabbit/Connection/CompositeConnectionListener.cs
  16. +531 −531 src/Spring.Messaging.Amqp.Rabbit/Core/RabbitAdmin.cs
  17. +791 −791 src/Spring.Messaging.Amqp.Rabbit/Core/RabbitTemplate.cs
  18. +881 −881 src/Spring.Messaging.Amqp.Rabbit/Listener/SimpleMessageListenerContainer.cs
  19. +94 −94 src/Spring.Messaging.Amqp/Core/Address.cs
  20. +160 −160 src/Spring.Messaging.Amqp/Core/Binding.cs
  21. +54 −54 src/Spring.Messaging.Amqp/Core/ExchangeType.cs
  22. +2 −2 test/Spring.Messaging.Amqp.Tests/.gitignore
  23. +99 −99 test/Spring.Messaging.Amqp.Tests/Core/AddressTests.cs
  24. +36 −36 test/Spring.Messaging.Amqp.Tests/Properties/AssemblyInfo.cs
  25. +277 −0 tools/NUnit/bin/NUnitFitTests.html
  26. +61 −0 tools/NUnit/bin/NUnitTests.VisualState.xml
  27. +45 −0 tools/NUnit/bin/NUnitTests.config
  28. +14 −0 tools/NUnit/bin/NUnitTests.nunit
  29. +4 −0 tools/NUnit/bin/agent.conf
  30. +18 −0 tools/NUnit/bin/agent.log.conf
  31. BIN  tools/NUnit/bin/framework/nunit.framework.dll
  32. +10,892 −0 tools/NUnit/bin/framework/nunit.framework.xml
  33. BIN  tools/NUnit/bin/framework/nunit.mocks.dll
  34. BIN  tools/NUnit/bin/framework/pnunit.framework.dll
  35. +18 −0 tools/NUnit/bin/launcher.log.conf
  36. BIN  tools/NUnit/bin/lib/Images/Ellipsis.gif
  37. BIN  tools/NUnit/bin/lib/Images/Tree/Circles/Failure.jpg
  38. BIN  tools/NUnit/bin/lib/Images/Tree/Circles/Ignored.jpg
  39. BIN  tools/NUnit/bin/lib/Images/Tree/Circles/Inconclusive.jpg
  40. BIN  tools/NUnit/bin/lib/Images/Tree/Circles/Skipped.jpg
  41. BIN  tools/NUnit/bin/lib/Images/Tree/Circles/Success.jpg
  42. BIN  tools/NUnit/bin/lib/Images/Tree/Classic/Failure.jpg
  43. BIN  tools/NUnit/bin/lib/Images/Tree/Classic/Ignored.jpg
  44. BIN  tools/NUnit/bin/lib/Images/Tree/Classic/Inconclusive.jpg
  45. BIN  tools/NUnit/bin/lib/Images/Tree/Classic/Skipped.jpg
  46. BIN  tools/NUnit/bin/lib/Images/Tree/Classic/Success.jpg
  47. BIN  tools/NUnit/bin/lib/Images/Tree/Default/Failure.png
  48. BIN  tools/NUnit/bin/lib/Images/Tree/Default/Ignored.png
  49. BIN  tools/NUnit/bin/lib/Images/Tree/Default/Inconclusive.png
  50. BIN  tools/NUnit/bin/lib/Images/Tree/Default/Skipped.png
  51. BIN  tools/NUnit/bin/lib/Images/Tree/Default/Success.png
  52. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/Failure.png
  53. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/Ignored.png
  54. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/Inconclusive.png
  55. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/SeriousWarning.png
  56. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/Skipped.png
  57. BIN  tools/NUnit/bin/lib/Images/Tree/Visual Studio/Success.png
  58. BIN  tools/NUnit/bin/lib/Images/pinned.gif
  59. BIN  tools/NUnit/bin/lib/Images/unpinned.gif
  60. BIN  tools/NUnit/bin/lib/NSubstitute.dll
  61. +259 −0 tools/NUnit/bin/lib/NSubstitute.xml
  62. BIN  tools/NUnit/bin/lib/Rhino.Mocks.dll
  63. +5,413 −0 tools/NUnit/bin/lib/Rhino.Mocks.xml
  64. BIN  tools/NUnit/bin/lib/log4net.dll
  65. BIN  tools/NUnit/bin/lib/nunit-console-runner.dll
  66. BIN  tools/NUnit/bin/lib/nunit-gui-runner.dll
  67. BIN  tools/NUnit/bin/lib/nunit.core.dll
  68. BIN  tools/NUnit/bin/lib/nunit.core.interfaces.dll
  69. BIN  tools/NUnit/bin/lib/nunit.uiexception.dll
  70. BIN  tools/NUnit/bin/lib/nunit.uikit.dll
  71. BIN  tools/NUnit/bin/lib/nunit.util.dll
  72. BIN  tools/NUnit/bin/nunit-agent-x86.exe
  73. +37 −0 tools/NUnit/bin/nunit-agent-x86.exe.config
  74. BIN  tools/NUnit/bin/nunit-agent.exe
  75. +37 −0 tools/NUnit/bin/nunit-agent.exe.config
  76. BIN  tools/NUnit/bin/nunit-console-x86.exe
  77. +31 −0 tools/NUnit/bin/nunit-console-x86.exe.config
  78. BIN  tools/NUnit/bin/nunit-console.exe
  79. +31 −0 tools/NUnit/bin/nunit-console.exe.config
  80. BIN  tools/NUnit/bin/nunit-editor.exe
  81. BIN  tools/NUnit/bin/nunit-x86.exe
  82. +30 −0 tools/NUnit/bin/nunit-x86.exe.config
  83. BIN  tools/NUnit/bin/nunit.exe
  84. +30 −0 tools/NUnit/bin/nunit.exe.config
  85. BIN  tools/NUnit/bin/nunit.framework.dll
  86. BIN  tools/NUnit/bin/pnunit-agent.exe
  87. +77 −0 tools/NUnit/bin/pnunit-agent.exe.config
  88. BIN  tools/NUnit/bin/pnunit-launcher.exe
  89. +77 −0 tools/NUnit/bin/pnunit-launcher.exe.config
  90. BIN  tools/NUnit/bin/pnunit.framework.dll
  91. BIN  tools/NUnit/bin/pnunit.tests.dll
  92. +3 −0  tools/NUnit/bin/runpnunit.bat
  93. +82 −0 tools/NUnit/bin/test.conf
  94. BIN  tools/NUnit/bin/tests/mock-assembly.dll
  95. BIN  tools/NUnit/bin/tests/nonamespace-assembly.dll
  96. BIN  tools/NUnit/bin/tests/nunit-console.tests.dll
  97. BIN  tools/NUnit/bin/tests/nunit-editor.tests.dll
  98. BIN  tools/NUnit/bin/tests/nunit-gui.tests.dll
  99. BIN  tools/NUnit/bin/tests/nunit.core.tests.dll
  100. BIN  tools/NUnit/bin/tests/nunit.framework.dll
  101. BIN  tools/NUnit/bin/tests/nunit.framework.tests.dll
  102. BIN  tools/NUnit/bin/tests/nunit.mocks.tests.dll
  103. BIN  tools/NUnit/bin/tests/nunit.uiexception.tests.dll
  104. BIN  tools/NUnit/bin/tests/nunit.uikit.tests.dll
  105. BIN  tools/NUnit/bin/tests/nunit.util.tests.dll
  106. BIN  tools/NUnit/bin/tests/test-assembly.dll
  107. BIN  tools/NUnit/bin/tests/test-utilities.dll
View
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
View
4 .gitignore
@@ -13,7 +13,7 @@
*.log
*.[Cc]ache
[Oo]bj
-[Bb]in
+src/**/[Bb]in
[Dd]ebug*/
[Rr]elease*/
@@ -29,4 +29,4 @@ log.txt*
/*.Amqp.build~
/package/
*.nupkg
-src/CommonAssemblyInfo.cs
+src/CommonAssemblyInfo.cs
View
2  doc/docx/Spring.Messaging.Amqp-1.0/.gitignore
@@ -1 +1 @@
-/*.bak
+/*.bak
View
2  doc/reference/.gitignore
@@ -1 +1 @@
-/target/
+/target/
View
4 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/.gitignore
@@ -1,2 +1,2 @@
-/bin/
-/obj/
+/bin/
+/obj/
View
66 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/Program.cs
@@ -1,33 +1,33 @@
-
-using System;
-using Spring.Messaging.Amqp.Core;
-using Spring.Messaging.Amqp.Rabbit.Connection;
-using Spring.Messaging.Amqp.Rabbit.Core;
-
-namespace Spring.RabbitQuickStart.BrokerConfiguration
-{
- class Program
- {
- static void Main(string[] args)
- {
- using (IConnectionFactory connectionFactory = new SingleConnectionFactory())
- {
- IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);
-
- var marketDataQueue = new Queue("APP.STOCK.MARKETDATA");
- amqpAdmin.DeclareQueue(marketDataQueue);
- var binding = BindingBuilder.Bind(marketDataQueue).To(DirectExchange.DEFAULT).WithQueueName();
- amqpAdmin.DeclareBinding(binding);
-
- amqpAdmin.DeclareQueue(new Queue("APP.STOCK.REQUEST"));
- amqpAdmin.DeclareQueue(new Queue("APP.STOCK.JOE"));
-
- //Each queue is automatically bound to the default direct exchange.
-
- Console.WriteLine("Queues and exchanges have been declared.");
- Console.WriteLine("Press 'enter' to exit");
- Console.ReadLine();
- }
- }
- }
-}
+
+using System;
+using Spring.Messaging.Amqp.Core;
+using Spring.Messaging.Amqp.Rabbit.Connection;
+using Spring.Messaging.Amqp.Rabbit.Core;
+
+namespace Spring.RabbitQuickStart.BrokerConfiguration
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ using (IConnectionFactory connectionFactory = new SingleConnectionFactory())
+ {
+ IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);
+
+ var marketDataQueue = new Queue("APP.STOCK.MARKETDATA");
+ amqpAdmin.DeclareQueue(marketDataQueue);
+ var binding = BindingBuilder.Bind(marketDataQueue).To(DirectExchange.DEFAULT).WithQueueName();
+ amqpAdmin.DeclareBinding(binding);
+
+ amqpAdmin.DeclareQueue(new Queue("APP.STOCK.REQUEST"));
+ amqpAdmin.DeclareQueue(new Queue("APP.STOCK.JOE"));
+
+ //Each queue is automatically bound to the default direct exchange.
+
+ Console.WriteLine("Queues and exchanges have been declared.");
+ Console.WriteLine("Press 'enter' to exit");
+ Console.ReadLine();
+ }
+ }
+ }
+}
View
72 ...pring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/Properties/AssemblyInfo.cs
@@ -1,36 +1,36 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Spring.RabbitQuickStart.BrokerConfiguration")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Spring.RabbitQuickStart.BrokerConfiguration")]
-[assembly: AssemblyCopyright("Copyright © 2010")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("31e1913d-8075-4ee0-a1e7-1886039f5087")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Spring.RabbitQuickStart.BrokerConfiguration")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Spring.RabbitQuickStart.BrokerConfiguration")]
+[assembly: AssemblyCopyright("Copyright © 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("31e1913d-8075-4ee0-a1e7-1886039f5087")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
34 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.BrokerConfiguration/app.config
@@ -1,18 +1,18 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
- </startup>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="Spring.Aop" publicKeyToken="65e474d141e25e07" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.3.1.40711" newVersion="1.3.1.40711" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Spring.Core" publicKeyToken="65e474d141e25e07" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.3.1.40711" newVersion="1.3.1.40711" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
+ </startup>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="Spring.Aop" publicKeyToken="65e474d141e25e07" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.3.1.40711" newVersion="1.3.1.40711" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="Spring.Core" publicKeyToken="65e474d141e25e07" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.3.1.40711" newVersion="1.3.1.40711" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
</configuration>
View
134 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Client/Program.cs
@@ -1,68 +1,68 @@
-#region License
-
-/*
- * Copyright 2002-2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#endregion
-
-using System;
-using System.Threading;
-using System.Windows.Forms;
-using Common.Logging;
-using RabbitMQ.Client;
-using Spring.Context;
-using Spring.Context.Support;
-using Spring.Messaging.Amqp.Rabbit.Core;
-using Spring.RabbitQuickStart.Client.UI;
-
-namespace Spring.RabbitQuickStart.Client
-{
- static class Program
- {
-
- private static readonly ILog log = LogManager.GetLogger(typeof(Program));
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- try
- {
- log.Info("Running....");
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- using (IApplicationContext ctx = ContextRegistry.GetContext())
- {
- StockForm stockForm = new StockForm();
- Application.ThreadException += ThreadException;
- Application.Run(stockForm);
- }
- }
- catch (Exception e)
- {
- log.Error("Spring.RabbitQuickStart.Client is broken.", e);
- }
- }
-
- private static void ThreadException(object sender, ThreadExceptionEventArgs e)
- {
- log.Error("Uncaught application exception.", e.Exception);
- Application.Exit();
- }
- }
+#region License
+
+/*
+ * Copyright 2002-2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+using System;
+using System.Threading;
+using System.Windows.Forms;
+using Common.Logging;
+using RabbitMQ.Client;
+using Spring.Context;
+using Spring.Context.Support;
+using Spring.Messaging.Amqp.Rabbit.Core;
+using Spring.RabbitQuickStart.Client.UI;
+
+namespace Spring.RabbitQuickStart.Client
+{
+ static class Program
+ {
+
+ private static readonly ILog log = LogManager.GetLogger(typeof(Program));
+
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ try
+ {
+ log.Info("Running....");
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ using (IApplicationContext ctx = ContextRegistry.GetContext())
+ {
+ StockForm stockForm = new StockForm();
+ Application.ThreadException += ThreadException;
+ Application.Run(stockForm);
+ }
+ }
+ catch (Exception e)
+ {
+ log.Error("Spring.RabbitQuickStart.Client is broken.", e);
+ }
+ }
+
+ private static void ThreadException(object sender, ThreadExceptionEventArgs e)
+ {
+ log.Error("Uncaught application exception.", e.Exception);
+ Application.Exit();
+ }
+ }
}
View
132 ...s/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Server/Gateways/MarketDataServiceGateway.cs
@@ -1,67 +1,67 @@
-using System;
-using System.Collections;
-using System.Threading;
-using Common.Logging;
-using Spring.Messaging.Amqp.Rabbit.Core.Support;
-
-namespace Spring.RabbitQuickStart.Server.Gateways
-{
- public class MarketDataServiceGateway : RabbitGatewaySupport, IMarketDataService
- {
- private static readonly ILog log = LogManager.GetLogger(typeof (MarketDataServiceGateway));
-
- private readonly Random random;
- private TimeSpan sleepTimeInSeconds = new TimeSpan(0,0,0,10,0);
-
-
- public MarketDataServiceGateway()
- {
- random = new Random();
- }
-
- public TimeSpan SleepTimeInSeconds
- {
- set { sleepTimeInSeconds = value; }
- }
-
- public void SendMarketData()
- {
- while (true)
- {
- IDictionary data = GenerateFakeMarketData();
- log.Info("Sending market data.");
- //String routingKey = "app.stock.quotes.nasdaq." + data["TICKER"];
- String routingKey = "APP.STOCK.MARKETDATA";
- RabbitTemplate.ConvertAndSend(routingKey, data);
- log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
- Thread.Sleep(sleepTimeInSeconds);
- }
- }
-
- private IDictionary GenerateFakeMarketData()
- {
- IDictionary md = new Hashtable();
- md.Add("TICKER", "CSCO");
- md.Add("PRICE", string.Format("{0:##.##}", 22+Math.Abs(Gaussian())));
- return md;
- }
-
- private double Gaussian()
- {
- double x1, x2, w;
-
- do
- {
- x1 = 2.0*random.NextDouble() - 1.0;
- x2 = 2.0*random.NextDouble() - 1.0;
- w = x1*x1 + x2*x2;
- } while (w >= 1.0);
-
- w = Math.Sqrt(-2.0*Math.Log(w)/w);
-
- // two Gaussian random numbers are generated
- return x1*w;
- //y2 = x2 * w;
- }
- }
+using System;
+using System.Collections;
+using System.Threading;
+using Common.Logging;
+using Spring.Messaging.Amqp.Rabbit.Core.Support;
+
+namespace Spring.RabbitQuickStart.Server.Gateways
+{
+ public class MarketDataServiceGateway : RabbitGatewaySupport, IMarketDataService
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof (MarketDataServiceGateway));
+
+ private readonly Random random;
+ private TimeSpan sleepTimeInSeconds = new TimeSpan(0,0,0,10,0);
+
+
+ public MarketDataServiceGateway()
+ {
+ random = new Random();
+ }
+
+ public TimeSpan SleepTimeInSeconds
+ {
+ set { sleepTimeInSeconds = value; }
+ }
+
+ public void SendMarketData()
+ {
+ while (true)
+ {
+ IDictionary data = GenerateFakeMarketData();
+ log.Info("Sending market data.");
+ //String routingKey = "app.stock.quotes.nasdaq." + data["TICKER"];
+ String routingKey = "APP.STOCK.MARKETDATA";
+ RabbitTemplate.ConvertAndSend(routingKey, data);
+ log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
+ Thread.Sleep(sleepTimeInSeconds);
+ }
+ }
+
+ private IDictionary GenerateFakeMarketData()
+ {
+ IDictionary md = new Hashtable();
+ md.Add("TICKER", "CSCO");
+ md.Add("PRICE", string.Format("{0:##.##}", 22+Math.Abs(Gaussian())));
+ return md;
+ }
+
+ private double Gaussian()
+ {
+ double x1, x2, w;
+
+ do
+ {
+ x1 = 2.0*random.NextDouble() - 1.0;
+ x2 = 2.0*random.NextDouble() - 1.0;
+ w = x1*x1 + x2*x2;
+ } while (w >= 1.0);
+
+ w = Math.Sqrt(-2.0*Math.Log(w)/w);
+
+ // two Gaussian random numbers are generated
+ return x1*w;
+ //y2 = x2 * w;
+ }
+ }
}
View
74 examples/Spring.RabbitQuickStart/src/Spring/Spring.RabbitQuickStart.Server/Program.cs
@@ -1,37 +1,37 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-using RabbitMQ.Client;
-using Spring.Context.Support;
-using Spring.Messaging.Amqp.Rabbit.Core;
-using Spring.RabbitQuickStart.Server.Gateways;
-
-namespace Spring.RabbitQuickStart.Server
-{
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- // Using Spring's IoC container
- ContextRegistry.GetContext();
- Console.Out.WriteLine("Server listening...");
- IMarketDataService marketDataService =
- ContextRegistry.GetContext().GetObject("MarketDataGateway") as MarketDataServiceGateway;
- ThreadStart job = new ThreadStart(marketDataService.SendMarketData);
- Thread thread = new Thread(job);
- thread.Start();
- Console.Out.WriteLine("--- Press <return> to quit ---");
- Console.ReadLine();
- }
- catch (Exception e)
- {
- Console.Out.WriteLine(e);
- Console.Out.WriteLine("--- Press <return> to quit ---");
- Console.ReadLine();
- }
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using RabbitMQ.Client;
+using Spring.Context.Support;
+using Spring.Messaging.Amqp.Rabbit.Core;
+using Spring.RabbitQuickStart.Server.Gateways;
+
+namespace Spring.RabbitQuickStart.Server
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ try
+ {
+ // Using Spring's IoC container
+ ContextRegistry.GetContext();
+ Console.Out.WriteLine("Server listening...");
+ IMarketDataService marketDataService =
+ ContextRegistry.GetContext().GetObject("MarketDataGateway") as MarketDataServiceGateway;
+ ThreadStart job = new ThreadStart(marketDataService.SendMarketData);
+ Thread thread = new Thread(job);
+ thread.Start();
+ Console.Out.WriteLine("--- Press <return> to quit ---");
+ Console.ReadLine();
+ }
+ catch (Exception e)
+ {
+ Console.Out.WriteLine(e);
+ Console.Out.WriteLine("--- Press <return> to quit ---");
+ Console.ReadLine();
+ }
+ }
+ }
+}
View
432 src/Spring.Messaging.Amqp.Rabbit.Admin/Admin/QueueInfo.cs
@@ -1,217 +1,217 @@
-
-#region License
-
-/*
- * Copyright 2002-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#endregion
-
-namespace Spring.Messaging.Amqp.Rabbit.Admin
-{
- /// <summary>
- /// This class represents a Queue that is configured on the RabbitMQ broker
- /// </summary>
- /// <author>Mark Pollack</author>
- public class QueueInfo
- {
- /*
- * {app.stock.request={transactions=0, acks_uncommitted=0,
- * consumers=0, pid=#Pid<rabbit@MARK6500.150.0>,
- * durable=false, messages=0, memory=2320, auto_delete=false,
- * messages_ready=0, arguments=[], name=app.stock.request,
- * messages_unacknowledged=0, messages_uncommitted=0},
- */
-
- private long transactions;
-
- private long acksUncommitted;
-
- private long consumers;
-
- private string pid;
-
- private bool durable;
-
- private long messages;
-
- private long memory;
-
- private bool autoDelete;
-
- private long messagesReady;
-
- private string[] arguments;
-
- private string name;
-
- private long messagesUnacknowledged;
-
- private long messageUncommitted;
-
- /// <summary>
- /// Gets or sets the transactions.
- /// </summary>
- /// <value>The transactions.</value>
- /// <remarks></remarks>
- public long Transactions
- {
- get { return this.transactions; }
- set { this.transactions = value; }
- }
-
- /// <summary>
- /// Gets or sets the acks uncommitted.
- /// </summary>
- /// <value>The acks uncommitted.</value>
- /// <remarks></remarks>
- public long AcksUncommitted
- {
- get { return this.acksUncommitted; }
- set { this.acksUncommitted = value; }
- }
-
- /// <summary>
- /// Gets or sets the consumers.
- /// </summary>
- /// <value>The consumers.</value>
- /// <remarks></remarks>
- public long Consumers
- {
- get { return this.consumers; }
- set { this.consumers = value; }
- }
-
- /// <summary>
- /// Gets or sets the pid.
- /// </summary>
- /// <value>The pid.</value>
- /// <remarks></remarks>
- public string Pid
- {
- get { return this.pid; }
- set { this.pid = value; }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="QueueInfo"/> is durable.
- /// </summary>
- /// <value><c>true</c> if durable; otherwise, <c>false</c>.</value>
- /// <remarks></remarks>
- public bool Durable
- {
- get { return this.durable; }
- set { this.durable = value; }
- }
-
- /// <summary>
- /// Gets or sets the messages.
- /// </summary>
- /// <value>The messages.</value>
- /// <remarks></remarks>
- public long Messages
- {
- get { return this.messages; }
- set { this.messages = value; }
- }
-
- /// <summary>
- /// Gets or sets the memory.
- /// </summary>
- /// <value>The memory.</value>
- /// <remarks></remarks>
- public long Memory
- {
- get { return this.memory; }
- set { this.memory = value; }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether [auto delete].
- /// </summary>
- /// <value><c>true</c> if [auto delete]; otherwise, <c>false</c>.</value>
- /// <remarks></remarks>
- public bool AutoDelete
- {
- get { return this.autoDelete; }
- set { this.autoDelete = value; }
- }
-
- /// <summary>
- /// Gets or sets the messages ready.
- /// </summary>
- /// <value>The messages ready.</value>
- /// <remarks></remarks>
- public long MessagesReady
- {
- get { return this.messagesReady; }
- set { this.messagesReady = value; }
- }
-
- /// <summary>
- /// Gets or sets the arguments.
- /// </summary>
- /// <value>The arguments.</value>
- /// <remarks></remarks>
- public string[] Arguments
- {
- get { return this.arguments; }
- set { this.arguments = value; }
- }
-
- /// <summary>
- /// Gets or sets the name.
- /// </summary>
- /// <value>The name.</value>
- /// <remarks></remarks>
- public string Name
- {
- get { return this.name; }
- set { this.name = value; }
- }
-
- /// <summary>
- /// Gets or sets the messages unacknowledged.
- /// </summary>
- /// <value>The messages unacknowledged.</value>
- /// <remarks></remarks>
- public long MessagesUnacknowledged
- {
- get { return this.messagesUnacknowledged; }
- set { this.messagesUnacknowledged = value; }
- }
-
- /// <summary>
- /// Gets or sets the message uncommitted.
- /// </summary>
- /// <value>The message uncommitted.</value>
- /// <remarks></remarks>
- public long MessageUncommitted
- {
- get { return this.messageUncommitted; }
- set { this.messageUncommitted = value; }
- }
-
- /// <summary>
- /// Returns a <see cref="System.String"/> that represents this instance.
- /// </summary>
- /// <returns>A <see cref="System.String"/> that represents this instance.</returns>
- /// <remarks></remarks>
- public override string ToString()
- {
- return string.Format("Transactions: {0}, AcksUncommitted: {1}, Consumers: {2}, Pid: {3}, Durable: {4}, Messages: {5}, Memory: {6}, AutoDelete: {7}, MessagesReady: {8}, Arguments: {9}, Name: {10}, MessagesUnacknowledged: {11}, MessageUncommitted: {12}", this.transactions, this.acksUncommitted, this.consumers, this.pid, this.durable, this.messages, this.memory, this.autoDelete, this.messagesReady, this.arguments, this.name, this.messagesUnacknowledged, this.messageUncommitted);
- }
- }
+
+#region License
+
+/*
+ * Copyright 2002-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+namespace Spring.Messaging.Amqp.Rabbit.Admin
+{
+ /// <summary>
+ /// This class represents a Queue that is configured on the RabbitMQ broker
+ /// </summary>
+ /// <author>Mark Pollack</author>
+ public class QueueInfo
+ {
+ /*
+ * {app.stock.request={transactions=0, acks_uncommitted=0,
+ * consumers=0, pid=#Pid<rabbit@MARK6500.150.0>,
+ * durable=false, messages=0, memory=2320, auto_delete=false,
+ * messages_ready=0, arguments=[], name=app.stock.request,
+ * messages_unacknowledged=0, messages_uncommitted=0},
+ */
+
+ private long transactions;
+
+ private long acksUncommitted;
+
+ private long consumers;
+
+ private string pid;
+
+ private bool durable;
+
+ private long messages;
+
+ private long memory;
+
+ private bool autoDelete;
+
+ private long messagesReady;
+
+ private string[] arguments;
+
+ private string name;
+
+ private long messagesUnacknowledged;
+
+ private long messageUncommitted;
+
+ /// <summary>
+ /// Gets or sets the transactions.
+ /// </summary>
+ /// <value>The transactions.</value>
+ /// <remarks></remarks>
+ public long Transactions
+ {
+ get { return this.transactions; }
+ set { this.transactions = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the acks uncommitted.
+ /// </summary>
+ /// <value>The acks uncommitted.</value>
+ /// <remarks></remarks>
+ public long AcksUncommitted
+ {
+ get { return this.acksUncommitted; }
+ set { this.acksUncommitted = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the consumers.
+ /// </summary>
+ /// <value>The consumers.</value>
+ /// <remarks></remarks>
+ public long Consumers
+ {
+ get { return this.consumers; }
+ set { this.consumers = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the pid.
+ /// </summary>
+ /// <value>The pid.</value>
+ /// <remarks></remarks>
+ public string Pid
+ {
+ get { return this.pid; }
+ set { this.pid = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this <see cref="QueueInfo"/> is durable.
+ /// </summary>
+ /// <value><c>true</c> if durable; otherwise, <c>false</c>.</value>
+ /// <remarks></remarks>
+ public bool Durable
+ {
+ get { return this.durable; }
+ set { this.durable = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the messages.
+ /// </summary>
+ /// <value>The messages.</value>
+ /// <remarks></remarks>
+ public long Messages
+ {
+ get { return this.messages; }
+ set { this.messages = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the memory.
+ /// </summary>
+ /// <value>The memory.</value>
+ /// <remarks></remarks>
+ public long Memory
+ {
+ get { return this.memory; }
+ set { this.memory = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether [auto delete].
+ /// </summary>
+ /// <value><c>true</c> if [auto delete]; otherwise, <c>false</c>.</value>
+ /// <remarks></remarks>
+ public bool AutoDelete
+ {
+ get { return this.autoDelete; }
+ set { this.autoDelete = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the messages ready.
+ /// </summary>
+ /// <value>The messages ready.</value>
+ /// <remarks></remarks>
+ public long MessagesReady
+ {
+ get { return this.messagesReady; }
+ set { this.messagesReady = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the arguments.
+ /// </summary>
+ /// <value>The arguments.</value>
+ /// <remarks></remarks>
+ public string[] Arguments
+ {
+ get { return this.arguments; }
+ set { this.arguments = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ /// <remarks></remarks>
+ public string Name
+ {
+ get { return this.name; }
+ set { this.name = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the messages unacknowledged.
+ /// </summary>
+ /// <value>The messages unacknowledged.</value>
+ /// <remarks></remarks>
+ public long MessagesUnacknowledged
+ {
+ get { return this.messagesUnacknowledged; }
+ set { this.messagesUnacknowledged = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the message uncommitted.
+ /// </summary>
+ /// <value>The message uncommitted.</value>
+ /// <remarks></remarks>
+ public long MessageUncommitted
+ {
+ get { return this.messageUncommitted; }
+ set { this.messageUncommitted = value; }
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String"/> that represents this instance.
+ /// </summary>
+ /// <returns>A <see cref="System.String"/> that represents this instance.</returns>
+ /// <remarks></remarks>
+ public override string ToString()
+ {
+ return string.Format("Transactions: {0}, AcksUncommitted: {1}, Consumers: {2}, Pid: {3}, Durable: {4}, Messages: {5}, Memory: {6}, AutoDelete: {7}, MessagesReady: {8}, Arguments: {9}, Name: {10}, MessagesUnacknowledged: {11}, MessageUncommitted: {12}", this.transactions, this.acksUncommitted, this.consumers, this.pid, this.durable, this.messages, this.memory, this.autoDelete, this.messagesReady, this.arguments, this.name, this.messagesUnacknowledged, this.messageUncommitted);
+ }
+ }
}
View
2  src/Spring.Messaging.Amqp.Rabbit/.gitignore
@@ -1 +1 @@
-/*.csproj.user
+/*.csproj.user
View
468 src/Spring.Messaging.Amqp.Rabbit/Connection/AbstractConnectionFactory.cs
@@ -1,235 +1,235 @@
-#region License
-
-/*
- * Copyright 2002-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Net;
-using Common.Logging;
-using RabbitMQ.Client;
-using Spring.Util;
-
-namespace Spring.Messaging.Amqp.Rabbit.Connection
-{
- /// <summary>
- /// A <see cref="IConnectionFactory"/> implementation that returns the same Connection from all
- /// <see cref="IConnectionFactory.CreateConnection"/> calls, and ignores call to
- /// <see cref="IConnection.Close()"/>
- /// </summary>
- /// <author>Mark Pollack</author>
- public abstract class AbstractConnectionFactory : IConnectionFactory, IDisposable
- {
- #region Logging Definition
-
- /// <summary>
- /// The logger.
- /// </summary>
- protected readonly ILog Logger = LogManager.GetLogger(typeof(AbstractConnectionFactory));
-
- #endregion
-
- /// <summary>
- /// The connection factory.
- /// </summary>
- private ConnectionFactory rabbitConnectionFactory;
-
- /// <summary>
- /// The connection listener.
- /// </summary>
- private readonly CompositeConnectionListener connectionListener = new CompositeConnectionListener();
-
- /// <summary>
- /// The channel listener.
- /// </summary>
- private readonly CompositeChannelListener channelListener = new CompositeChannelListener();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AbstractConnectionFactory"/> class.
- /// </summary>
- /// <param name="rabbitConnectionFactory">
- /// The rabbit connection factory.
- /// </param>
- public AbstractConnectionFactory(RabbitMQ.Client.ConnectionFactory rabbitConnectionFactory)
- {
- AssertUtils.ArgumentNotNull(rabbitConnectionFactory, "Target ConnectionFactory must not be null");
- this.rabbitConnectionFactory = rabbitConnectionFactory;
- }
-
- #region Implementation of IConnectionFactory
-
- /// <summary>
- /// Sets UserName.
- /// </summary>
- public string UserName
- {
- set { this.rabbitConnectionFactory.UserName = value; }
- }
-
- /// <summary>
- /// Sets Password.
- /// </summary>
- public string Password
- {
- set { this.rabbitConnectionFactory.Password = value; }
- }
-
- /// <summary>
- /// Gets or sets Host.
- /// </summary>
- public string Host
- {
- get { return this.rabbitConnectionFactory.HostName; }
- set { this.rabbitConnectionFactory.HostName = value; }
- }
-
- /// <summary>
- /// Gets or sets VirtualHost.
- /// </summary>
- public string VirtualHost
- {
- get { return this.rabbitConnectionFactory.VirtualHost; }
- set { this.rabbitConnectionFactory.VirtualHost = value; }
- }
-
- /// <summary>
- /// Gets or sets Port.
- /// </summary>
- public int Port
- {
- get { return this.rabbitConnectionFactory.Port; }
- set { this.rabbitConnectionFactory.Port = value; }
- }
-
- /// <summary>
- /// Gets the channel listener.
- /// </summary>
- public virtual IChannelListener ChannelListener
- {
- get { return this.channelListener; }
- }
-
- /// <summary>
- /// Gets the connection listener.
- /// </summary>
- public virtual IConnectionListener ConnectionListener
- {
- get { return this.connectionListener; }
- }
-
- /// <summary>
- /// Sets the connection listeners.
- /// </summary>
- /// <value>
- /// The connection listeners.
- /// </value>
- public virtual IList<IConnectionListener> ConnectionListeners
- {
- set { this.connectionListener.Delegates = value; }
- }
-
- /// <summary>
- /// Sets the channel listeners.
- /// </summary>
- /// <value>
- /// The channel listeners.
- /// </value>
- public virtual IList<IChannelListener> ChannelListeners
- {
- set { this.channelListener.Delegates = value; }
- }
-
- /// <summary>
- /// Add a connection listener.
- /// </summary>
- /// <param name="connectionListener">
- /// The listener.
- /// </param>
- public virtual void AddConnectionListener(IConnectionListener connectionListener)
- {
- this.connectionListener.AddDelegate(connectionListener);
- }
-
- /// <summary>
- /// Add a connection listener.
- /// </summary>
- /// <param name="channelListener">
- /// The listener.
- /// </param>
- public virtual void AddChannelListener(IChannelListener channelListener)
- {
- this.channelListener.AddDelegate(channelListener);
- }
-
- /// <summary>
- /// Create a connection.
- /// </summary>
- /// <returns>The connection.</returns>
- public abstract IConnection CreateConnection();
-
- /// <summary>
- /// Create a connection.
- /// </summary>
- /// <returns>The connection.</returns>
- public virtual IConnection CreateBareConnection()
- {
- try
- {
- return new SimpleConnection(this.rabbitConnectionFactory.CreateConnection());
- }
- catch (Exception ex)
- {
- throw RabbitUtils.ConvertRabbitAccessException(ex);
- }
- }
-
- /// <summary>
- /// Get the default host name.
- /// </summary>
- /// <returns>The host name.</returns>
- protected string GetDefaultHostName()
- {
- string temp;
- try
- {
- temp = Dns.GetHostName().ToUpper();
- this.Logger.Debug("Using hostname [" + temp + "] for hostname.");
- }
- catch (Exception e)
- {
- this.Logger.Warn("Could not get host name, using 'localhost' as default value", e);
- temp = "localhost";
- }
-
- return temp;
- }
-
- #endregion
-
- #region Implementation of IDisposable
-
- /// <summary>
- /// Close the underlying shared connection.
- /// </summary>
- public virtual void Dispose()
- {
- }
-
- #endregion
- }
+#region License
+
+/*
+ * Copyright 2002-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Net;
+using Common.Logging;
+using RabbitMQ.Client;
+using Spring.Util;
+
+namespace Spring.Messaging.Amqp.Rabbit.Connection
+{
+ /// <summary>
+ /// A <see cref="IConnectionFactory"/> implementation that returns the same Connection from all
+ /// <see cref="IConnectionFactory.CreateConnection"/> calls, and ignores call to
+ /// <see cref="IConnection.Close()"/>
+ /// </summary>
+ /// <author>Mark Pollack</author>
+ public abstract class AbstractConnectionFactory : IConnectionFactory, IDisposable
+ {
+ #region Logging Definition
+
+ /// <summary>
+ /// The logger.
+ /// </summary>
+ protected readonly ILog Logger = LogManager.GetLogger(typeof(AbstractConnectionFactory));
+
+ #endregion
+
+ /// <summary>
+ /// The connection factory.
+ /// </summary>
+ private ConnectionFactory rabbitConnectionFactory;
+
+ /// <summary>
+ /// The connection listener.
+ /// </summary>
+ private readonly CompositeConnectionListener connectionListener = new CompositeConnectionListener();
+
+ /// <summary>
+ /// The channel listener.
+ /// </summary>
+ private readonly CompositeChannelListener channelListener = new CompositeChannelListener();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AbstractConnectionFactory"/> class.
+ /// </summary>
+ /// <param name="rabbitConnectionFactory">
+ /// The rabbit connection factory.
+ /// </param>
+ public AbstractConnectionFactory(RabbitMQ.Client.ConnectionFactory rabbitConnectionFactory)
+ {
+ AssertUtils.ArgumentNotNull(rabbitConnectionFactory, "Target ConnectionFactory must not be null");
+ this.rabbitConnectionFactory = rabbitConnectionFactory;
+ }
+
+ #region Implementation of IConnectionFactory
+
+ /// <summary>
+ /// Sets UserName.
+ /// </summary>
+ public string UserName
+ {
+ set { this.rabbitConnectionFactory.UserName = value; }
+ }
+
+ /// <summary>
+ /// Sets Password.
+ /// </summary>
+ public string Password
+ {
+ set { this.rabbitConnectionFactory.Password = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets Host.
+ /// </summary>
+ public string Host
+ {
+ get { return this.rabbitConnectionFactory.HostName; }
+ set { this.rabbitConnectionFactory.HostName = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets VirtualHost.
+ /// </summary>
+ public string VirtualHost
+ {
+ get { return this.rabbitConnectionFactory.VirtualHost; }
+ set { this.rabbitConnectionFactory.VirtualHost = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets Port.
+ /// </summary>
+ public int Port
+ {
+ get { return this.rabbitConnectionFactory.Port; }
+ set { this.rabbitConnectionFactory.Port = value; }
+ }
+
+ /// <summary>
+ /// Gets the channel listener.
+ /// </summary>
+ public virtual IChannelListener ChannelListener
+ {
+ get { return this.channelListener; }
+ }
+
+ /// <summary>
+ /// Gets the connection listener.
+ /// </summary>
+ public virtual IConnectionListener ConnectionListener
+ {
+ get { return this.connectionListener; }
+ }
+
+ /// <summary>
+ /// Sets the connection listeners.
+ /// </summary>
+ /// <value>
+ /// The connection listeners.
+ /// </value>
+ public virtual IList<IConnectionListener> ConnectionListeners
+ {
+ set { this.connectionListener.Delegates = value; }
+ }
+
+ /// <summary>
+ /// Sets the channel listeners.
+ /// </summary>
+ /// <value>
+ /// The channel listeners.
+ /// </value>
+ public virtual IList<IChannelListener> ChannelListeners
+ {
+ set { this.channelListener.Delegates = value; }
+ }
+
+ /// <summary>
+ /// Add a connection listener.
+ /// </summary>
+ /// <param name="connectionListener">
+ /// The listener.
+ /// </param>
+ public virtual void AddConnectionListener(IConnectionListener connectionListener)
+ {
+ this.connectionListener.AddDelegate(connectionListener);
+ }
+
+ /// <summary>
+ /// Add a connection listener.
+ /// </summary>
+ /// <param name="channelListener">
+ /// The listener.
+ /// </param>
+ public virtual void AddChannelListener(IChannelListener channelListener)
+ {
+ this.channelListener.AddDelegate(channelListener);
+ }
+
+ /// <summary>
+ /// Create a connection.
+ /// </summary>
+ /// <returns>The connection.</returns>
+ public abstract IConnection CreateConnection();
+
+ /// <summary>
+ /// Create a connection.
+ /// </summary>
+ /// <returns>The connection.</returns>
+ public virtual IConnection CreateBareConnection()
+ {
+ try
+ {
+ return new SimpleConnection(this.rabbitConnectionFactory.CreateConnection());
+ }
+ catch (Exception ex)
+ {
+ throw RabbitUtils.ConvertRabbitAccessException(ex);
+ }
+ }
+
+ /// <summary>
+ /// Get the default host name.
+ /// </summary>
+ /// <returns>The host name.</returns>
+ protected string GetDefaultHostName()
+ {
+ string temp;
+ try
+ {
+ temp = Dns.GetHostName().ToUpper();
+ this.Logger.Debug("Using hostname [" + temp + "] for hostname.");
+ }
+ catch (Exception e)
+ {
+ this.Logger.Warn("Could not get host name, using 'localhost' as default value", e);
+ temp = "localhost";
+ }
+
+ return temp;
+ }
+
+ #endregion
+
+ #region Implementation of IDisposable
+
+ /// <summary>
+ /// Close the underlying shared connection.
+ /// </summary>
+ public virtual void Dispose()
+ {
+ }
+
+ #endregion
+ }
}
View
132 src/Spring.Messaging.Amqp.Rabbit/Connection/CompositeConnectionListener.cs
@@ -1,66 +1,66 @@
-
-using System.Collections.Generic;
-
-namespace Spring.Messaging.Amqp.Rabbit.Connection
-{
- /// <summary>
- /// A composite connection listener.
- /// </summary>
- /// <author>Dave Syer</author>
- /// <author>Joe Fitzgerald</author>
- public class CompositeConnectionListener : IConnectionListener
- {
- /// <summary>
- /// The delegates.
- /// </summary>
- private IList<IConnectionListener> delegates = new List<IConnectionListener>();
-
- /// <summary>
- /// Sets the delegates.
- /// </summary>
- /// <value>
- /// The delegates.
- /// </value>
- public IList<IConnectionListener> Delegates
- {
- set { this.delegates = value; }
- }
-
- /// <summary>
- /// Adds the delegate.
- /// </summary>
- /// <param name="connectionListener">The connection listener.</param>
- public void AddDelegate(IConnectionListener connectionListener)
- {
- this.delegates.Add(connectionListener);
- }
-
- /// <summary>
- /// Action to perform on create.
- /// </summary>
- /// <param name="connection">
- /// The connection.
- /// </param>
- public void OnCreate(IConnection connection)
- {
- foreach (var theDelegate in this.delegates)
- {
- theDelegate.OnCreate(connection);
- }
- }
-
- /// <summary>
- /// Action to perform on close.
- /// </summary>
- /// <param name="connection">
- /// The connection.
- /// </param>
- public void OnClose(IConnection connection)
- {
- foreach (var theDelegate in this.delegates)
- {
- theDelegate.OnClose(connection);
- }
- }
- }
-}
+
+using System.Collections.Generic;
+
+namespace Spring.Messaging.Amqp.Rabbit.Connection
+{
+ /// <summary>
+ /// A composite connection listener.
+ /// </summary>
+ /// <author>Dave Syer</author>
+ /// <author>Joe Fitzgerald</author>
+ public class CompositeConnectionListener : IConnectionListener
+ {
+ /// <summary>
+ /// The delegates.
+ /// </summary>
+ private IList<IConnectionListener> delegates = new List<IConnectionListener>();
+
+ /// <summary>
+ /// Sets the delegates.
+ /// </summary>
+ /// <value>
+ /// The delegates.
+ /// </value>
+ public IList<IConnectionListener> Delegates
+ {
+ set { this.delegates = value; }
+ }
+
+ /// <summary>
+ /// Adds the delegate.
+ /// </summary>
+ /// <param name="connectionListener">The connection listener.</param>
+ public void AddDelegate(IConnectionListener connectionListener)
+ {
+ this.delegates.Add(connectionListener);
+ }
+
+ /// <summary>
+ /// Action to perform on create.
+ /// </summary>
+ /// <param name="connection">
+ /// The connection.
+ /// </param>
+ public void OnCreate(IConnection connection)
+ {
+ foreach (var theDelegate in this.delegates)
+ {
+ theDelegate.OnCreate(connection);
+ }
+ }
+
+ /// <summary>
+ /// Action to perform on close.
+ /// </summary>
+ /// <param name="connection">
+ /// The connection.
+ /// </param>
+ public void OnClose(IConnection connection)
+ {
+ foreach (var theDelegate in this.delegates)
+ {
+ theDelegate.OnClose(connection);
+ }
+ }
+ }
+}
View
1,062 src/Spring.Messaging.Amqp.Rabbit/Core/RabbitAdmin.cs
@@ -1,532 +1,532 @@
-
-#region License
-
-/*
- * Copyright 2002-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#endregion
-
-using System;
-using Common.Logging;
-using Spring.Context;
-using Spring.Messaging.Amqp.Core;
-using Spring.Messaging.Amqp.Rabbit.Connection;
-using Spring.Objects.Factory;
-using Spring.Threading.AtomicTypes;
-using Spring.Util;
-
-namespace Spring.Messaging.Amqp.Rabbit.Core
-{
- using System.Collections;
-
- using Queue = Spring.Messaging.Amqp.Core.Queue;
-
- /// <summary>
- /// RabbitMQ implementation of portable AMQP administrative operations for AMQP >= 0.8
- /// </summary>
- /// <author>Mark Pollack</author>
- /// <author>Joe Fitzgerald</author>
- public class RabbitAdmin : IAmqpAdmin, IApplicationContextAware, IInitializingObject
- {
- /// <summary>
- /// The logger.
- /// </summary>
- protected static readonly ILog Logger = LogManager.GetLogger(typeof(RabbitAdmin));
-
- /// <summary>
- /// The rabbit template.
- /// </summary>
- private RabbitTemplate rabbitTemplate;
-
- /// <summary>
- /// The running flag.
- /// </summary>
- private volatile bool running = false;
-
- /// <summary>
- /// The auto startup flag.
- /// </summary>
- private volatile bool autoStartup = true;
-
- /// <summary>
- /// The application context.
- /// </summary>
- private volatile IApplicationContext applicationContext;
-
- /// <summary>
- /// The lifecycle monitor.
- /// </summary>
- private readonly object lifecycleMonitor = new object();
-
- /// <summary>
- /// The connection factory.
- /// </summary>
- private IConnectionFactory connectionFactory;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="RabbitAdmin"/> class.
- /// </summary>
- /// <param name="connectionFactory">The connection factory.</param>
- public RabbitAdmin(IConnectionFactory connectionFactory)
- {
- this.connectionFactory = connectionFactory;
- AssertUtils.ArgumentNotNull(connectionFactory, "ConnectionFactory is required");
- this.rabbitTemplate = new RabbitTemplate(connectionFactory);
- }
-
- /// <summary>
- /// Sets a value indicating whether AutoStartup.
- /// </summary>
- public bool AutoStartup
- {
- get { return this.autoStartup; }
- set { this.autoStartup = value; }
- }
-
- /// <summary>
- /// Sets ApplicationContext.
- /// </summary>
- public IApplicationContext ApplicationContext
- {
- set { this.applicationContext = value; }
- }
-
- /// <summary>
- /// Gets RabbitTemplate.
- /// </summary>
- public RabbitTemplate RabbitTemplate
- {
- get { return this.rabbitTemplate; }
- }
-
- #region Implementation of IAmqpAdmin
-
- /// <summary>
- /// Declares the exchange.
- /// </summary>
- /// <param name="exchange">The exchange.</param>
- public void DeclareExchange(IExchange exchange)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- this.DeclareExchanges(channel, exchange);
- return null;
- });
- }
-
- /// <summary>
- /// Deletes the exchange.
- /// </summary>
- /// <remarks>
- /// Look at implementation specific subclass for implementation specific behavior, for example
- /// for RabbitMQ this will delete the exchange without regard for whether it is in use or not.
- /// </remarks>
- /// <param name="exchangeName">
- /// Name of the exchange.
- /// </param>
- /// <returns>
- /// The result of deleting the exchange.
- /// </returns>
- public bool DeleteExchange(string exchangeName)
- {
- return this.rabbitTemplate.Execute(channel =>
- {
- try
- {
- channel.ExchangeDelete(exchangeName, false);
- }
- catch (Exception e)
- {
- Logger.Error("Could not delete exchange.", e);
- return false;
- }
-
- return true;
- });
- }
-
- /// <summary>
- /// Declares the queue.
- /// </summary>
- /// <param name="queue">The queue.</param>
- public void DeclareQueue(Queue queue)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- this.DeclareQueues(channel, queue);
- return null;
- });
- }
-
- /// <summary>
- /// Declares a queue whose name is automatically named by the server. It is created with
- /// exclusive = true, autoDelete=true, and durable = false.
- /// </summary>
- /// <returns>The queue.</returns>
- public Queue DeclareQueue()
- {
- var queueName = this.rabbitTemplate.Execute(channel => channel.QueueDeclare());
- var queue = new Queue(queueName.QueueName, false, true, true);
- return queue;
- }
-
- /// <summary>
- /// Deletes the queue, without regard for whether it is in use or has messages on it
- /// </summary>
- /// <param name="queueName">
- /// Name of the queue.
- /// </param>
- /// <returns>
- /// The result of deleting the queue.
- /// </returns>
- public bool DeleteQueue(string queueName)
- {
- return this.rabbitTemplate.Execute(channel =>
- {
- try
- {
- channel.QueueDelete(queueName);
- }
- catch (Exception e)
- {
- Logger.Error("Could not delete queue.", e);
- return false;
- }
-
- return true;
- });
- }
-
- /// <summary>
- /// Deletes the queue.
- /// </summary>
- /// <param name="queueName">Name of the queue.</param>
- /// <param name="unused">if set to <c>true</c> the queue should be deleted only if not in use.</param>
- /// <param name="empty">if set to <c>true</c> the queue should be deleted only if empty.</param>
- public void DeleteQueue(string queueName, bool unused, bool empty)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- channel.QueueDelete(queueName, unused, empty);
- return null;
- });
- }
-
- /// <summary>
- /// Purges the queue.
- /// </summary>
- /// <param name="queueName">Name of the queue.</param>
- /// <param name="noWait">if set to <c>true</c> [no wait].</param>
- public void PurgeQueue(string queueName, bool noWait)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- channel.QueuePurge(queueName);
- return null;
- });
- }
-
- /// <summary>
- /// Declare the binding.
- /// </summary>
- /// <param name="binding">
- /// The binding.
- /// </param>
- public void DeclareBinding(Binding binding)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- this.DeclareBindings(channel, binding);
- return null;
- });
- }
-
- /// <summary>
- /// Remove a binding of a queue to an exchange.
- /// </summary>
- /// <param name="binding">Binding to remove.</param>
- public void RemoveBinding(Binding binding)
- {
- this.rabbitTemplate.Execute<object>(channel =>
- {
- if (binding.IsDestinationQueue())
- {
- channel.QueueUnbind(binding.Destination, binding.Exchange, binding.RoutingKey, binding.Arguments);
- }
- else
- {
- channel.ExchangeUnbind(binding.Destination, binding.Exchange, binding.RoutingKey, binding.Arguments);
- }
-
- return null;
- });
- }
-
- #endregion
-
- #region Implementation of IInitializingObject
-
- /// <summary>
- /// Actions to perform after properties are set.
- /// </summary>
- /// <exception cref="InvalidOperationException">
- /// </exception>
- public void AfterPropertiesSet()
- {
- lock (this.lifecycleMonitor)
- {
- if (this.running || !this.autoStartup)
- {
- return;
- }
-
- this.connectionFactory.AddConnectionListener(new AdminConnectionListener(this));
-
- this.running = true;
- }
- }
-
- /// <summary>
- /// Declares all the exchanges, queues and bindings in the enclosing application context, if any. It should be safe
- /// (but unnecessary) to call this method more than once.
- /// </summary>
- public void Initialize()
- {
- if (this.applicationContext == null)
- {
- if (Logger.IsDebugEnabled)
- {
- Logger.Debug("no ApplicationContext has been set, cannot auto-declare Exchanges, Queues, and Bindings");
- }
-
- return;
- }
-
- Logger.Debug("Initializing declarations");
- var exchanges = this.applicationContext.GetObjectsOfType(typeof(IExchange)).Values;
- var queues = this.applicationContext.GetObjectsOfType(typeof(Queue)).Values;
- var bindings = this.applicationContext.GetObjectsOfType(typeof(Binding)).Values;
-
- foreach (IExchange exchange in exchanges)
- {
- if (!exchange.Durable)
- {
- Logger.Warn("Auto-declaring a non-durable Exchange ("
- + exchange.Name +
- "). It will be deleted by the broker if it shuts down, and can be redeclared by closing and reopening the connection.");
- }
- if (exchange.AutoDelete)
- {
- Logger.Warn("Auto-declaring an auto-delete Exchange ("
- + exchange.Name
- + "). It will be deleted by the broker if not in use (if all bindings are deleted), but will only be redeclared if the connection is closed and reopened.");
- }
- }
-
- foreach (Queue queue in queues)
- {
- if (!queue.Durable)
- {
- Logger.Warn("Auto-declaring a non-durable Queue ("
- + queue.Name
- + "). It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.");
- }
-
- if (queue.AutoDelete)
- {
- Logger.Warn("Auto-declaring an auto-delete Queue ("
- + queue.Name
- + "). It will be deleted by the broker if not in use, and all messages will be lost. Redeclared when the connection is closed and reopened.");
- }
-
- if (queue.Exclusive)
- {
- Logger.Warn("Auto-declaring an exclusive Queue ("
- + queue.Name
- + "). It cannot be accessed by consumers on another connection, and will be redeclared if the connection is reopened.");
- }
- }
-
- this.rabbitTemplate.Execute<object>(channel =>
- {
- var exchangeArray = new IExchange[exchanges.Count];
- var queueArray = new Queue[queues.Count];
- var bindingArray = new Binding[bindings.Count];
-
- exchanges.CopyTo(exchangeArray, 0);
- queues.CopyTo(queueArray, 0);
- bindings.CopyTo(bindingArray, 0);
-
- this.DeclareExchanges(channel, exchangeArray);
- this.DeclareQueues(channel, queueArray);
- this.DeclareBindings(channel, bindingArray);
- return null;
- });
-
- Logger.Debug("Declarations finished");
- }
- #endregion
-
- /// <summary>
- /// Declare the exchanges.
- /// </summary>
- /// <param name="channel">
- /// The channel.
- /// </param>
- /// <param name="exchanges">
- /// The exchanges.
- /// </param>
- private void DeclareExchanges(RabbitMQ.Client.IModel channel, params IExchange[] exchanges)
- {
- foreach (var exchange in exchanges)
- {
- if (Logger.IsDebugEnabled)
- {
- Logger.Debug("declaring Exchange '" + exchange.Name + "'");
- }
-
- channel.ExchangeDeclare(exchange.Name, exchange.ExchangeType, exchange.Durable, exchange.AutoDelete, exchange.Arguments);
- }
- }
-
- /// <summary>
- /// Declare the queues.
- /// </summary>
- /// <param name="channel">
- /// The channel.
- /// </param>
- /// <param name="queues">
- /// The queues.
- /// </param>
- private void DeclareQueues(RabbitMQ.Client.IModel channel, params Queue[] queues)
- {
- foreach (var queue in queues)
- {
- if (!queue.Name.StartsWith("amq."))
- {
- if (Logger.IsDebugEnabled)
- {
- Logger.Debug("Declaring Queue '" + queue.Name + "'");
- }
-
- channel.QueueDeclare(queue.Name, queue.Durable, queue.Exclusive, queue.AutoDelete, (IDictionary)queue.Arguments);
- }
- else if (Logger.IsDebugEnabled)
- {
- Logger.Debug("Queue with name that starts with 'amq.' cannot be declared.");
- }
- }
- }
-
- /// <summary>
- /// Declare the bindings.
- /// </summary>
- /// <param name="channel">
- /// The channel.
- /// </param>
- /// <param name="bindings">
- /// The bindings.
- /// </param>
- private void DeclareBindings(RabbitMQ.Client.IModel channel, params Binding[] bindings)
- {
- foreach (var binding in bindings)
- {
- if (Logger.IsDebugEnabled)
- {
- Logger.Debug("Binding destination [" + binding.Destination + " (" + binding.BindingDestinationType
- + ")] to exchange [" + binding.Exchange + "] with routing key [" + binding.RoutingKey
- + "]");
- }
-
- if (binding.IsDestinationQueue())
- {
- channel.QueueBind(binding.Destination, binding.Exchange, binding.RoutingKey, binding.Arguments);
- }
- else
- {
- channel.ExchangeBind(binding.Destination, binding.Exchange, binding.RoutingKey, binding.Arguments);
- }
- }
- }
- }
-
- /// <summary>
- /// An admin connection listener.
- /// </summary>
- internal class AdminConnectionListener : IConnectionListener
- {
- /// <summary>
- /// The outer rabbitadmin.
- /// </summary>
- private readonly RabbitAdmin outer;
-
- /// <summary>
- /// Prevent stack overflow...
- /// </summary>
- private AtomicBoolean initializing = new AtomicBoolean(false);
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AdminConnectionListener"/> class.
- /// </summary>
- /// <param name="outer">
- /// The outer.
- /// </param>
- public AdminConnectionListener(RabbitAdmin outer)
- {
- this.outer = outer;
- }
-
- /// <summary>
- /// Actions to perform on create.
- /// </summary>
- /// <param name="connection">
- /// The connection.
- /// </param>
- public void OnCreate(IConnection connection)
- {
- if (!this.initializing.CompareAndSet(false, true))
- {
- // If we are already initializing, we don't need to do it again...
- return;
- }
-
- try
- {
- /*
- * ...but it is possible for this to happen twice in the same ConnectionFactory (if more than
- * one concurrent Connection is allowed). It's idempotent, so no big deal (a bit of network
- * chatter). In fact it might even be a good thing: exclusive queues only make sense if they are
- * declared for every connection. If anyone has a problem with it: use auto-startup="false".
- */
- this.outer.Initialize();
- }
- finally
- {
- this.initializing.CompareAndSet(true, false);
- }
- }
-
- /// <summary>
- /// Actions to perform on close.
- /// </summary>
- /// <param name="connection">
- /// The connection.
- /// </param>
- public void OnClose(IConnection connection)
- {
- }
- }
+
+#region License
+
+/*
+ * Copyright 2002-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+using System;
+using Common.Logging;
+using Spring.Context;
+using Spring.Messaging.Amqp.Core;
+using Spring.Messaging.Amqp.Rabbit.Connection;
+using Spring.Objects.Factory;
+using Spring.Threading.AtomicTypes;
+using Spring.Util;
+
+namespace Spring.Messaging.Amqp.Rabbit.Core
+{
+ using System.Collections;
+
+ using Queue = Spring.Messaging.Amqp.Core.Queue;
+
+ /// <summary>
+ /// RabbitMQ implementation of portable AMQP administrative operations for AMQP >= 0.8
+ /// </summary>
+ /// <author>Mark Pollack</author>
+ /// <author>Joe Fitzgerald</author>
+ public class RabbitAdmin : IAmqpAdmin, IApplicationContextAware, IInitializingObject
+ {
+ /// <summary>
+ /// The logger.
+ /// </summary>
+ protected static readonly ILog Logger = LogManager.GetLogger(typeof(RabbitAdmin));
+
+ /// <summary>
+ /// The rabbit template.
+ /// </summary>
+ private RabbitTemplate rabbitTemplate;
+
+ /// <summary>
+ /// The running flag.
+ /// </summary>
+ private volatile bool running = false;
+
+ /// <summary>
+ /// The auto startup flag.
+ /// </summary>
+ private volatile bool autoStartup = true;
+
+ /// <summary>
+ /// The application context.
+ /// </summary>
+ private volatile IApplicationContext applicationContext;
+
+ /// <summary>
+ /// The lifecycle monitor.
+ /// </summary>
+ private readonly object lifecycleMonitor = new object();
+
+ /// <summary>
+ /// The connection factory.
+ /// </summary>
+ private IConnectionFactory connectionFactory;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RabbitAdmin"/> class.
+ /// </summary>
+ /// <param name="connectionFactory">The connection factory.</param>
+ public RabbitAdmin(IConnectionFactory connectionFactory)
+ {
+ this.connectionFactory = connectionFactory;
+ AssertUtils.ArgumentNotNull(connectionFactory, "ConnectionFactory is required");
+ this.rabbitTemplate = new RabbitTemplate(connectionFactory);
+ }
+
+ /// <summary>
+ /// Sets a value indicating whether AutoStartup.
+ /// </summary>
+ public bool AutoStartup
+ {
+ get { return this.autoStartup; }
+ set { this.autoStartup = value; }
+ }
+
+ /// <summary>
+ /// Sets ApplicationContext.
+ /// </summary>
+ public IApplicationContext ApplicationContext
+ {
+ set { this.applicationContext = value; }
+ }
+
+ /// <summary>
+ /// Gets RabbitTemplate.
+ /// </summary>
+ public RabbitTemplate RabbitTemplate
+ {
+ get { return this.rabbitTemplate; }
+ }
+
+ #region Implementation of IAmqpAdmin
+
+ /// <summary>
+ /// Declares the exchange.
+ /// </summary>
+ /// <param name="exchange">The exchange.</param>
+ public void DeclareExchange(IExchange exchange)
+ {
+ this.rabbitTemplate.Execute<object>(channel =>
+ {
+ this.DeclareExchanges(channel, exchange);
+ return null;
+ });
+ }
+
+ /// <summary>
+ /// Deletes the exchange.
+ /// </summary>
+ /// <remarks>
+ /// Look at implementation specific subclass for implementation specific behavior, for example
+ /// for RabbitMQ this will delete the exchange without regard for whether it is in use or not.
+ /// </remarks>
+ /// <param name="exchangeName">
+ /// Name of the exchange.
+ /// </param>
+ /// <returns>
+ /// The result of deleting the exchange.
+ /// </returns>
+ public bool DeleteExchange(string exchangeName)
+ {
+ return this.rabbitTemplate.Execute(channel =>
+ {
+ try
+ {
+ channel.ExchangeDelete(exchangeName, false);
+ }
+ catch (Exception e)
+ {
+ Logger.Error("Could not delete exchange.", e);
+ return false;
+ }
+
+ return true;
+ });
+ }
+
+ /// <summary>
+ /// Declares the queue.
+ /// </summary>
+ /// <param name="queue">The queue.</param>
+ public void DeclareQueue(Queue queue)
+ {
+ this.rabbitTemplate.Execute<object>(channel =>
+ {
+ this.DeclareQueues(channel, queue);
+ return null;
+ });
+ }
+
+ /// <summary>
+ /// Declares a queue whose name is automatically named by the server. It is created with
+ /// exclusive = true, autoDelete=true, and durable = false.
+ /// </summary>
+ /// <returns>The queue.</returns>
+ public Queue DeclareQueue()
+ {
+ var queueName = this.rabbitTemplate.Execute(channel => channel.QueueDeclare());
+ var queue = new Queue(queueName.QueueName, false, true, true);
+ return queue;
+ }
+
+ /// <summary>
+ /// Deletes the queue, without regard for whether it is in use or has messages on it
+ /// </summary>
+ /// <param name="queueName">
+ /// Name of the queue.