activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Gomes <>
Subject Re: C#+EmbeddedBroker
Date Tue, 28 Feb 2017 21:31:10 GMT
You can use IKVM ( to create a C# assembly from the
ActiveMQ jar file.  Here's the command-line you can use to compile it:

ikvmc.exe activemq-all-*.jar -out:ActiveMQ.Broker.dll -platform:anycpu

Once you have created that assembly, create a new project that references
the ActiveMQ.Broker.dll and the IKVM.OpenJDK.Core assemblies.  Call this
new project *ActiveMQ.Embedded*. It will output the assembly
ActiveMQ.Embedded.dll.  This project will have the following source file
(name the source file AMQBroker.cs):

using System;
using System.IO;
using System.Reflection;

namespace ActiveMQ.Embedded
public class AMQBroker : IDisposable
private readonly amqBroker;
private readonly string tmpDataDir = null;

public AMQBroker()
: this(0, false, null)

public AMQBroker(ushort port)
: this(port, false, null)

public AMQBroker(ushort port, bool persistent)
: this(port, persistent, null)

public AMQBroker(ushort port, bool persistent, string dataDirectory)
amqBroker = new;

tmpDataDir = GetTemporaryDirectory();

string localserveraddress = IsLinux ? "" : "localhost"; connector =
ConnectionUri = new Uri(connector.getUri().ToString());

public static bool IsLinux
int p = (int) Environment.OSVersion.Platform;
return (p == 4) || (p == 6) || (p == 128);

public Uri ConnectionUri { get; private set; }
public int ConnectionPort { get { return ConnectionUri.Port; } }
public Uri FailoverUri { get { return new
Uri($"activemq:failover:{ConnectionUri.ToString()}"); } }

private static string GetTemporaryDirectory()
string tempFolder = Path.GetTempFileName();
return tempFolder;

public void Dispose()
if(null != tmpDataDir)
Directory.Delete(tmpDataDir, true);
catch(Exception e)

Once you have created the ActiveMQ.Embedded.dll, you can then reference it
in your project and instantiate an embedded broker as follows:

using ActiveMQ.Embedded;

AMQBroker broker = new AMQBroker(56500);  // Set whatever port number you
want to use, or leave it to the default.

It's that simple. Just remember to Dispose() it when you are done. Having
an embedded broker is fantastic for unit testing, or for many other uses.

Good luck!


On Tue, Feb 28, 2017 at 12:00 PM xinchangan <> wrote:

I need to build an ActiveMQ client with C#.In order to improve the
of transmit I have to use the embedded-broker within my C# Client. Finding
through all the documents and examples provided by ActiveMQ, I could not get
any clue or answers.

How can I do it? Anyone has a suggestion?


View this message in context:
Sent from the ActiveMQ - Dev mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message