diff --git a/assembly/src/release/examples/openwire/cpp/Listener.cpp b/assembly/src/release/examples/openwire/cpp/Listener.cpp new file mode 100644 index 0000000000..d5d0c784f6 --- /dev/null +++ b/assembly/src/release/examples/openwire/cpp/Listener.cpp @@ -0,0 +1,126 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace activemq; +using namespace activemq::core; +using namespace decaf::lang; +using namespace cms; +using namespace std; + +//////////////////////////////////////////////////////////////////////////////// +std::string getEnv(const std::string& key, const std::string& defaultValue) { + + try{ + return System::getenv(key); + } catch(...) { + } + + return defaultValue; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string getArg(char* argv[], int argc, int index, const std::string& defaultValue) { + + if( index < argc ) { + return argv[index]; + } + + return defaultValue; +} + +//////////////////////////////////////////////////////////////////////////////// +int main(int argc AMQCPP_UNUSED, char* argv[] AMQCPP_UNUSED) { + + activemq::library::ActiveMQCPP::initializeLibrary(); + + std::cout << "=====================================================\n"; + std::cout << "Starting the Listener example:" << std::endl; + std::cout << "-----------------------------------------------------\n"; + + std::string user = getEnv("ACTIVEMQ_USER", "admin"); + std::string password = getEnv("ACTIVEMQ_PASSWORD", "password"); + std::string host = getEnv("ACTIVEMQ_HOST", "localhost"); + int port = Integer::parseInt(getEnv("ACTIVEMQ_PORT", "61616")); + std::string destination = getArg(argv, argc, 1, "event"); + + { + ActiveMQConnectionFactory factory; + factory.setBrokerURI(std::string("tcp://") + host + ":" + Integer::toString(port)); + + std::auto_ptr connection(factory.createConnection(user, password)); + + std::auto_ptr session(connection->createSession()); + std::auto_ptr dest(session->createTopic(destination)); + std::auto_ptr consumer(session->createConsumer(dest.get())); + + connection->start(); + + long long start = System::currentTimeMillis(); + long long count = 0; + + std::cout << "Waiting for messages..." << std::endl; + while(true) { + + std::auto_ptr message(consumer->receive()); + + const TextMessage* txtMsg = dynamic_cast(message.get()); + + if( txtMsg != NULL ) { + std::string body = txtMsg->getText(); + if( body == "SHUTDOWN" ) { + long long diff = System::currentTimeMillis() - start; + cout << "Received " << count << " in " << (double)diff/1000.0 << " seconds" << std::endl; + break; + } else { + if( count == 0 ) { + start = System::currentTimeMillis(); + } + count++; + if( count % 1000 == 0 ) { + std::cout << "Received " << count << " messages." << std::endl; + } + } + + } else { + std::cout << "Unexpected message type." << std::endl; + } + } + + connection->close(); + } + + std::cout << "-----------------------------------------------------\n"; + std::cout << "Finished with the example." << std::endl; + std::cout << "=====================================================\n"; + + activemq::library::ActiveMQCPP::shutdownLibrary(); +} diff --git a/assembly/src/release/examples/openwire/cpp/Publisher.cpp b/assembly/src/release/examples/openwire/cpp/Publisher.cpp new file mode 100644 index 0000000000..9001726548 --- /dev/null +++ b/assembly/src/release/examples/openwire/cpp/Publisher.cpp @@ -0,0 +1,120 @@ +/* + * 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace cms; +using namespace activemq; +using namespace activemq::core; +using namespace decaf; +using namespace decaf::lang; + +//////////////////////////////////////////////////////////////////////////////// +std::string getEnv(const std::string& key, const std::string& defaultValue) { + + try{ + return System::getenv(key); + } catch(...) { + } + + return defaultValue; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string getArg(char* argv[], int argc, int index, const std::string& defaultValue) { + + if( index < argc ) { + return argv[index]; + } + + return defaultValue; +} + +//////////////////////////////////////////////////////////////////////////////// +int main(int argc, char* argv[]) { + + activemq::library::ActiveMQCPP::initializeLibrary(); + + std::cout << "=====================================================\n"; + std::cout << "Starting the Publisher example:" << std::endl; + std::cout << "-----------------------------------------------------\n"; + + std::string user = getEnv("ACTIVEMQ_USER", "admin"); + std::string password = getEnv("ACTIVEMQ_PASSWORD", "password"); + std::string host = getEnv("ACTIVEMQ_HOST", "localhost"); + int port = Integer::parseInt(getEnv("ACTIVEMQ_PORT", "61616")); + std::string destination = getArg(argv, argc, 1, "event"); + + int messages = 10000; + int size = 256; + + std::string DATA = "abcdefghijklmnopqrstuvwxyz"; + std::string body = ""; + for( int i=0; i < size; i ++) { + body += DATA.at(i%DATA.length()); + } + + { + ActiveMQConnectionFactory factory; + factory.setBrokerURI(std::string("tcp://") + host + ":" + Integer::toString(port)); + + std::auto_ptr message; + std::auto_ptr connection(factory.createConnection(user, password)); + + connection->start(); + + std::auto_ptr session(connection->createSession()); + std::auto_ptr dest(session->createTopic(destination)); + std::auto_ptr producer(session->createProducer(dest.get())); + + producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); + + for( int i=1; i <= messages; i ++) { + message.reset(session->createTextMessage(body)); + producer->send(message.get()); + if( (i % 1000) == 0) { + std::cout << "Sent " << i << " messages" << std::endl;; + } + } + + message.reset(session->createTextMessage("SHUTDOWN")); + producer->send(message.get()); + + connection->close(); + } + + std::cout << "-----------------------------------------------------\n"; + std::cout << "Finished with the example." << std::endl; + std::cout << "=====================================================\n"; + + activemq::library::ActiveMQCPP::shutdownLibrary(); +} diff --git a/assembly/src/release/examples/openwire/cpp/readme.md b/assembly/src/release/examples/openwire/cpp/readme.md new file mode 100644 index 0000000000..3ea59ce91b --- /dev/null +++ b/assembly/src/release/examples/openwire/cpp/readme.md @@ -0,0 +1,42 @@ +Prereqs +======= + +These examples use the [ActiveMQ-CPP](http://activemq.apache.org/cms) C++ library, + + +1. [Download the latest release from the ActiveMQ-CPP website) +2. [Build and Install](http://activemq.apache.org/cms/building.html) + +Building +======== + +This will vary depending on where you installed your libraries and the compiler +you are using but on my Ubuntu system, I compiled the examples as follows: + + gcc Listener.cpp -o listener -I/usr/local/include/activemq-cpp-3.8.1 -I/usr/include/apr-1.0 -lactivemq-cpp -lstdc++ + gcc Publisher.cpp -o publisher -I/usr/local/include/activemq-cpp-3.8.1 -I/usr/include/apr-1.0 -lactivemq-cpp -lstdc++ + +Running the Examples +==================== + +Note: You may need to update set an environment variable so that the +activemq-cpp shared libraries can be loaded. For example on my Ubuntu +system I had to add the following to my profile: + + export LD_LIBRARY_PATH=/usr/local/lib + +In one terminal window run: + + ./listener + +In another terminal window run: + + ./publisher + +You can control to which stomp server the examples try to connect to by +setting the following environment variables: + +* `ACTIVEMQ_HOST` +* `ACTIVEMQ_PORT` +* `ACTIVEMQ_USER` +* `ACTIVEMQ_PASSWORD` diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.sln b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.sln new file mode 100644 index 0000000000..ade0d240e3 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Publisher", "Publisher\Publisher.csproj", "{0FEEC122-F3FD-4148-A461-0A724AE0C691}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Listener", "Listener\Listener.csproj", "{08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}.Debug|x86.ActiveCfg = Debug|x86 + {08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}.Debug|x86.Build.0 = Debug|x86 + {08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}.Release|x86.ActiveCfg = Release|x86 + {08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}.Release|x86.Build.0 = Release|x86 + {0FEEC122-F3FD-4148-A461-0A724AE0C691}.Debug|x86.ActiveCfg = Debug|x86 + {0FEEC122-F3FD-4148-A461-0A724AE0C691}.Debug|x86.Build.0 = Debug|x86 + {0FEEC122-F3FD-4148-A461-0A724AE0C691}.Release|x86.ActiveCfg = Release|x86 + {0FEEC122-F3FD-4148-A461-0A724AE0C691}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Listener\Listener.csproj + EndGlobalSection +EndGlobal diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.userprefs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.userprefs new file mode 100644 index 0000000000..6a204c8be6 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/ActiveMQExamples.userprefs @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/AssemblyInfo.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/AssemblyInfo.cs new file mode 100644 index 0000000000..a1f96a9a3f --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/AssemblyInfo.cs @@ -0,0 +1,44 @@ +/** + * 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.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Listener")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.cs new file mode 100644 index 0000000000..dd6c1248dd --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.cs @@ -0,0 +1,106 @@ +/* + * 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.ActiveMQ; + +namespace ActiveMQ.Example +{ + class Listemer + { + public static void Main(string[] args) + { + Console.WriteLine("Starting up Listener."); + + String user = env("ACTIVEMQ_USER", "admin"); + String password = env("ACTIVEMQ_PASSWORD", "password"); + String host = env("ACTIVEMQ_HOST", "localhost"); + int port = Int32.Parse(env("ACTIVEMQ_PORT", "61616")); + String destination = arg(args, 0, "event"); + + String brokerUri = "activemq:tcp://" + host + ":" + port + "?transport.useLogging=true"; + NMSConnectionFactory factory = new NMSConnectionFactory(brokerUri); + + IConnection connection = factory.CreateConnection(user, password); + connection.Start(); + ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); + IDestination dest = session.GetTopic(destination); + + IMessageConsumer consumer = session.CreateConsumer(dest); + DateTime start = DateTime.Now; + long count = 0; + + Console.WriteLine("Waiting for messages..."); + while (true) + { + IMessage msg = consumer.Receive(); + if (msg is ITextMessage) + { + ITextMessage txtMsg = msg as ITextMessage; + String body = txtMsg.Text; + if ("SHUTDOWN".Equals(body)) + { + TimeSpan diff = DateTime.Now - start; + Console.WriteLine(String.Format("Received {0} in {1} seconds", count, (1.0*diff.TotalMilliseconds/1000.0))); + break; + } + else + { + if (count == 0) + { + start = DateTime.Now; + } + count ++; + if (count % 1000 == 0) + { + Console.WriteLine(String.Format("Received {0} messages.", count)); + } + } + + } + else + { + Console.WriteLine("Unexpected message type: " + msg.GetType().Name); + } + } + + Console.WriteLine("Shutting down Listener."); + connection.Close(); + } + + private static String env(String key, String defaultValue) + { + String rc = System.Environment.GetEnvironmentVariable(key); + if (rc == null) + { + return defaultValue; + } + return rc; + } + + private static String arg(String []args, int index, String defaultValue) + { + if (index < args.Length) + { + return args[index]; + } + return defaultValue; + } + } +} diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.csproj b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.csproj new file mode 100644 index 0000000000..2fe971c0d2 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/Listener.csproj @@ -0,0 +1,52 @@ + + + + Debug + x86 + 9.0.21022 + 2.0 + {08413D64-4C72-4F92-9B4A-9BAECCDB6DC3} + Exe + Listener + Listener + v3.5 + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + x86 + true + + + none + false + bin\Release + prompt + 4 + x86 + true + + + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\Apache.NMS\mono-2.0\Apache.NMS.dll + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\DotNetZip\mono-2.0\Ionic.Zlib.dll + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\build\mono-2.0\debug\Apache.NMS.ActiveMQ.dll + + + + + + + + + \ No newline at end of file diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/NMSTracer.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/NMSTracer.cs new file mode 100755 index 0000000000..b37af66ac3 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Listener/NMSTracer.cs @@ -0,0 +1,78 @@ +/* + * 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 ActiveMQ.Example +{ + public class NmsTracer : Apache.NMS.ITrace + { + #region ITrace Members + public void Debug(string message) + { + Console.WriteLine("DEBUG: " + message); + } + + public void Error(string message) + { + Console.WriteLine("ERROR: " + message); + } + + public void Fatal(string message) + { + Console.WriteLine("FATAL: " + message); + } + + public void Info(string message) + { + Console.WriteLine("INFO: " + message); + } + + public void Warn(string message) + { + Console.WriteLine("WARN: " + message); + } + + public bool IsDebugEnabled + { + get { return true; } + } + + public bool IsErrorEnabled + { + get { return true; } + } + + public bool IsFatalEnabled + { + get { return true; } + } + + public bool IsInfoEnabled + { + get { return true; } + } + + public bool IsWarnEnabled + { + get { return true; } + } + + #endregion + } +} + diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/AssemblyInfo.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/AssemblyInfo.cs new file mode 100644 index 0000000000..2628d121cb --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/AssemblyInfo.cs @@ -0,0 +1,44 @@ +/** + * 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.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Publisher")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/NMSTracer.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/NMSTracer.cs new file mode 100755 index 0000000000..b37af66ac3 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/NMSTracer.cs @@ -0,0 +1,78 @@ +/* + * 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 ActiveMQ.Example +{ + public class NmsTracer : Apache.NMS.ITrace + { + #region ITrace Members + public void Debug(string message) + { + Console.WriteLine("DEBUG: " + message); + } + + public void Error(string message) + { + Console.WriteLine("ERROR: " + message); + } + + public void Fatal(string message) + { + Console.WriteLine("FATAL: " + message); + } + + public void Info(string message) + { + Console.WriteLine("INFO: " + message); + } + + public void Warn(string message) + { + Console.WriteLine("WARN: " + message); + } + + public bool IsDebugEnabled + { + get { return true; } + } + + public bool IsErrorEnabled + { + get { return true; } + } + + public bool IsFatalEnabled + { + get { return true; } + } + + public bool IsInfoEnabled + { + get { return true; } + } + + public bool IsWarnEnabled + { + get { return true; } + } + + #endregion + } +} + diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.cs b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.cs new file mode 100644 index 0000000000..2a3a88d65b --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.cs @@ -0,0 +1,87 @@ +/* + * 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.ActiveMQ; + +namespace ActiveMQ.Example +{ + class Publisher + { + public static void Main (string[] args) + { + String user = env("ACTIVEMQ_USER", "admin"); + String password = env("ACTIVEMQ_PASSWORD", "password"); + String host = env("ACTIVEMQ_HOST", "localhost"); + int port = Int32.Parse(env("ACTIVEMQ_PORT", "61616")); + String destination = arg(args, 0, "event"); + + int messages = 10000; + int size = 256; + + String DATA = "abcdefghijklmnopqrstuvwxyz"; + String body = ""; + for(int i=0; i < size; i ++) + { + body += DATA[i%DATA.Length]; + } + + String brokerUri = "activemq:tcp://" + host + ":" + port; + NMSConnectionFactory factory = new NMSConnectionFactory(brokerUri); + + IConnection connection = factory.CreateConnection(user, password); + connection.Start(); + ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); + IDestination dest = session.GetTopic(destination); + IMessageProducer producer = session.CreateProducer(dest); + producer.DeliveryMode = MsgDeliveryMode.NonPersistent; + + for (int i=1; i <= messages; i ++) + { + producer.Send(session.CreateTextMessage(body)); + if ((i % 1000) == 0) + { + Console.WriteLine(String.Format("Sent {0} messages", i)); + } + } + + producer.Send(session.CreateTextMessage("SHUTDOWN")); + connection.Close(); + } + + private static String env(String key, String defaultValue) + { + String rc = System.Environment.GetEnvironmentVariable(key); + if (rc == null) + { + return defaultValue; + } + return rc; + } + + private static String arg(String []args, int index, String defaultValue) + { + if (index < args.Length) + { + return args[index]; + } + return defaultValue; + } + } +} diff --git a/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.csproj b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.csproj new file mode 100644 index 0000000000..1d4dfd7196 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/ActiveMQExamples/Publisher/Publisher.csproj @@ -0,0 +1,52 @@ + + + + Debug + x86 + 9.0.21022 + 2.0 + {0FEEC122-F3FD-4148-A461-0A724AE0C691} + Exe + Publisher + Publisher + v3.5 + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + x86 + true + + + none + false + bin\Release + prompt + 4 + x86 + true + + + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\build\mono-2.0\debug\Apache.NMS.ActiveMQ.dll + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\Apache.NMS\mono-2.0\Apache.NMS.dll + + + ..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\DotNetZip\mono-2.0\Ionic.Zlib.dll + + + + + + + + + \ No newline at end of file diff --git a/assembly/src/release/examples/openwire/csharp/readme.md b/assembly/src/release/examples/openwire/csharp/readme.md new file mode 100644 index 0000000000..73b9ab01d2 --- /dev/null +++ b/assembly/src/release/examples/openwire/csharp/readme.md @@ -0,0 +1,33 @@ +Prereqs +======= + +- Install [Apache.NMS.ActiveMQ](http://activemq.apache.org/nms/download.html) + +Building +======== + +This will vary depending on where you installed your libraries. Open the +ActiveMQExamples solution in Visual Studio and update the references for the +Listener and Publisher project to point to where you Apache.NMS.dll, +Apache.NMS.ActiveMQ.dll and Ionic.Zlib.dll are located. + +Build both projects in the solution. + +Running the Examples +==================== + +In one terminal window run: + + ./Listener.exe + +In another terminal window run: + + ./Publisher.exe + +You can control to which ActiveMQ server the examples try to connect to by +setting the following environment variables: + +* `ACTIVEMQ_HOST` +* `ACTIVEMQ_PORT` +* `ACTIVEMQ_USER` +* `ACTIVEMQ_PASSWORD`