Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehadlow committed Apr 8, 2011
0 parents commit 1203dc0
Show file tree
Hide file tree
Showing 36 changed files with 16,169 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Oo]bj
[Bb]in
*.user
*.suo
*.[Cc]ache
*.bak
*.ncb
*.log
*.DS_Store
[Tt]humbs.db
_ReSharper.*
Binary file added ActiveMQ/Apache.NMS.ActiveMQ.Test.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions ActiveMQ/Apache.NMS.ActiveMQ.Test.nunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<NUnitProject>
<Settings activeconfig="Default" />
<Config name="Default" binpathtype="Auto">
<assembly path="Apache.NMS.Test.dll" />
<assembly path="Apache.NMS.ActiveMQ.Test.dll" />
</Config>
</NUnitProject>
Binary file added ActiveMQ/Apache.NMS.ActiveMQ.Test.pdb
Binary file not shown.
15 changes: 15 additions & 0 deletions ActiveMQ/Apache.NMS.ActiveMQ.Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added ActiveMQ/Apache.NMS.ActiveMQ.dll
Binary file not shown.
Binary file added ActiveMQ/Apache.NMS.ActiveMQ.pdb
Binary file not shown.
8,096 changes: 8,096 additions & 0 deletions ActiveMQ/Apache.NMS.ActiveMQ.xml

Large diffs are not rendered by default.

Binary file added ActiveMQ/Apache.NMS.Test.dll
Binary file not shown.
Binary file added ActiveMQ/Apache.NMS.Test.pdb
Binary file not shown.
Binary file added ActiveMQ/Apache.NMS.dll
Binary file not shown.
Binary file added ActiveMQ/Apache.NMS.pdb
Binary file not shown.
33 changes: 33 additions & 0 deletions ActiveMQ/nmsprovider-test.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
* 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.
-->
<configuration>
<defaultURI value="activemq:tcp://${activemqhost}:61616?connection.AsyncClose=false">
<userName value="system"/>
<passWord value="manager"/>
</defaultURI>

<maxInactivityDurationURI value="activemq:tcp://${activemqhost}:61616?wireFormat.MaxInactivityDurationInitialDelay=5000&amp;wireFormat.MaxInactivityDuration=10000&amp;connection.AsyncClose=false"/>

<openWireURI value="activemq:tcp://${activemqhost}:61616?connection.AsyncClose=false">
<factoryParams>
<param type="string" value="OpenWireTestClient"/>
</factoryParams>
<userName value="guest"/>
<passWord value="guest"/>
</openWireURI>
</configuration>
20 changes: 20 additions & 0 deletions Mike.MQShootout.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mike.MQShootout", "Mike.MQShootout\Mike.MQShootout.csproj", "{A376D26C-8181-4C2B-95B3-8D310CB4D809}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A376D26C-8181-4C2B-95B3-8D310CB4D809}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A376D26C-8181-4C2B-95B3-8D310CB4D809}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A376D26C-8181-4C2B-95B3-8D310CB4D809}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A376D26C-8181-4C2B-95B3-8D310CB4D809}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
73 changes: 73 additions & 0 deletions Mike.MQShootout/ActiveMq.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Apache.NMS;
using Apache.NMS.ActiveMQ.Commands;

namespace Mike.MQShootout
{
public class ActiveMq : IMessageSender<byte[]>, IMessageReceiver<byte[]>, IDisposable
{
private readonly IConnection connection;
private readonly ISession session;
private readonly ITopic topic;
private readonly IMessageProducer sender;
private IMessageConsumer receiver;

private const string brokerUri = "tcp://localhost:61616";

public ActiveMq()
{
var connectionFactory = new NMSConnectionFactory(brokerUri);
connection = connectionFactory.CreateConnection();
connection.Start();
session = connection.CreateSession();

// need to create session
topic = new ActiveMQTopic("testTopic");
sender = session.CreateProducer(topic);
}

public void Send(byte[] message)
{
var bytesMessage = sender.CreateBytesMessage(message);
sender.Send(bytesMessage);
}

public void ReceiveMessage(Action<byte[]> messageReceiver)
{
receiver = session.CreateConsumer(topic);
receiver.Listener += message =>
{
var byteMessage = message as IBytesMessage;
if (byteMessage == null)
{
throw new ApplicationException("byteMessage was null");
}
messageReceiver(byteMessage.Content);
};
}

private bool disposed = false;
public void Dispose()
{
if (disposed) return;

sender.Close();
sender.Dispose();

if (receiver != null)
{
receiver.Close();
receiver.Dispose();
}

session.Close();
session.Dispose();

connection.Stop();
connection.Close();
connection.Dispose();

disposed = true;
}
}
}
9 changes: 9 additions & 0 deletions Mike.MQShootout/IMessageReceiver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Mike.MQShootout
{
public interface IMessageReceiver<T>
{
void ReceiveMessage(Action<T> messageReceiver);
}
}
8 changes: 8 additions & 0 deletions Mike.MQShootout/IMessageSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Mike.MQShootout
{
public interface IMessageSender<in T>
{
// send should be an async operation
void Send(T message);
}
}
70 changes: 70 additions & 0 deletions Mike.MQShootout/MessageReceivingMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Diagnostics;
using System.Threading;

namespace Mike.MQShootout
{
public class MessageReceivingMachine
{
private readonly IMessageReceiver<byte[]> messageReceiver;
private readonly long numberOfMessages;

public MessageReceivingMachine(IMessageReceiver<byte[]> messageReceiver, long numberOfMessages)
{
this.messageReceiver = messageReceiver;
this.messageReceiver.ReceiveMessage(ReceiveMessage);
this.numberOfMessages = numberOfMessages;
}

private bool started = false;
private bool completed = false;
private long messageCounter = 0;
private readonly Stopwatch stopwatch = new Stopwatch();
private readonly object theLock = new object();

private void ReceiveMessage(byte[] message)
{
if (!started)
{
lock (theLock)
{
if (!started)
{
started = true;
stopwatch.Start();
}
}
}

Interlocked.Increment(ref messageCounter);

if (messageCounter == numberOfMessages)
{
lock (theLock)
{
stopwatch.Stop();
var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
Console.WriteLine("{0} messages received in {1} ms", numberOfMessages, elapsedMilliseconds);
Console.WriteLine("Received {0} per second", elapsedMilliseconds == 0 ? 0L : (1000 * numberOfMessages) / elapsedMilliseconds);
completed = true;
}
}
}

public void WaitForCompletion()
{
while (NotCompleted())
{
Thread.Sleep(100);
}
}

private bool NotCompleted()
{
lock (theLock)
{
return !completed;
}
}
}
}
39 changes: 39 additions & 0 deletions Mike.MQShootout/MessageSendingMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Diagnostics;

namespace Mike.MQShootout
{
public class MessageSendingMachine
{
private readonly IMessageSender<byte[]> messageSender;
private const long reportingInterval = 1000000;

public MessageSendingMachine(IMessageSender<byte[]> messageSender)
{
this.messageSender = messageSender;
}

public void RunTest(int messageSize, long numberToSend)
{
var message = new byte[messageSize];

var stopwatch = new Stopwatch();
stopwatch.Start();

for (long i = 0; i < numberToSend; i++)
{
if (i%reportingInterval == 0)
{
Console.WriteLine("Sent {0}", i);
}

messageSender.Send(message);
}

stopwatch.Stop();
var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
Console.WriteLine("Sent {0} messages in {1} ms", numberToSend, elapsedMilliseconds);
Console.WriteLine("{0} per second", elapsedMilliseconds == 0 ? 0L : (1000 * numberToSend) / elapsedMilliseconds);
}
}
}
79 changes: 79 additions & 0 deletions Mike.MQShootout/Mike.MQShootout.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A376D26C-8181-4C2B-95B3-8D310CB4D809}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mike.MQShootout</RootNamespace>
<AssemblyName>Mike.MQShootout</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Apache.NMS">
<HintPath>..\ActiveMQ\Apache.NMS.dll</HintPath>
</Reference>
<Reference Include="Apache.NMS.ActiveMQ">
<HintPath>..\ActiveMQ\Apache.NMS.ActiveMQ.dll</HintPath>
</Reference>
<Reference Include="clrzmq">
<HintPath>..\ZeroMQ\clrzmq.dll</HintPath>
</Reference>
<Reference Include="RabbitMQ.Client">
<HintPath>..\RabbitMQ\RabbitMQ.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Messaging" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveMq.cs" />
<Compile Include="IMessageReceiver.cs" />
<Compile Include="IMessageSender.cs" />
<Compile Include="MessageReceivingMachine.cs" />
<Compile Include="MessageSendingMachine.cs" />
<Compile Include="Msmq.cs" />
<Compile Include="NullMq.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rabbit.cs" />
<Compile Include="StateMachine\SagaSpike.cs" />
<Compile Include="TheShootout.cs" />
<Compile Include="ZeroMq.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\ZeroMQ\libzmq.dll">
<Link>libzmq.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 1203dc0

Please sign in to comment.