diff --git a/apache-nms-amqp.sln b/apache-nms-amqp.sln index 8cc386e0..aa6cfc65 100644 --- a/apache-nms-amqp.sln +++ b/apache-nms-amqp.sln @@ -4,25 +4,17 @@ VisualStudioVersion = 16.0.28922.388 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache-NMS-AMQP", "src\NMS.AMQP\Apache-NMS-AMQP.csproj", "{0D8CF699-9702-4EC6-8719-C2968D32F09A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorld", "src\HelloWorld\HelloWorld.csproj", "{A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache-NMS-AMQP-Test", "test\Apache-NMS-AMQP-Test\Apache-NMS-AMQP-Test.csproj", "{DF402917-D85D-421C-A7E2-DC3DF371B9CB}" ProjectSection(ProjectDependencies) = postProject {0D8CF699-9702-4EC6-8719-C2968D32F09A} = {0D8CF699-9702-4EC6-8719-C2968D32F09A} EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructuredMessage", "src\StructuredMessage\StructuredMessage.csproj", "{08936343-AA11-4409-9599-06762070CF82}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{19D7C0B5-0D2B-4459-BE75-6DD353857B28}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transactions", "src\Transactions\Transactions.csproj", "{846D7B8A-49F5-408E-9189-402F4A90912D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache-NMS-AMQP-Interop-Test", "test\Apache-NMS-AMQP-Interop-Test\Apache-NMS-AMQP-Interop-Test.csproj", "{E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{C0489CE7-BB93-48A6-A136-26FA942DB990}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PingPong", "src\PingPong\PingPong.csproj", "{CA6094FA-B615-47E6-A5D5-224BE62CDF70}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,18 +37,6 @@ Global {0D8CF699-9702-4EC6-8719-C2968D32F09A}.Release|x64.Build.0 = Release|Any CPU {0D8CF699-9702-4EC6-8719-C2968D32F09A}.Release|x86.ActiveCfg = Release|Any CPU {0D8CF699-9702-4EC6-8719-C2968D32F09A}.Release|x86.Build.0 = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|x64.ActiveCfg = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|x64.Build.0 = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|x86.ActiveCfg = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Debug|x86.Build.0 = Debug|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|Any CPU.Build.0 = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|x64.ActiveCfg = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|x64.Build.0 = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|x86.ActiveCfg = Release|Any CPU - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD}.Release|x86.Build.0 = Release|Any CPU {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -69,30 +49,6 @@ Global {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Release|x64.Build.0 = Release|Any CPU {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Release|x86.ActiveCfg = Release|Any CPU {DF402917-D85D-421C-A7E2-DC3DF371B9CB}.Release|x86.Build.0 = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|Any CPU.Build.0 = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|x64.ActiveCfg = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|x64.Build.0 = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|x86.ActiveCfg = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Debug|x86.Build.0 = Debug|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|Any CPU.ActiveCfg = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|Any CPU.Build.0 = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|x64.ActiveCfg = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|x64.Build.0 = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|x86.ActiveCfg = Release|Any CPU - {08936343-AA11-4409-9599-06762070CF82}.Release|x86.Build.0 = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|x64.ActiveCfg = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|x64.Build.0 = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|x86.ActiveCfg = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Debug|x86.Build.0 = Debug|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|Any CPU.Build.0 = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|x64.ActiveCfg = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|x64.Build.0 = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|x86.ActiveCfg = Release|Any CPU - {846D7B8A-49F5-408E-9189-402F4A90912D}.Release|x86.Build.0 = Release|Any CPU {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Debug|Any CPU.Build.0 = Debug|Any CPU {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -105,18 +61,6 @@ Global {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Release|x64.Build.0 = Release|Any CPU {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Release|x86.ActiveCfg = Release|Any CPU {E5D009CB-7DDD-4C49-B7EB-361D42D0BF14}.Release|x86.Build.0 = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|x64.ActiveCfg = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|x64.Build.0 = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|x86.ActiveCfg = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Debug|x86.Build.0 = Debug|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|Any CPU.Build.0 = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|x64.ActiveCfg = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|x64.Build.0 = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|x86.ActiveCfg = Release|Any CPU - {CA6094FA-B615-47E6-A5D5-224BE62CDF70}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -125,9 +69,5 @@ Global SolutionGuid = {B29AB696-17A9-4B32-AA26-D354C00C9587} EndGlobalSection GlobalSection(NestedProjects) = preSolution - {A56349BE-ED66-4E18-B5FE-E3EA069D2ADD} = {19D7C0B5-0D2B-4459-BE75-6DD353857B28} - {08936343-AA11-4409-9599-06762070CF82} = {19D7C0B5-0D2B-4459-BE75-6DD353857B28} - {846D7B8A-49F5-408E-9189-402F4A90912D} = {19D7C0B5-0D2B-4459-BE75-6DD353857B28} - {CA6094FA-B615-47E6-A5D5-224BE62CDF70} = {C0489CE7-BB93-48A6-A136-26FA942DB990} EndGlobalSection EndGlobal diff --git a/src/HelloWorld/HelloWorld.cs b/src/HelloWorld/HelloWorld.cs deleted file mode 100644 index d17a2db9..00000000 --- a/src/HelloWorld/HelloWorld.cs +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -using System; -using System.Collections.Specialized; -using Apache.NMS; -using Apache.NMS.AMQP; -using CommandLine; - -namespace HelloWorld -{ - class CommandLineOpts - { - // URI for message broker. Must be of the format amqp://: or amqps://: - [Option("uri", Required = true, HelpText = "The URI for the AMQP Message Broker")] - public string host { get; set; } - // Connection Request Timeout - [Option("ct", Default = 15000, HelpText = "the connection request timeout in milliseconds.")] - public long connTimeout { get; set; } - // UserName for authentication with the broker. - [Option("cu", Default = null, HelpText = "The Username for authentication with the message broker")] - public string username { get; set; } - // Password for authentication with the broker - [Option("cpwd", Default = null, HelpText = "The password for authentication with the message broker")] - public string password { get; set; } - [Option("cid", Default = null, HelpText = "The Client ID on the connection")] - public string clientId { get; set; } - // Logging Level - [Option("log", Default = "warn", HelpText = "Sets the log level for the application and NMS Library. The levels are (from highest verbosity): debug,info,warn,error,fatal.")] - public string logLevel { get; set; } - // - [Option("topic", Default = null, HelpText = "Topic to publish messages to. Can not be used with --queue.")] - public string topic { get; set; } - // - [Option("queue", Default = null, HelpText = "Queue to publish messages to. Can not be used with --topic.")] - public string queue { get; set; } - // - [Option('n', "messages", Default = 5, HelpText = "Number of messages to send.")] - public int NUM_MSG { get; set; } - // - [Option("deliveryMode", Default = 5, HelpText = "Message Delivery Mode, Persistnent(0) and Non Persistent(1). The default is Persistent(0).")] - public int mode { get; set; } - } - class Program - { - - private static void RunWithOptions (CommandLineOpts opts) - { - ITrace logger = new Logger(Logger.ToLogLevel(opts.logLevel)); - Tracer.Trace = logger; - - string ip = opts.host; - Uri providerUri = new Uri(ip); - Console.WriteLine("scheme: {0}", providerUri.Scheme); - - IConnection conn = null; - if (opts.topic == null && opts.queue == null) - { - Console.WriteLine("ERROR: Must specify a topic or queue destination"); - return; - } - try - { - NmsConnectionFactory factory = new NmsConnectionFactory(ip); - if (opts.username != null) - { - factory.UserName = opts.username; - } - if (opts.password != null) - { - factory.Password = opts.password; - } - if (opts.clientId != null) - { - factory.ClientId = opts.clientId; - } - - if (opts.connTimeout != default) - { - factory.SendTimeout = opts.connTimeout; - } - - Console.WriteLine("Creating Connection..."); - conn = factory.CreateConnection(); - conn.ExceptionListener += (logger as Logger).LogException; - Console.WriteLine("Created Connection."); - Console.WriteLine("Version: {0}", conn.MetaData); - Console.WriteLine("Creating Session..."); - ISession ses = conn.CreateSession(); - Console.WriteLine("Session Created."); - - conn.Start(); - IDestination dest = (opts.topic==null) ? (IDestination)ses.GetQueue(opts.queue) : (IDestination)ses.GetTopic(opts.topic); - Console.WriteLine("Creating Message Producer for : {0}...", dest); - IMessageProducer prod = ses.CreateProducer(dest); - IMessageConsumer consumer = ses.CreateConsumer(dest); - Console.WriteLine("Created Message Producer."); - prod.DeliveryMode = opts.mode == 0 ? MsgDeliveryMode.NonPersistent : MsgDeliveryMode.Persistent; - prod.TimeToLive = TimeSpan.FromSeconds(20); - ITextMessage msg = prod.CreateTextMessage("Hello World!"); - - Console.WriteLine("Sending Msg: {0}", msg.ToString()); - Console.WriteLine("Starting Connection..."); - conn.Start(); - Console.WriteLine("Connection Started: {0} Resquest Timeout: {1}", conn.IsStarted, conn.RequestTimeout); - Console.WriteLine("Sending {0} Messages...", opts.NUM_MSG); - for (int i = 0; i < opts.NUM_MSG; i++) - { - Tracer.InfoFormat("Sending Msg {0}", i + 1); - // Text Msg Body - msg.Text = "Hello World! n: " + i; - prod.Send(msg); - msg.ClearBody(); - } - - IMessage rmsg = null; - for (int i = 0; i < opts.NUM_MSG; i++) - { - Tracer.InfoFormat("Waiting to receive message {0} from consumer.", i); - rmsg = consumer.Receive(TimeSpan.FromMilliseconds(opts.connTimeout)); - if(rmsg == null) - { - Console.WriteLine("Failed to receive Message in {0}ms.", opts.connTimeout); - } - else - { - Console.WriteLine("Received Message with id {0} and contents {1}.", rmsg.NMSMessageId, rmsg.ToString()); - } - } - if (conn.IsStarted) - { - Console.WriteLine("Closing Connection..."); - conn.Close(); - Console.WriteLine("Connection Closed."); - } - } - catch(NMSException ne) - { - Console.WriteLine("Caught NMSException : {0} \nStack: {1}", ne.Message, ne); - } - catch (Exception e) - { - Console.WriteLine("Caught unexpected exception : {0}", e); - } - finally - { - if(conn != null) - { - conn.Dispose(); - } - } - } - - static void Main(string[] args) - { - CommandLineOpts opts = new CommandLineOpts(); - ParserResult result = CommandLine.Parser.Default.ParseArguments(args) - .WithParsed(options => RunWithOptions(options)); - } - } - - #region Logging - - class Logger : ITrace - { - public enum LogLevel - { - OFF = -1, - FATAL, - ERROR, - WARN, - INFO, - DEBUG - } - - public static LogLevel ToLogLevel(string logString) - { - if(logString == null || logString.Length == 0) - { - return LogLevel.OFF; - } - if ("FATAL".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.FATAL; - } - else if ("ERROR".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.ERROR; - } - else if ("WARN".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.WARN; - } - else if ("INFO".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.INFO; - } - else if ("DEBUG".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.DEBUG; - } - else - { - return LogLevel.OFF; - } - } - - private LogLevel lv; - - public void LogException(Exception ex) - { - this.Warn("Exception: "+ex.Message); - } - - public Logger() : this(LogLevel.WARN) - { - } - - public Logger(LogLevel lvl) - { - lv = lvl; - } - - public bool IsDebugEnabled - { - get - { - return lv >= LogLevel.DEBUG; - } - } - - public bool IsErrorEnabled - { - get - { - - return lv >= LogLevel.ERROR; - } - } - - public bool IsFatalEnabled - { - get - { - return lv >= LogLevel.FATAL; - } - } - - public bool IsInfoEnabled - { - get - { - return lv >= LogLevel.INFO; - } - } - - public bool IsWarnEnabled - { - get - { - return lv >= LogLevel.WARN; - } - } - - public void Debug(string message) - { - if(IsDebugEnabled) - Console.WriteLine("Debug: {0}", message); - } - - public void Error(string message) - { - if (IsErrorEnabled) - Console.WriteLine("Error: {0}", message); - } - - public void Fatal(string message) - { - if (IsFatalEnabled) - Console.WriteLine("Fatal: {0}", message); - } - - public void Info(string message) - { - if (IsInfoEnabled) - Console.WriteLine("Info: {0}", message); - } - - public void Warn(string message) - { - if (IsWarnEnabled) - Console.WriteLine("Warn: {0}", message); - } - } - #endregion -} diff --git a/src/HelloWorld/HelloWorld.csproj b/src/HelloWorld/HelloWorld.csproj deleted file mode 100644 index 6a460a0b..00000000 --- a/src/HelloWorld/HelloWorld.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - - net462;netcoreapp2.1 - $(AppTargetFramework) - Exe - HelloWorld - HelloWorld - 7.3 - False - - - - - - - - - - diff --git a/src/PingPong/Ping.cs b/src/PingPong/Ping.cs deleted file mode 100644 index ff2fa4f4..00000000 --- a/src/PingPong/Ping.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -using System; -using System.Diagnostics; -using System.Threading.Tasks; -using Apache.NMS; - -namespace PingPong -{ - public class Ping: IDisposable - { - private readonly IConnection connection; - private readonly ISession session; - private readonly IMessageProducer messageProducer; - private readonly IMessageConsumer messageConsumer; - private readonly Stopwatch stopwatch; - private readonly ITextMessage pingMessage; - private TaskCompletionSource tsc; - private int numberOfMessages; - private int skipMessages; - private int counter; - - public Ping(IConnectionFactory connectionFactory) - { - this.connection = connectionFactory.CreateConnection(); - this.session = this.connection.CreateSession(); - this.messageProducer = session.CreateProducer(session.GetTopic("ping")); - this.messageConsumer = session.CreateConsumer(session.GetTopic("pong")); - this.messageConsumer.Listener += OnMessage; - this.stopwatch = new Stopwatch(); - this.pingMessage = session.CreateTextMessage("Ping"); - this.connection.Start(); - } - - private void OnMessage(IMessage message) - { - if (skipMessages > 0) - skipMessages--; - else - counter++; - - if (counter == numberOfMessages) - { - stopwatch.Stop(); - this.tsc.SetResult(new Stats { MessagesCount = counter, Elapsed = stopwatch.Elapsed }); - } - else - { - messageProducer.Send(pingMessage); - } - } - - public Task Start(int numberOfMessages, int skipMessages) - { - this.numberOfMessages = numberOfMessages; - this.skipMessages = skipMessages; - this.tsc = new TaskCompletionSource(); - stopwatch.Start(); - messageProducer.Send(pingMessage); - return this.tsc.Task; - } - - public void Dispose() - { - connection?.Dispose(); - } - } -} \ No newline at end of file diff --git a/src/PingPong/PingPong.csproj b/src/PingPong/PingPong.csproj deleted file mode 100644 index b7c8fd1c..00000000 --- a/src/PingPong/PingPong.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Exe - netcoreapp2.1 - False - - - - - - - diff --git a/src/PingPong/Pong.cs b/src/PingPong/Pong.cs deleted file mode 100644 index b1e4500b..00000000 --- a/src/PingPong/Pong.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -using System; -using Apache.NMS; - -namespace PingPong -{ - public class Pong : IDisposable - { - private readonly IConnection connection; - private readonly ISession session; - private readonly IMessageProducer messageProducer; - private readonly IMessageConsumer messageConsumer; - private readonly ITextMessage pongMessage; - - public Pong(IConnectionFactory connectionFactory) - { - this.connection = connectionFactory.CreateConnection(); - this.session = this.connection.CreateSession(); - this.messageProducer = session.CreateProducer(session.GetTopic("pong")); - this.messageConsumer = session.CreateConsumer(session.GetTopic("ping")); - this.messageConsumer.Listener += OnMessage; - this.pongMessage = session.CreateTextMessage("Pong"); - this.connection.Start(); - } - - private void OnMessage(IMessage message) - { - this.messageProducer.Send(pongMessage); - } - - public void Dispose() - { - connection?.Dispose(); - } - } -} \ No newline at end of file diff --git a/src/PingPong/Program.cs b/src/PingPong/Program.cs deleted file mode 100644 index aafbb104..00000000 --- a/src/PingPong/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -using System; -using System.Threading.Tasks; -using Apache.NMS.AMQP; - -namespace PingPong -{ - class Program - { - static async Task Main(string[] args) - { - var connectionFactory = new NmsConnectionFactory(); - connectionFactory.UserName = "artemis"; - connectionFactory.Password = "simetraehcapa"; - - using (var ping = new Ping(connectionFactory)) - using (new Pong(connectionFactory)) - { - var stats = await ping.Start(skipMessages: 100, numberOfMessages: 10000); - Console.WriteLine(stats); - } - } - } -} \ No newline at end of file diff --git a/src/PingPong/Stats.cs b/src/PingPong/Stats.cs deleted file mode 100644 index fbedf7f4..00000000 --- a/src/PingPong/Stats.cs +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -using System; - -namespace PingPong -{ - public class Stats - { - public int MessagesCount { get; set; } - public TimeSpan Elapsed { get; set; } - - public override string ToString() - { - return $"Sent {MessagesCount} msg in {Elapsed.TotalMilliseconds:F2}ms -- {MessagesCount / Elapsed.TotalSeconds:F2} msg/s"; - } - } -} \ No newline at end of file diff --git a/src/StructuredMessage/StructuredMessage.cs b/src/StructuredMessage/StructuredMessage.cs deleted file mode 100644 index d014f3b3..00000000 --- a/src/StructuredMessage/StructuredMessage.cs +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -using System; -using System.Collections.Specialized; -using Apache.NMS; -using Apache.NMS.AMQP; -using CommandLine; - -namespace StructuredMessage -{ - class CommandLineOpts - { - // URI for message broker. Must be of the format amqp://: or amqps://: - [Option("uri", Required = true, HelpText = "The URI for the AMQP Message Broker")] - public string host { get; set; } - // Connection Request Timeout - [Option("ct", Default = 15000, HelpText = "the connection request timeout in milliseconds.")] - public long connTimeout { get; set; } - // UserName for authentication with the broker. - [Option("cu", Default = null, HelpText = "The Username for authentication with the message broker")] - public string username { get; set; } - // Password for authentication with the broker - [Option("cpwd", Default = null, HelpText = "The password for authentication with the message broker")] - public string password { get; set; } - [Option("cid", Default = null, HelpText = "The Client ID on the connection")] - public string clientId { get; set; } - // Logging Level - [Option("log", Default = "warn", HelpText = "Sets the log level for the application and NMS Library. The levels are (from highest verbosity): debug,info,warn,error,fatal.")] - public string logLevel { get; set; } - // - [Option("topic", Default = null, HelpText = "Topic to publish messages to. Can not be used with --queue.")] - public string topic { get; set; } - // - [Option("queue", Default = null, HelpText = "Queue to publish messages to. Can not be used with --topic.")] - public string queue { get; set; } - // - [Option("deliveryMode", Default = 5, HelpText = "Message Delivery Mode, Persistnent(0) and Non Persistent(1). The default is Persistent(0).")] - public int mode { get; set; } - } - class Program - { - - private static void RunWithOptions (CommandLineOpts opts) - { - ITrace logger = new Logger(Logger.ToLogLevel(opts.logLevel)); - Tracer.Trace = logger; - - string ip = opts.host; - Uri providerUri = new Uri(ip); - Console.WriteLine("scheme: {0}", providerUri.Scheme); - - IConnection conn = null; - if (opts.topic == null && opts.queue == null) - { - Console.WriteLine("ERROR: Must specify a topic or queue destination"); - return; - } - try - { - NmsConnectionFactory factory = new NmsConnectionFactory(ip); - if (opts.username != null) - { - factory.UserName = opts.username; - } - if (opts.password != null) - { - factory.Password = opts.password; - } - if (opts.clientId != null) - { - factory.ClientId = opts.clientId; - } - - if (opts.connTimeout != default) - { - factory.SendTimeout = opts.connTimeout; - } - - Console.WriteLine("Creating Connection..."); - conn = factory.CreateConnection(); - conn.ExceptionListener += (logger as Logger).LogException; - Console.WriteLine("Created Connection."); - Console.WriteLine("Version: {0}", conn.MetaData); - Console.WriteLine("Creating Session..."); - ISession ses = conn.CreateSession(); - Console.WriteLine("Session Created."); - - conn.Start(); - IDestination dest = (opts.topic==null) ? (IDestination)ses.GetQueue(opts.queue) : (IDestination)ses.GetTopic(opts.topic); - Console.WriteLine("Creating Message Producer for : {0}...", dest); - IMessageProducer prod = ses.CreateProducer(dest); - IMessageConsumer consumer = ses.CreateConsumer(dest); - Console.WriteLine("Created Message Producer."); - prod.DeliveryMode = opts.mode == 0 ? MsgDeliveryMode.NonPersistent : MsgDeliveryMode.Persistent; - prod.TimeToLive = TimeSpan.FromSeconds(20); - IMapMessage mapMsg = prod.CreateMapMessage(); - IStreamMessage streamMsg = prod.CreateStreamMessage(); - - Console.WriteLine("Starting Connection..."); - conn.Start(); - Console.WriteLine("Connection Started: {0} Resquest Timeout: {1}", conn.IsStarted, conn.RequestTimeout); - Tracer.InfoFormat("Sending MapMsg"); - // Map Msg Body - mapMsg.Body.SetString("mykey", "Hello World!"); - mapMsg.Body.SetBytes("myBytesKey", new byte[] { 0x6d, 0x61, 0x70 }); - Console.WriteLine("Sending Msg: {0}", mapMsg.ToString()); - prod.Send(mapMsg); - mapMsg.ClearBody(); - - // Stream Msg Body - streamMsg.WriteBytes(new byte[] { 0x53, 0x74, 0x72}); - streamMsg.WriteInt64(1354684651565648484L); - streamMsg.WriteObject("bar"); - streamMsg.Properties["foobar"] = 42 + ""; - Console.WriteLine("Sending Msg: {0}", streamMsg.ToString()); - prod.Send(streamMsg); - streamMsg.ClearBody(); - - IMessage rmsg = null; - for (int i = 0; i < 2; i++) - { - Tracer.InfoFormat("Waiting to receive message {0} from consumer.", i); - rmsg = consumer.Receive(TimeSpan.FromMilliseconds(opts.connTimeout)); - if(rmsg == null) - { - Console.WriteLine("Failed to receive Message in {0}ms.", opts.connTimeout); - } - else - { - Console.WriteLine("Received Message with id {0} and contents {1}.", rmsg.NMSMessageId, rmsg.ToString()); - foreach (string key in rmsg.Properties.Keys) - { - Console.WriteLine("Message contains Property[{0}] = {1}", key, rmsg.Properties[key].ToString()); - } - } - } - if (conn.IsStarted) - { - Console.WriteLine("Closing Connection..."); - conn.Close(); - Console.WriteLine("Connection Closed."); - } - } - catch(NMSException ne) - { - Console.WriteLine("Caught NMSException : {0} \nStack: {1}", ne.Message, ne); - } - catch (Exception e) - { - Console.WriteLine("Caught unexpected exception : {0}", e); - } - finally - { - if(conn != null) - { - conn.Dispose(); - } - } - } - - static void Main(string[] args) - { - CommandLineOpts opts = new CommandLineOpts(); - ParserResult result = CommandLine.Parser.Default.ParseArguments(args) - .WithParsed(options => RunWithOptions(options)); - } - } - - #region Logging - - class Logger : ITrace - { - public enum LogLevel - { - OFF = -1, - FATAL, - ERROR, - WARN, - INFO, - DEBUG - } - - public static LogLevel ToLogLevel(string logString) - { - if(logString == null || logString.Length == 0) - { - return LogLevel.OFF; - } - if ("FATAL".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.FATAL; - } - else if ("ERROR".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.ERROR; - } - else if ("WARN".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.WARN; - } - else if ("INFO".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.INFO; - } - else if ("DEBUG".StartsWith(logString, StringComparison.CurrentCultureIgnoreCase)) - { - return LogLevel.DEBUG; - } - else - { - return LogLevel.OFF; - } - } - - private LogLevel lv; - - public void LogException(Exception ex) - { - this.Warn("Exception: "+ex.Message); - } - - public Logger() : this(LogLevel.WARN) - { - } - - public Logger(LogLevel lvl) - { - lv = lvl; - } - - public bool IsDebugEnabled - { - get - { - return lv >= LogLevel.DEBUG; - } - } - - public bool IsErrorEnabled - { - get - { - - return lv >= LogLevel.ERROR; - } - } - - public bool IsFatalEnabled - { - get - { - return lv >= LogLevel.FATAL; - } - } - - public bool IsInfoEnabled - { - get - { - return lv >= LogLevel.INFO; - } - } - - public bool IsWarnEnabled - { - get - { - return lv >= LogLevel.WARN; - } - } - - public void Debug(string message) - { - if(IsDebugEnabled) - Console.WriteLine("Debug: {0}", message); - } - - public void Error(string message) - { - if (IsErrorEnabled) - Console.WriteLine("Error: {0}", message); - } - - public void Fatal(string message) - { - if (IsFatalEnabled) - Console.WriteLine("Fatal: {0}", message); - } - - public void Info(string message) - { - if (IsInfoEnabled) - Console.WriteLine("Info: {0}", message); - } - - public void Warn(string message) - { - if (IsWarnEnabled) - Console.WriteLine("Warn: {0}", message); - } - } - #endregion -} diff --git a/src/StructuredMessage/StructuredMessage.csproj b/src/StructuredMessage/StructuredMessage.csproj deleted file mode 100644 index 91b5f8d4..00000000 --- a/src/StructuredMessage/StructuredMessage.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - - net462;netcoreapp2.1 - $(AppTargetFramework) - Exe - StructuredMessage - StructuredMessage - 7.3 - False - - - - - - - - - - diff --git a/src/Transactions/Program.cs b/src/Transactions/Program.cs deleted file mode 100644 index 625d2a3c..00000000 --- a/src/Transactions/Program.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -using System; -using Apache.NMS; -using Apache.NMS.AMQP; - -namespace Transactions -{ - static class Program - { - static void Main(string[] args) - { - Console.WriteLine("NMS-AMQP Transactions Example"); - - var connectionFactory = new NmsConnectionFactory("admin", "admin", "amqp://127.0.0.1:5672"); - var connection = connectionFactory.CreateConnection(); - connection.ClientId = "TransactionsExampleSender"; - - var session = connection.CreateSession(AcknowledgementMode.Transactional); - var queue = session.GetQueue("TransactionQueue"); - var producer = session.CreateProducer(queue); - - for (int i = 1; i <= 5; i++) - { - ITextMessage message = producer.CreateTextMessage($"Message {i}"); - producer.Send(message); - Console.WriteLine("Sent message " + i); - } - - session.Rollback(); - Console.WriteLine("Rollback"); - - for (int i = 6; i <= 10; i++) - { - ITextMessage message = producer.CreateTextMessage($"Message {i}"); - producer.Send(message); - Console.WriteLine("Sent message " + i); - } - - session.Commit(); - - var consumer = session.CreateConsumer(queue); - - connection.Start(); - - for (int i = 0; i < 5; i++) - { - var message = consumer.Receive() as ITextMessage; - Console.WriteLine("Message " + message.Text + " received"); - } - - Console.ReadKey(); - - producer.Close(); - session.Close(); - connection.Close(); - - Console.WriteLine("Press any key to exit."); - Console.ReadKey(); - } - } -} \ No newline at end of file diff --git a/src/Transactions/Transactions.csproj b/src/Transactions/Transactions.csproj deleted file mode 100644 index 76005c45..00000000 --- a/src/Transactions/Transactions.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Exe - netcoreapp2.1 - $(AppTargetFramework) - False - - - - - -