-
Notifications
You must be signed in to change notification settings - Fork 22
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
Showing
11 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
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,13 @@ | ||
# Tester application for ActiveMQ | ||
|
||
## Usage | ||
|
||
Update appsettings.json with new values. | ||
|
||
Make application act as sender: `.\ActiveMqTester.exe sender` | ||
|
||
Make application act as receiver: `.\ActiveMqTester.exe receiver` | ||
|
||
## More information | ||
|
||
Please see https://blog.mathiaskunto.com/2022/06/10/activemq-connection-tester-application/ |
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="appsettings.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Apache.NMS.ActiveMQ" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31702.278 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActiveMqTester", "ActiveMqTester.csproj", "{63F88131-964B-4925-B89C-C3CDB145E034}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{63F88131-964B-4925-B89C-C3CDB145E034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{63F88131-964B-4925-B89C-C3CDB145E034}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{63F88131-964B-4925-B89C-C3CDB145E034}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{63F88131-964B-4925-B89C-C3CDB145E034}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {F9221A66-D5C9-4356-9996-E4C2BAF4BFE6} | ||
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,43 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace ActiveMqTester | ||
{ | ||
class Program | ||
{ | ||
private const string _help = "Usage:\r\nActiveMqTester.exe sender (the app will act as a sender).\r\nActiveMqTester.exe reciever (the app will act as a receiver)."; | ||
|
||
static void Main(string[] args) | ||
{ | ||
if (args.Length != 1) | ||
{ | ||
Console.WriteLine(_help); | ||
return; | ||
} | ||
|
||
IConfigurationRoot configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) | ||
.AddJsonFile("appsettings.json", false) | ||
.Build(); | ||
IConfigurationSection section = configuration.GetSection("TesterSettings"); | ||
|
||
Console.WriteLine($"\r\nActiveMQ tester."); | ||
|
||
switch (args[0]) | ||
{ | ||
case "sender": | ||
Sender.Send(section); | ||
break; | ||
case "receiver": | ||
Receiver.Receive(section); | ||
break; | ||
default: | ||
Console.WriteLine(_help); | ||
break; | ||
} | ||
Console.WriteLine($"\r\nExiting ..."); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
ActiveMqTester/src/Properties/PublishProfiles/FolderProfile.pubxml
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net5.0\publish\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
</PropertyGroup> | ||
</Project> |
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,35 @@ | ||
using Apache.NMS; | ||
using Apache.NMS.ActiveMQ; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
|
||
using System; | ||
|
||
namespace ActiveMqTester | ||
{ | ||
internal class Receiver | ||
{ | ||
public static void Receive(IConfigurationSection section) | ||
{ | ||
(ConnectionFactory factory, string queue, string username, string password, MsgDeliveryMode deliveryMode, AcknowledgementMode acknowledgementMode) = Settings.GetValues(section); | ||
|
||
|
||
using IConnection connection = factory.CreateConnection(username, password); | ||
connection.Start(); | ||
|
||
using ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); | ||
using IDestination destination = session.GetQueue(queue); | ||
using IMessageConsumer consumer = session.CreateConsumer(destination); | ||
|
||
Console.WriteLine("\r\n--- Waiting for messages (press any key to quit) ---\r\n"); | ||
|
||
consumer.Listener += (IMessage message) => | ||
{ | ||
var textMessage = message as ITextMessage; | ||
Console.WriteLine($"Received {DateTime.Now:HH:mm:ss}: {textMessage.Text}"); | ||
}; | ||
|
||
_ = Console.ReadLine(); | ||
} | ||
} | ||
} |
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,42 @@ | ||
using Apache.NMS; | ||
using Apache.NMS.ActiveMQ; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
|
||
using System; | ||
|
||
namespace ActiveMqTester | ||
{ | ||
internal class Sender | ||
{ | ||
public static void Send(IConfigurationSection section) | ||
{ | ||
(ConnectionFactory factory, string queue, string username, string password, MsgDeliveryMode deliveryMode, AcknowledgementMode acknowledgementMode) = Settings.GetValues(section); | ||
|
||
using IConnection connection = factory.CreateConnection(username, password); | ||
connection.Start(); | ||
|
||
using ISession session = connection.CreateSession(acknowledgementMode); | ||
using IDestination destination = session.GetQueue(queue); | ||
using IMessageProducer producer = session.CreateProducer(destination); | ||
|
||
producer.DeliveryMode = deliveryMode; | ||
|
||
string message; | ||
while (true) | ||
{ | ||
Console.Write("\r\nMessage to send (ENTER to quit): "); | ||
message = Console.ReadLine(); | ||
if (message == string.Empty) | ||
{ | ||
break; | ||
} | ||
|
||
ITextMessage textMessage = session.CreateTextMessage(message); | ||
producer.Send(textMessage); | ||
|
||
Console.WriteLine($"Message sent {DateTime.Now:HH:mm:ss}"); | ||
} | ||
} | ||
} | ||
} |
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 Apache.NMS; | ||
using Apache.NMS.ActiveMQ; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
|
||
using System; | ||
|
||
namespace ActiveMqTester | ||
{ | ||
internal class Settings | ||
{ | ||
public static (ConnectionFactory factory, string queue, string username, string password, MsgDeliveryMode deliveryMode, AcknowledgementMode acknowledgementMode) GetValues(IConfigurationSection section) | ||
{ | ||
string hostName = section.GetSection("HostName").Value; | ||
string queue = section.GetSection("Queue").Value; | ||
int port = int.Parse(section.GetSection("Port").Value); | ||
string username = section.GetSection("Username").Value; | ||
string password = section.GetSection("Password").Value; | ||
var delMode = (MsgDeliveryMode)int.Parse(section.GetSection("MsgDeliveryMode").Value); | ||
var ackMode = (AcknowledgementMode)int.Parse(section.GetSection("AcknowledgementMode").Value); | ||
string brokerAddress = $"activemq:tcp://{hostName}:{port}"; | ||
|
||
Console.WriteLine("\r\nUsing the following settings from appsettings.json:"); | ||
Console.WriteLine($"HostName: {hostName}"); | ||
Console.WriteLine($"Port: {port}"); | ||
Console.WriteLine($"Username: {username}"); | ||
Console.WriteLine($"Password: Not shown"); | ||
Console.WriteLine($"Queue: {queue}"); | ||
Console.WriteLine($"Del.Mode: {delMode}"); | ||
Console.WriteLine($"Ack.Mode: {ackMode}"); | ||
Console.WriteLine($"Broker Url: {brokerAddress}"); | ||
|
||
var brokerUri = new Uri(brokerAddress); | ||
var factory = new ConnectionFactory(brokerUri); | ||
|
||
return (factory, queue, username, password, delMode, ackMode); | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"TesterSettings": { | ||
"HostName": "my-activemq-server.com", | ||
"Port": 61616, | ||
"Queue": "nameofqueue", | ||
"Username": "username", | ||
"Password": "password", | ||
"MsgDeliveryMode": 1, | ||
"AcknowledgementMode": 0 | ||
} | ||
} |
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