forked from mikehadlow/Mike.MQShootout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1203dc0
Showing
36 changed files
with
16,169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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&wireFormat.MaxInactivityDuration=10000&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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.