mirror of https://github.com/apache/activemq.git
Add in C++ and CSharp examples for Openwire
This commit is contained in:
parent
b4dafca869
commit
a912d6d5ce
|
@ -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 <activemq/core/ActiveMQConnectionFactory.h>
|
||||
#include <activemq/core/ActiveMQConnection.h>
|
||||
#include <activemq/library/ActiveMQCPP.h>
|
||||
#include <decaf/lang/Integer.h>
|
||||
#include <decaf/lang/System.h>
|
||||
#include <activemq/util/Config.h>
|
||||
#include <cms/Connection.h>
|
||||
#include <cms/Session.h>
|
||||
#include <cms/Destination.h>
|
||||
#include <cms/MessageProducer.h>
|
||||
#include <cms/TextMessage.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
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> connection(factory.createConnection(user, password));
|
||||
|
||||
std::auto_ptr<Session> session(connection->createSession());
|
||||
std::auto_ptr<Destination> dest(session->createTopic(destination));
|
||||
std::auto_ptr<MessageConsumer> 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> message(consumer->receive());
|
||||
|
||||
const TextMessage* txtMsg = dynamic_cast<const TextMessage*>(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();
|
||||
}
|
|
@ -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 <activemq/util/Config.h>
|
||||
|
||||
#include <decaf/lang/System.h>
|
||||
#include <decaf/lang/Runnable.h>
|
||||
#include <decaf/lang/Integer.h>
|
||||
#include <activemq/core/ActiveMQConnectionFactory.h>
|
||||
#include <activemq/library/ActiveMQCPP.h>
|
||||
#include <cms/Connection.h>
|
||||
#include <cms/Session.h>
|
||||
#include <cms/Destination.h>
|
||||
#include <cms/MessageProducer.h>
|
||||
#include <cms/TextMessage.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
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<TextMessage> message;
|
||||
std::auto_ptr<Connection> connection(factory.createConnection(user, password));
|
||||
|
||||
connection->start();
|
||||
|
||||
std::auto_ptr<Session> session(connection->createSession());
|
||||
std::auto_ptr<Destination> dest(session->createTopic(destination));
|
||||
std::auto_ptr<MessageProducer> 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();
|
||||
}
|
|
@ -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`
|
|
@ -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
|
|
@ -0,0 +1,29 @@
|
|||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Publisher/Publisher.cs">
|
||||
<Files>
|
||||
<File FileName="Listener/Listener.cs" Line="35" Column="17" />
|
||||
<File FileName="Publisher/Publisher.cs" Line="21" Column="26" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="ProjectPad">
|
||||
<State expanded="True">
|
||||
<Node name="Listener" expanded="True">
|
||||
<Node name="References" expanded="True" />
|
||||
</Node>
|
||||
<Node name="Publisher" expanded="True">
|
||||
<Node name="References" expanded="True" />
|
||||
<Node name="Publisher.cs" selected="True" />
|
||||
</Node>
|
||||
</State>
|
||||
</Pad>
|
||||
<Pad Id="ClassPad">
|
||||
<State selected="True" />
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||
</Properties>
|
|
@ -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("")]
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{08413D64-4C72-4F92-9B4A-9BAECCDB6DC3}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Listener</RootNamespace>
|
||||
<AssemblyName>Listener</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Apache.NMS">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\Apache.NMS\mono-2.0\Apache.NMS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ionic.Zlib">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\DotNetZip\mono-2.0\Ionic.Zlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Apache.NMS.ActiveMQ">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\build\mono-2.0\debug\Apache.NMS.ActiveMQ.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Listener.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="NMSTracer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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("")]
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0FEEC122-F3FD-4148-A461-0A724AE0C691}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Publisher</RootNamespace>
|
||||
<AssemblyName>Publisher</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Apache.NMS.ActiveMQ">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\build\mono-2.0\debug\Apache.NMS.ActiveMQ.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Apache.NMS">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\Apache.NMS\mono-2.0\Apache.NMS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ionic.Zlib">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\..\activemq\NMS.ActiveMQ\lib\DotNetZip\mono-2.0\Ionic.Zlib.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Publisher.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="NMSTracer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -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`
|
Loading…
Reference in New Issue